summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Collins <robertc@robertcollins.net>2013-01-20 23:07:48 +1300
committerRobert Collins <robertc@robertcollins.net>2013-01-20 23:07:48 +1300
commit2a1ab3bc4d630c4d03232bf36da2a1cf2c971d4a (patch)
tree42d77fa0f7fd740a2a82f67277178b2f579b74dd
parentcb2a1ac4182535ed20323303edc77e7a1fa6f9ff (diff)
downloadtestresources-2a1ab3bc4d630c4d03232bf36da2a1cf2c971d4a.tar.gz
* FixtureResource was not triggering cleanups or resets between uses, this is
fixed (but will make OptimisingTestSuite trigger resets on every transition between tests). (Robert Collins, James Westby, #1023423)
-rw-r--r--NEWS7
-rw-r--r--lib/testresources/__init__.py23
-rw-r--r--lib/testresources/tests/test_test_resource.py9
-rwxr-xr-xsetup.py4
4 files changed, 31 insertions, 12 deletions
diff --git a/NEWS b/NEWS
index 5d00968..4448da8 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,13 @@ testresources release notes
IN DEVELOPMENT
--------------
+IMPROVEMENTS
+~~~~~~~~~~~~
+
+* FixtureResource was not triggering cleanups or resets between uses, this is
+ fixed (but will make OptimisingTestSuite trigger resets on every transition
+ between tests). (Robert Collins, James Westby, #1023423)
+
0.2.6
-----
diff --git a/lib/testresources/__init__.py b/lib/testresources/__init__.py
index b1ea0ce..148ff1a 100644
--- a/lib/testresources/__init__.py
+++ b/lib/testresources/__init__.py
@@ -33,7 +33,7 @@ import unittest
# If the releaselevel is 'final', then the tarball will be major.minor.micro.
# Otherwise it is major.minor.micro~$(revno).
-__version__ = (0, 2, 6, 'final', 0)
+__version__ = (0, 2, 7, 'final', 0)
def test_suite():
@@ -486,7 +486,8 @@ class TestResourceManager(object):
the `clean` hook, which should do any resource-specific
cleanup.
- :param resource: A resource returned by `TestResource.getResource`.
+ :param resource: A resource returned by
+ `TestResourceManager.getResource`.
:param result: An optional TestResult to report resource changes to.
"""
self._uses -= 1
@@ -592,8 +593,8 @@ class TestResourceManager(object):
TestResource = TestResourceManager
-class GenericResource(TestResource):
- """A TestResource that decorates an external helper of some kind.
+class GenericResource(TestResourceManager):
+ """A TestResourceManager that decorates an external helper of some kind.
GenericResource can be used to adapt an external resource so that
testresources can use it. By default the setUp and tearDown methods are
@@ -617,7 +618,7 @@ class GenericResource(TestResource):
:param teardown_method_name: Optional method name to call to tear down
the resource. Defaults to 'tearDown'.
"""
- TestResource.__init__(self)
+ super(GenericResource, self).__init__()
self.resource_factory = resource_factory
self.setup_method_name = setup_method_name
self.teardown_method_name = teardown_method_name
@@ -634,8 +635,8 @@ class GenericResource(TestResource):
return True
-class FixtureResource(TestResource):
- """A TestResource that decorates a ``fixtures.Fixture``.
+class FixtureResource(TestResourceManager):
+ """A TestResourceManager that decorates a ``fixtures.Fixture``.
The fixture has its setUp and cleanUp called as expected, and
reset is called between uses.
@@ -660,7 +661,7 @@ class FixtureResource(TestResource):
:param fixture: The fixture to wrap.
"""
- TestResource.__init__(self)
+ super(FixtureResource, self).__init__()
self.fixture = fixture
def clean(self, resource):
@@ -673,6 +674,8 @@ class FixtureResource(TestResource):
def isDirty(self):
return True
+ _dirty = property(lambda _:True, lambda _, _1:None)
+
class ResourcedTestCase(unittest.TestCase):
"""A TestCase parent or utility that enables cross-test resource usage.
@@ -685,8 +688,8 @@ class ResourcedTestCase(unittest.TestCase):
from your setUp and tearDown (or whatever cleanup idiom is used).
:ivar resources: A list of (name, resource) pairs, where 'resource' is a
- subclass of `TestResource` and 'name' is the name of the attribute
- that the resource should be stored on.
+ subclass of `TestResourceManager` and 'name' is the name of the
+ attribute that the resource should be stored on.
"""
resources = []
diff --git a/lib/testresources/tests/test_test_resource.py b/lib/testresources/tests/test_test_resource.py
index fbc883b..74fb9ed 100644
--- a/lib/testresources/tests/test_test_resource.py
+++ b/lib/testresources/tests/test_test_resource.py
@@ -469,3 +469,12 @@ class TestFixtureResource(testtools.TestCase):
resource = mgr.getResource()
self.assertTrue(mgr.isDirty())
mgr.finishedWith(resource)
+
+ def test_reset_called(self):
+ fixture = LoggingFixture()
+ mgr = testresources.FixtureResource(fixture)
+ resource = mgr.getResource()
+ mgr.reset(resource)
+ mgr.finishedWith(resource)
+ self.assertEqual(
+ ['setUp', 'cleanUp', 'setUp', 'cleanUp'], fixture.calls)
diff --git a/setup.py b/setup.py
index c5f61c7..58928d4 100755
--- a/setup.py
+++ b/setup.py
@@ -1,12 +1,12 @@
#!/usr/bin/env python
-from distutils.core import setup
+from setuptools import setup
import os.path
description = open(os.path.join(os.path.dirname(__file__), 'README'), 'rt').read()
setup(name="testresources",
- version="0.2.6",
+ version="0.2.7",
description="Testresources, a pyunit extension for managing expensive "
"test resources",
long_description=description,