Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def for_call(self):
mock_args = tuple(f"mock {str(arg)}" for arg in self.call_args)
mock_kwargs = {k: f"mock {str(v)}" for k, v in self.call_kwargs.items()}
mock_async_callable(self.target_arg, self.callable_arg).for_call(
*mock_args, **mock_kwargs
).to_return_value("mock")
self.assertEqual(
await self.callable_target(*mock_args, **mock_kwargs), "mock"
)
if mock_args or mock_kwargs:
with self.assertRaises(UnexpectedCallArguments):
await self.callable_target(*self.call_args, **self.call_kwargs)
async def before(self):
mock_async_callable(
self.target_arg, self.callable_arg
).with_wrapper(self.wrapper)
self.callable_target = getattr(self.real_target, self.callable_arg)
async def it_is_not_allowed(self):
with self.assertRaisesRegex(
ValueError,
"Patching an instance method at the class is not supported",
):
mock_async_callable(self.target_arg, self.callable_arg)
async def before(self):
self.callable_arg = "async_test_function"
self.original_callable = getattr(self.real_target, self.callable_arg)
self.mock_async_callable_dsl = mock_async_callable(
self.target_arg, self.callable_arg
)
self.callable_target = getattr(self.real_target, self.callable_arg)
self.call_args = ("1", "2")
self.call_kwargs = {"kwarg1": "1", "kwarg2": "2"}
async def before(self):
self.callable_arg = "__aiter__"
self.mock_async_callable_dsl = mock_async_callable(
self.target_arg, self.callable_arg
)
self.callable_target = getattr(self.real_target, self.callable_arg)
self.call_args = ()
self.call_kwargs = {}
async def can_mock_with_flag(self):
mock_async_callable(
self.target_arg, self.callable_arg, callable_returns_coroutine=True
)
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
async def before(self):
self.callable_arg = "async_instance_method"
self.mock_async_callable_dsl = mock_async_callable(
self.target_arg, self.callable_arg
)
self.callable_target = getattr(self.real_target, self.callable_arg)
async def before(self):
self.callable_arg = "async_static_method"
self.original_callable = getattr(self.real_target, self.callable_arg)
self.mock_async_callable_dsl = mock_async_callable(
self.target_arg, self.callable_arg
)
self.callable_target = getattr(self.real_target, self.callable_arg)