How to use the testslide.strict_mock.StrictMock 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 / strict_mock_testslide.py View on Github external
        context.memoize("strict_mock", lambda self: StrictMock())
github facebookincubator / TestSlide / tests / mock_callable_testslide.py View on Github external
def before(self):
            target = StrictMock(template=sample_module.Target)
            self.original_callable = None
            self.real_target = target
            self.target_arg = target
github facebookincubator / TestSlide / testslide / strict_mock.py View on Github external
def __setattr__(self, name, value):
        if self._is_magic_method(name):
            # ...check whether we're allowed to mock...
            if name in self._UNSETTABLE_MAGICS or (
                name in StrictMock.__dict__ and name not in self._SETTABLE_MAGICS
            ):
                raise UnsupportedMagic(self, name)
            # ...or if it is something unsupported.
            if name not in self._SETTABLE_MAGICS:
                raise NotImplementedError(
                    f"StrictMock does not implement support for {name}"
                )

        mock_value = self._validate_and_wrap_mock_value(name, value)
        setattr(type(self), name, mock_value)
github facebookincubator / TestSlide / tests / strict_mock_testslide.py View on Github external
def allows_setting_with_mock_with_invalid_type_template(
                                self,
                            ):
                                self.strict_mock.non_callable = unittest.mock.Mock(
                                    spec=int
                                )
                                self.strict_mock.non_callable = StrictMock(template=int)
github facebookincubator / TestSlide / tests / strict_mock_testslide.py View on Github external
def allows_setting_valid_type_with_templated_mock(self):
                            self.strict_mock.non_callable = unittest.mock.Mock(spec=str)
                            self.strict_mock.non_callable = StrictMock(template=str)
github facebookincubator / TestSlide / tests / strict_mock_testslide.py View on Github external
        context.memoize("strict_mock", lambda self: StrictMock(template=Template))
        context.memoize("key", lambda self: 1)
github facebookincubator / TestSlide / tests / mock_callable_testslide.py View on Github external
def before(self):
                    self.target = StrictMock(
                        template=sample_module.Target,
                        runtime_attrs=["dynamic_instance_method"],
                    )
                    self.original_callable = None
                    self.real_target = self.target
                    self.target_arg = self.target
github facebookincubator / TestSlide / tests / mock_callable_testslide.py View on Github external
def other_instances_are_not_mocked(self):
                mock_callable(self.target_arg, self.callable_arg).to_return_value(
                    "mocked value"
                )
                self.assertEqual(
                    self.callable_target(*self.call_args, **self.call_kwargs),
                    "mocked value",
                )
                other_strict_mock = StrictMock(
                    template=sample_module.Target, runtime_attrs=runtime_attrs
                )
                mock_callable(other_strict_mock, self.callable_arg).to_return_value(
                    "other mocked value"
                )
                self.assertEqual(
                    getattr(other_strict_mock, self.callable_arg)(
                        *self.call_args, **self.call_kwargs
                    ),
                    "other mocked value",
                )
github facebookincubator / TestSlide / tests / mock_constructor_testslide.py View on Github external
def get_target_mock(self):
            return StrictMock(template=self.get_target_class())
github facebookincubator / TestSlide / tests / mock_async_callable_testslide.py View on Github external
async def before(self):
            self.original_callable = None
            self.real_target = StrictMock(template=sample_module.Target)
            self.target_arg = self.real_target
            self.call_args = ("1", "2")
            self.call_kwargs = {"kwarg1": "1", "kwarg2": "2"}