How to use the testslide.mock_callable.mock_async_callable function in TestSlide

To help you get started, we’ve selected a few TestSlide examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github facebookincubator / TestSlide / tests / mock_async_callable_testslide.py View on Github external
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)
github facebookincubator / TestSlide / tests / mock_async_callable_testslide.py View on Github external
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)
github facebookincubator / TestSlide / tests / mock_async_callable_testslide.py View on Github external
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)
github facebookincubator / TestSlide / tests / mock_async_callable_testslide.py View on Github external
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"}
github facebookincubator / TestSlide / tests / mock_async_callable_testslide.py View on Github external
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 = {}
github facebookincubator / TestSlide / tests / mock_async_callable_testslide.py View on Github external
async def can_mock_with_flag(self):
                mock_async_callable(
                    self.target_arg, self.callable_arg, callable_returns_coroutine=True
                )
github facebookincubator / TestSlide / testslide / __init__.py View on Github external
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
github facebookincubator / TestSlide / tests / mock_async_callable_testslide.py View on Github external
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)
github facebookincubator / TestSlide / tests / mock_async_callable_testslide.py View on Github external
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)