def test_mocks_can_allow_calls(mocks): return_value = "Hello!" mock = mocks.mock(name='save') allows_call(mock).returns(return_value) assert mock() is return_value assert mock() is return_value mock("positional", key="word") is return_value
def test_can_allow_calls_with_the_same_syntax_that_it_will_be_called_with(mocks): to_print = "Hello, hello, hello, what's going on here then?" to_return = "There are four lights!" printer = mocks.mock() allows_call(printer)(to_print).returns(to_return) assert printer(to_print) is to_return
def test_mocks_can_allow_calls_with_args(mocks): return_value = "Hello!" mock = mocks.mock(name='save') allows_call(mock).with_args("positional").returns(return_value) assert mock("positional") is return_value assert_raises(UnexpectedInvocationError, mock) assert_raises(UnexpectedInvocationError, lambda: mock("positional", key="word"))
def test_can_mock_methods_used_internally_by_mock(mocks): mock = mocks.mock() expects(mock)._mocked_calls expects(mock).save() allows(mock)._mocked_calls allows(mock).save() expects_call(mock) allows_call(mock) mock._mocked_calls() mock.save() mock() class UserRepository(object): def _base(self): pass based_mock = mocks.mock(UserRepository) allows(based_mock)._base