How to use the testslide.mock_callable.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 / tests / mock_callable_testslide.py View on Github external
def it_doest_not_type_validate(self):
                            call_args = [1 for arg in self.call_args]
                            call_kwargs = {key: 1 for key in self.call_kwargs.keys()}
                            mock_callable(
                                self.target_arg,
                                self.callable_arg,
                                type_validation=self.type_validation,
                            ).for_call(*call_args, **call_kwargs).to_return_value(None)
                            self.callable_target(*call_args, **call_kwargs)
github facebookincubator / TestSlide / tests / mock_callable_testslide.py View on Github external
def mock_callable_dsl(self):
                return mock_callable(
                    self.target_arg,
                    self.callable_arg,
                    type_validation=self.type_validation,
                )
github facebookincubator / TestSlide / tests / mock_callable_testslide.py View on Github external
def mock_callable_dsl(self):
                return mock_callable(
                    self.target_arg,
                    self.callable_arg,
                    type_validation=self.type_validation,
                )
github facebookincubator / TestSlide / tests / mock_callable_testslide.py View on Github external
def it_is_not_allowed(self):
                with self.assertRaises(ValueError):
                    mock_callable(sample_module.Target, "__str__")
github facebookincubator / TestSlide / tests / mock_callable_testslide.py View on Github external
def mock_callable_dsl(self):
                return mock_callable(
                    self.target_arg,
                    self.callable_arg,
                    type_validation=self.type_validation,
                )
github facebookincubator / TestSlide / tests / mock_callable_testslide.py View on Github external
def newest_mock_has_precedence_over_older_mocks(self):
                    """
                    Mocks are designed to be composable, allowing us to declare
                    multiple behaviors for different calls. Those definitions stack up,
                    and when a call is made to the mock, they are searched from newest
                    to oldest, to find one that is able to be caled.
                    """
                    # First, mock all calls
                    mock_callable(self.target_arg, self.callable_arg).to_return_value(
                        "any args"
                    )
                    # Then we add some specific call behavior
                    mock_callable(self.target_arg, self.callable_arg).for_call(
                        *self.specific_call_args, **self.specific_call_kwargs
                    ).to_return_value("specific")
                    # The first behavior should still be there
                    self.assertEqual(
                        self.callable_target(*self.call_args, **self.call_kwargs),
                        "any args",
                    )
                    # as well as the specific case
                    self.assertEqual(
                        self.callable_target(
                            *self.specific_call_args, **self.specific_call_kwargs
                        ),
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_callable_testslide.py View on Github external
def mock_callable_dsl(self):
                    return mock_callable(self.target_arg, self.callable_arg)