How to use the testslide.mock_callable.UnexpectedCallReceived 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 called(self):
                        with self.assertRaisesWithMessage(
                            UnexpectedCallReceived,
                            "{}, {}: Expected not to be called!".format(
                                repr(self.real_target), repr(self.callable_arg)
                            ),
                        ):
                            self.callable_target(*self.call_args, **self.call_kwargs)
github facebookincubator / TestSlide / testslide / mock_callable.py View on Github external
def and_assert_called_exactly(self, count):
        """
        Assert that there were exactly the given number of calls.

        If assertion is for 0 calls, any received call will raise
        UnexpectedCallReceived and also an AssertionError.
        """
        if count:
            self._assert_runner()
        else:
            if not self._runner:
                self.to_raise(
                    UnexpectedCallReceived(
                        ("{}, {}: Expected not to be called!").format(
                            _format_target(self._target), repr(self._method)
                        )
                    )
                )
        self._runner.add_exact_calls_assertion(count)
        return self
github facebookincubator / TestSlide / tests / mock_callable_testslide.py View on Github external
def called_more_times(self):
                    for _ in range(self.times):
                        self.callable_target(*self.call_args, **self.call_kwargs)
                    with self.assertRaisesWithMessage(
                        UnexpectedCallReceived,
                        (
                            "Unexpected call received.\n"
                            "{}, {}:\n"
                            "  expected to receive at most {} calls with any arguments "
                            "  but received an extra call."
                        ).format(
                            repr(self.target_arg), repr(self.callable_arg), self.times
                        ),
                    ):
                        self.callable_target(*self.call_args, **self.call_kwargs)
github facebookincubator / TestSlide / testslide / mock_callable.py View on Github external
def inc_call_count(self):
        self._call_count += 1
        if self.max_calls and self._call_count > self.max_calls:
            raise UnexpectedCallReceived(
                (
                    "Unexpected call received.\n"
                    "{}, {}:\n"
                    "  expected to receive at most {} calls with {}"
                    "  but received an extra call."
                ).format(
                    _format_target(self.target),
                    repr(self.method),
                    self.max_calls,
                    self._args_message(),
                )