示例#1
0
 def test_patch_autospec_really_leaves_an_autospec_behind(self):
     self.patch_autospec(self, "method_to_be_patched")
     # The patched method is now a callable mock.
     self.assertThat(self.method_to_be_patched, IsCallableMock())
     # The patched method can be called with positional or keyword
     # arguments.
     self.method_to_be_patched(1, 2)
     self.method_to_be_patched(3, b=4)
     self.method_to_be_patched(a=5, b=6)
     self.assertThat(self.method_to_be_patched, MockCallsMatch(
         call(1, 2), call(3, b=4), call(a=5, b=6)))
     # Calling the patched method with unrecognised arguments or not
     # enough arguments results in an exception.
     self.assertRaises(TypeError, self.method_to_be_patched, c=7)
     self.assertRaises(TypeError, self.method_to_be_patched, 8)
     self.assertRaises(TypeError, self.method_to_be_patched, b=9)
示例#2
0
 def test__returns_mismatch_when_its_a_non_callable_object(self):
     matcher = IsCallableMock()
     result = matcher.match(object())
     self.assertMismatch(result, " is not callable")
示例#3
0
 def test__returns_mismatch_when_its_a_non_callable_autospec(self):
     mock = create_autospec(None)
     matcher = IsCallableMock()
     result = matcher.match(mock)
     self.assertMismatch(result, " is not callable")
示例#4
0
 def test__returns_mismatch_when_its_a_non_callable_mock(self):
     mock = NonCallableMock()
     matcher = IsCallableMock()
     result = matcher.match(mock)
     self.assertMismatch(result, " is not callable")
示例#5
0
 def test__returns_none_when_its_a_callable_autospec(self):
     mock = create_autospec(lambda: None)
     matcher = IsCallableMock()
     result = matcher.match(mock)
     self.assertIsNone(result)
示例#6
0
 def test__returns_none_when_its_a_callable_mock(self):
     mock = Mock()
     matcher = IsCallableMock()
     result = matcher.match(mock)
     self.assertIsNone(result)