diff options
author | Jonathan Lange <jml@canonical.com> | 2012-07-04 19:04:32 +0100 |
---|---|---|
committer | Jonathan Lange <jml@canonical.com> | 2012-07-04 19:04:32 +0100 |
commit | 03620da7ff3e99c7b506cf701ad4c28e631da811 (patch) | |
tree | 8630e70249e583cbd6aba80f21caff464af2863a | |
parent | 533529b8d2980eea203933f9e7e010f7aba3f97f (diff) | |
download | fixtures-03620da7ff3e99c7b506cf701ad4c28e631da811.tar.gz |
Add a matcher, because I can't bear to write that code again.
-rw-r--r-- | lib/fixtures/tests/_fixtures/test_tempdir.py | 5 | ||||
-rw-r--r-- | lib/fixtures/tests/_fixtures/test_temphomedir.py | 5 | ||||
-rw-r--r-- | lib/fixtures/tests/helpers.py | 21 |
3 files changed, 27 insertions, 4 deletions
diff --git a/lib/fixtures/tests/_fixtures/test_tempdir.py b/lib/fixtures/tests/_fixtures/test_tempdir.py index 1e42257..5fd5a46 100644 --- a/lib/fixtures/tests/_fixtures/test_tempdir.py +++ b/lib/fixtures/tests/_fixtures/test_tempdir.py @@ -23,13 +23,14 @@ from fixtures import ( NestedTempfile, TempDir, ) +from fixtures.tests.helpers import NotHasattr + class TestTempDir(testtools.TestCase): def test_basic(self): fixture = TempDir() - sentinel = object() - self.assertEqual(sentinel, getattr(fixture, 'path', sentinel)) + self.assertThat(fixture, NotHasattr('path')) fixture.setUp() try: path = fixture.path diff --git a/lib/fixtures/tests/_fixtures/test_temphomedir.py b/lib/fixtures/tests/_fixtures/test_temphomedir.py index 339ce2c..5e0db9a 100644 --- a/lib/fixtures/tests/_fixtures/test_temphomedir.py +++ b/lib/fixtures/tests/_fixtures/test_temphomedir.py @@ -22,13 +22,14 @@ from fixtures import ( TempDir, TempHomeDir, ) +from fixtures.tests.helpers import NotHasattr + class TestTempDir(testtools.TestCase): def test_basic(self): fixture = TempHomeDir() - sentinel = object() - self.assertEqual(sentinel, getattr(fixture, 'path', sentinel)) + self.assertThat(fixture, NotHasattr('path')) fixture.setUp() try: path = fixture.path diff --git a/lib/fixtures/tests/helpers.py b/lib/fixtures/tests/helpers.py index ae0d8d3..680d396 100644 --- a/lib/fixtures/tests/helpers.py +++ b/lib/fixtures/tests/helpers.py @@ -15,6 +15,9 @@ import fixtures +from testtools.matchers import Mismatch + + class LoggingFixture(fixtures.Fixture): def __init__(self, suffix='', calls=None): @@ -31,3 +34,21 @@ class LoggingFixture(fixtures.Fixture): def reset(self): self.calls.append('reset' + self.suffix) + + +class NotHasattr(object): + """For asserting that an object does not have a particular attribute.""" + + def __init__(self, attr_name): + self._attr_name = attr_name + + def __str__(self): + return 'NotHasattr(%s)' % (self._attr_name,) + + def match(self, obj): + sentinel = object() + value = getattr(obj, self._attr_name, sentinel) + if value is not sentinel: + return Mismatch( + "%s is an attribute of %r: %r" % ( + self._attr_name, obj, value)) |