@@ -67,3 +67,32 @@ def __init__(self, *args, **kwargs):
6767 kwd_args = {"multi" : True } # Like interactive mode.
6868 kwd_args .update (kwargs )
6969 super (SafeTestPipeline , self ).__init__ (* args , ** kwd_args )
70+
71+ # originally imported from veracitools v0.1.4 (now deprecated)
72+ class ExpectContext (object ):
73+ """ Pytest validation context, a framework for varied kinds of expectations. """
74+
75+ def __init__ (self , expected , test_func ):
76+ """
77+ Create the test context by specifying expectation and function.
78+
79+ :param object | type expected: expected result or exception
80+ :param callable test_func: the callable object to test
81+ """
82+ self ._f = test_func
83+ self ._exp = expected
84+
85+ def __enter__ (self ):
86+ """ Return the instance for use as a callable. """
87+ return self
88+
89+ def __exit__ (self , exc_type , exc_val , exc_tb ):
90+ pass
91+
92+ def __call__ (self , * args , ** kwargs ):
93+ """ Execute the instance's function, passing given args/kwargs. """
94+ if isinstance (self ._exp , type ) and issubclass (self ._exp , Exception ):
95+ with pytest .raises (self ._exp ):
96+ self ._f (* args , ** kwargs )
97+ else :
98+ assert self ._exp == self ._f (* args , ** kwargs )
0 commit comments