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)
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
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")
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)
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")
def test_should_delegate_to_mock_method(self): dummy = mock.Mock() dummy(True) self.assertCalledWith(dummy, True)