Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _init_mocks(self):
self.mock_callable = testslide.mock_callable.mock_callable
self.mock_async_callable = testslide.mock_callable.mock_async_callable
self.mock_constructor = testslide.mock_constructor.mock_constructor
self.patch_attribute = testslide.patch_attribute.patch_attribute
self._mock_callable_after_functions = []
def register_assertion(assertion):
if self._example.is_async:
async def f(_):
assertion()
else:
f = lambda _: assertion()
self._mock_callable_after_functions.append(f)
testslide.mock_callable.register_assertion = register_assertion
def mock_callable(*args, **kwargs):
return testslide.mock_callable.mock_callable(*args, **kwargs)
def mock_async_callable(*args, **kwargs):
return testslide.mock_callable.mock_async_callable(*args, **kwargs)
def setUp(self):
testslide.mock_callable.register_assertion = lambda assertion: self.addCleanup(
assertion
)
self.addCleanup(testslide.mock_callable.unpatch_all_callable_mocks)
self.addCleanup(testslide.mock_constructor.unpatch_all_constructor_mocks)
self.addCleanup(testslide.patch_attribute.unpatch_all_mocked_attributes)
super(TestCase, self).setUp()
def return_validation_wrapper(*args, **kwargs):
return_value = signature_validation_wrapper(
*args, **kwargs
)
if self.__dict__["_type_validation"] and not isinstance(
value, testslide.mock_callable._CallableMock
):
testslide.lib._validate_return_type(
template_value,
return_value,
self.__dict__["_caller_frame_info"],
)
return return_value
def register_assertions(self):
def register_assertion(assertion):
self.assertions.append(assertion)
testslide.mock_callable.register_assertion = register_assertion
self.mock_async_callable = testslide.mock_callable.mock_async_callable
self.mock_constructor = testslide.mock_constructor.mock_constructor
self.patch_attribute = testslide.patch_attribute.patch_attribute
self._mock_callable_after_functions = []
def register_assertion(assertion):
if self._example.is_async:
async def f(_):
assertion()
else:
f = lambda _: assertion()
self._mock_callable_after_functions.append(f)
testslide.mock_callable.register_assertion = register_assertion