Example #1
0
 def test_changes_attribute_and_resets(self):
     patches = gocept.testing.patch.Patches()
     subject = mock.Mock()
     subject.foo = mock.sentinel.foo
     patches.set(subject, 'foo', mock.sentinel.bar)
     self.assertEqual(mock.sentinel.bar, subject.foo)
     patches.reset()
     self.assertEqual(mock.sentinel.foo, subject.foo)
Example #2
0
 def setUp(self):
     """Has patches after setup."""
     assert hasattr(self, 'patches') is False
     super().setUp()
     assert hasattr(self, 'patches') is True
     self.foo = mock.sentinel.foo
     self.bar = mock.sentinel.bar
     self.subject = mock.Mock()
     self.subject.foo = self.foo
Example #3
0
 def test_add_object_should_delegate_to_patch_object(self):
     patches = gocept.testing.mock.Patches()
     subject = mock.Mock()
     subject.foo = mock.sentinel.Something
     patches.add_object(subject, 'foo', mock.sentinel.Something2)
     self.assertEqual(subject.foo, mock.sentinel.Something2, "unpatched")
     patches.reset()
     self.assertEqual(
         subject.foo, mock.sentinel.Something, "patch not restored")
Example #4
0
 def test_multiple_reset_does_no_harm(self):
     patches = gocept.testing.patch.Patches()
     subject = mock.Mock()
     subject.foo = mock.sentinel.foo
     patches.set(subject, 'foo', mock.sentinel.bar)
     self.assertEqual(mock.sentinel.bar, subject.foo)
     patches.reset()
     self.assertEqual(mock.sentinel.foo, subject.foo)
     with self.assertNothingRaised():
         patches.reset()
     self.assertEqual(mock.sentinel.foo, subject.foo)
Example #5
0
 def test_reset_multiple_times_does_no_harm(self):
     patches = gocept.testing.mock.Patches()
     subject = mock.Mock()
     subject.foo = mock.sentinel.Something
     patches.add_object(subject, 'foo', mock.sentinel.Something2)
     self.assertEqual(subject.foo, mock.sentinel.Something2, "unpatched")
     patches.reset()
     self.assertEqual(
         subject.foo, mock.sentinel.Something, "patch not restored")
     patches.reset()
     self.assertEqual(
         subject.foo, mock.sentinel.Something, "patch not restored")
Example #6
0
 def test_should_delegate_to_mock_method(self):
     dummy = mock.Mock()
     dummy(True)
     self.assertCalledWith(dummy, True)