summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Collins <robertc@robertcollins.net>2010-11-15 06:43:44 +1300
committerRobert Collins <robertc@robertcollins.net>2010-11-15 06:43:44 +1300
commitb9d27a1c14775430901346059dd60f12b248c8f6 (patch)
tree14a46445be858ea58c7cf34c7cc7ec011937b061
parent3d5fe00351af8d185bf38bc114c2be59f358f681 (diff)
downloadtestresources-git-b9d27a1c14775430901346059dd60f12b248c8f6.tar.gz
* Added ``testresources.FixtureResource`` to wrap ``fixtures.Fixture``
instances. (Robert Collins)
-rw-r--r--NEWS6
-rw-r--r--README14
-rw-r--r--lib/testresources/__init__.py36
-rw-r--r--lib/testresources/tests/test_test_resource.py20
4 files changed, 71 insertions, 5 deletions
diff --git a/NEWS b/NEWS
index 292fa08..4f7e0fd 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,12 @@ testresources release notes
IN DEVELOPMENT
--------------
+IMPROVEMENTS
+~~~~~~~~~~~~
+
+* Added ``testresources.FixtureResource`` to wrap ``fixtures.Fixture``
+ instances. (Robert Collins)
+
0.2.4
-----
diff --git a/README b/README
index 3dbdfa5..e1c9cea 100644
--- a/README
+++ b/README
@@ -25,14 +25,18 @@ provide test optimisation where expensive common resources are needed for test
cases - for example sample working trees for VCS systems, reference databases
for enterprise applications, or web servers ... let imagination run wild.
-Dependencies
-============
+Dependencies to build/selftest
+==============================
* Python 2.4+
-* testtools
+* testtools (http://pypi.python.org/pypi/testtools/)
+* fixtures (http://pypi.python.org/pypi/fixtures)
+
+Dependencies to use testresources
+=================================
-Note that testtools is required for *running* the tests for testresources. You
-can use testresources in your own app without using testtools.
+* Python 2.4+
+* fixtures (http://pypi.python.org/pypi/fixtures)
How testresources Works
diff --git a/lib/testresources/__init__.py b/lib/testresources/__init__.py
index 32d97e4..dbb2f01 100644
--- a/lib/testresources/__init__.py
+++ b/lib/testresources/__init__.py
@@ -616,6 +616,42 @@ class GenericResource(TestResource):
return True
+class FixtureResource(TestResource):
+ """A TestResource that decorates a ``fixtures.Fixture``.
+
+ The fixture has its setUp and cleanUp called as expected, and
+ reset is called between uses.
+
+ Due to the API of fixtures, dependency_resources are not
+ accessible to the wrapped fixture. However, if you are using
+ resource optimisation, you should wrap any dependencies in a
+ FixtureResource and set resources appropriately.
+
+ See the ``fixtures`` documentation for information on managing
+ dependencies within the ``fixtures`` API.
+
+ :ivar fixture: The wrapped fixture.
+ """
+
+ def __init__(self, fixture):
+ """Create a FixtureResource
+
+ :param fixture: The fixture to wrap.
+ """
+ TestResource.__init__(self)
+ self.fixture = fixture
+
+ def clean(self, resource):
+ resource.cleanUp()
+
+ def make(self, dependency_resources):
+ self.fixture.setUp()
+ return self.fixture
+
+ def isDirty(self):
+ return True
+
+
class ResourcedTestCase(unittest.TestCase):
"""A TestCase parent or utility that enables cross-test resource usage.
diff --git a/lib/testresources/tests/test_test_resource.py b/lib/testresources/tests/test_test_resource.py
index 97e5ab0..7cde13b 100644
--- a/lib/testresources/tests/test_test_resource.py
+++ b/lib/testresources/tests/test_test_resource.py
@@ -15,6 +15,7 @@
# license.
#
+from fixtures.tests.helpers import LoggingFixture
import testtools
import testresources
@@ -446,3 +447,22 @@ class TestGenericResource(testtools.TestCase):
resource = mgr.getResource()
self.assertTrue(mgr.isDirty())
mgr.finishedWith(resource)
+
+
+class TestFixtureResource(testtools.TestCase):
+
+ def test_uses_setUp_cleanUp(self):
+ fixture = LoggingFixture()
+ mgr = testresources.FixtureResource(fixture)
+ resource = mgr.getResource()
+ self.assertEqual(fixture, resource)
+ self.assertEqual(['setUp'], fixture.calls)
+ mgr.finishedWith(resource)
+ self.assertEqual(['setUp', 'cleanUp'], fixture.calls)
+
+ def test_always_dirty(self):
+ fixture = LoggingFixture()
+ mgr = testresources.FixtureResource(fixture)
+ resource = mgr.getResource()
+ self.assertTrue(mgr.isDirty())
+ mgr.finishedWith(resource)