How to use the testslide.mock_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 / 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 / testslide / __init__.py View on Github external
def mock_callable(*args, **kwargs):
        return testslide.mock_callable.mock_callable(*args, **kwargs)
github facebookincubator / TestSlide / testslide / __init__.py View on Github external
def mock_async_callable(*args, **kwargs):
        return testslide.mock_callable.mock_async_callable(*args, **kwargs)
github facebookincubator / TestSlide / testslide / __init__.py View on Github external
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()
github facebookincubator / TestSlide / testslide / strict_mock.py View on Github external
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
github facebookincubator / TestSlide / tests / mock_callable_testslide.py View on Github external
def register_assertions(self):
        def register_assertion(assertion):
            self.assertions.append(assertion)

        testslide.mock_callable.register_assertion = register_assertion
github facebookincubator / TestSlide / testslide / __init__.py View on Github external
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