def test_assert_has_calls(self): kalls1 = [call(1, 2), ({"a": 3},), ((3, 4),), call(b=6), ("", (1,), {"b": 6})] kalls2 = [call.foo(), call.bar(1)] kalls2.extend(call.spam().baz(a=3).call_list()) kalls2.extend(call.bam(set(), foo={}).fish([1]).call_list()) mocks = [] for mock in Mock(), MagicMock(): mock(1, 2) mock(a=3) mock(3, 4) mock(b=6) mock(1, b=6) mocks.append((mock, kalls1)) mock = Mock() mock.foo() mock.bar(1) mock.spam().baz(a=3) mock.bam(set(), foo={}).fish([1]) mocks.append((mock, kalls2)) for mock, kalls in mocks: for i in range(len(kalls)): for step in 1, 2, 3: these = kalls[i : i + step] mock.assert_has_calls(these) if len(these) > 1: self.assertRaises(AssertionError, mock.assert_has_calls, list(reversed(these)))
def test_proxy(self): client_1 = Mock() client_2 = Mock() proxy = CorbaClientProxy(client_1) self.assertEqual(proxy.client, client_1) proxy.foo() proxy.client = client_2 self.assertEqual(proxy.client, client_2) proxy.bar() self.assertEqual(client_1.mock_calls, [call.foo()]) self.assertEqual(client_2.mock_calls, [call.bar()])
def test_should_call_functions_in_process_special_settings(self): funcs = MagicMock() settings_dict = { 'SIMPLE_SETTINGS': { 'bar': 'bar_value', 'foo': 'foo_value' } } with patch('simple_settings.special_settings.SPECIAL_SETTINGS_MAPPING', OrderedDict((('foo', funcs.foo), ('bar', funcs.bar)))): process_special_settings(settings_dict) assert funcs.mock_calls == [ call.foo(settings_dict), call.bar(settings_dict) ]
def test_assert_has_calls(self): kalls1 = [ call(1, 2), ({ 'a': 3 }, ), ((3, 4), ), call(b=6), ('', (1, ), { 'b': 6 }), ] kalls2 = [call.foo(), call.bar(1)] kalls2.extend(call.spam().baz(a=3).call_list()) kalls2.extend(call.bam(set(), foo={}).fish([1]).call_list()) mocks = [] for mock in Mock(), MagicMock(): mock(1, 2) mock(a=3) mock(3, 4) mock(b=6) mock(1, b=6) mocks.append((mock, kalls1)) mock = Mock() mock.foo() mock.bar(1) mock.spam().baz(a=3) mock.bam(set(), foo={}).fish([1]) mocks.append((mock, kalls2)) for mock, kalls in mocks: for i in range(len(kalls)): for step in 1, 2, 3: these = kalls[i:i + step] mock.assert_has_calls(these) if len(these) > 1: self.assertRaises(AssertionError, mock.assert_has_calls, list(reversed(these)))
def test_should_call_functions_in_process_special_settings(self): funcs = MagicMock() settings_dict = { 'SIMPLE_SETTINGS': { 'bar': 'bar_value', 'foo': 'foo_value' } } with patch( 'simple_settings.special_settings.SPECIAL_SETTINGS_MAPPING', OrderedDict((('foo', funcs.foo), ('bar', funcs.bar))) ): process_special_settings(settings_dict) assert funcs.mock_calls == [ call.foo(settings_dict), call.bar(settings_dict) ]