Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2014
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. def assert_called_once(mock, expected_args=None, expected_kwargs=None):
  2.     """Assert ``mock`` called once with expected args/kwargs.
  3.  
  4.    :param mock.Mock mock: The Mock to assert against.
  5.    :param expected_args:
  6.        A tuple containing the expected positional arguments.
  7.    :param expected_kwargs:
  8.        A dictionary containing the expected keyword arguments.
  9.    """
  10.     assert_true(isinstance(mock, Mock))
  11.     if expected_args is None:
  12.         expected_args = ()
  13.     if expected_kwargs is None:
  14.         expected_kwargs = {}
  15.     assert_equal(1, mock.call_count)
  16.     args, kwargs = mock.call_args
  17.     assert_equal(expected_args, args)
  18.     assert_equal(expected_kwargs, kwargs)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement