summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Collins <robertc@robertcollins.net>2013-01-20 11:38:59 +1300
committerRobert Collins <robertc@robertcollins.net>2013-01-20 11:38:59 +1300
commitcb2a1ac4182535ed20323303edc77e7a1fa6f9ff (patch)
treeaab08cc4afa38ce6ece4c84673c57f686814f4c1
parentcf53bcf11057aa93ddf17dcff899434f37ce920c (diff)
downloadtestresources-cb2a1ac4182535ed20323303edc77e7a1fa6f9ff.tar.gz
Release 0.2.6 and add Python3.2 compat.0.2.6
-rw-r--r--NEWS5
-rw-r--r--README25
-rw-r--r--lib/testresources/__init__.py34
-rw-r--r--lib/testresources/tests/TestUtil.py2
-rw-r--r--lib/testresources/tests/test_resource_graph.py4
-rw-r--r--lib/testresources/tests/test_test_resource.py3
-rwxr-xr-xsetup.py6
7 files changed, 51 insertions, 28 deletions
diff --git a/NEWS b/NEWS
index a96ac63..5d00968 100644
--- a/NEWS
+++ b/NEWS
@@ -5,11 +5,16 @@ testresources release notes
IN DEVELOPMENT
--------------
+0.2.6
+-----
+
IMPROVEMENTS
~~~~~~~~~~~~
* NEWS made clearer. (Martin Pool)
+* Python3.2+ compatible. (Robert Collins)
+
0.2.5
-----
diff --git a/README b/README
index 0444a6a..0ccc25f 100644
--- a/README
+++ b/README
@@ -1,7 +1,7 @@
testresources: extensions to python unittest to allow declarative use
of resources by test cases.
-Copyright (C) 2005-2010 Robert Collins <robertc@robertcollins.net>
+Copyright (C) 2005-2013 Robert Collins <robertc@robertcollins.net>
Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
license at the users choice. A copy of both licenses are available in the
@@ -20,23 +20,22 @@ Copyright (C) 2005-2010 Robert Collins <robertc@robertcollins.net>
Testresources
+++++++++++++
-testresources is attempting to extend unittest with a clean and simple api to
-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.
+testresources extends unittest with a clean and simple api to 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 to build/selftest
==============================
-* Python 2.4+
+* Python 2.4+ (or 3.2+)
* testtools (http://pypi.python.org/pypi/testtools/)
* fixtures (http://pypi.python.org/pypi/fixtures)
Dependencies to use testresources
=================================
-* Python 2.4+
-
+* Python 2.4+ (or 3.2+)
How testresources Works
=======================
@@ -131,17 +130,17 @@ For instance::
class TemporaryDirectoryResource(TestResourceManager):
- def clean(self, resource):
- shutil.rmtree(resource)
+ def clean(self, resource):
+ shutil.rmtree(resource)
def make(self):
- return tempfile.mkdtemp()
+ return tempfile.mkdtemp()
- def isDirty(self, resource):
+ def isDirty(self, resource):
# Can't detect when the directory is written to, so assume it
# can never be reused. We could list the directory, but that might
# not catch it being open as a cwd etc.
- return True
+ return True
The ``resources`` list on the TestResourceManager object is used to declare
dependencies. For instance, a DataBaseResource that needs a TemporaryDirectory
diff --git a/lib/testresources/__init__.py b/lib/testresources/__init__.py
index 22f11e6..b1ea0ce 100644
--- a/lib/testresources/__init__.py
+++ b/lib/testresources/__init__.py
@@ -21,6 +21,20 @@ import heapq
import inspect
import unittest
+# same format as sys.version_info: "A tuple containing the five components of
+# the version number: major, minor, micro, releaselevel, and serial. All
+# values except releaselevel are integers; the release level is 'alpha',
+# 'beta', 'candidate', or 'final'. The version_info value corresponding to the
+# Python version 2.0 is (2, 0, 0, 'final', 0)." Additionally we use a
+# releaselevel of 'dev' for unreleased under-development code.
+#
+# If the releaselevel is 'alpha' then the major/minor/micro components are not
+# established at this point, and setup.py will use a version of next-$(revno).
+# 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)
+
def test_suite():
import testresources.tests
@@ -40,12 +54,12 @@ def _digraph_to_graph(digraph, prime_node_mapping):
No other edges are created.
"""
result = {}
- for from_node, from_prime_node in prime_node_mapping.iteritems():
+ for from_node, from_prime_node in prime_node_mapping.items():
result[from_node] = {from_prime_node: 0}
result[from_prime_node] = {from_node: 0}
- for from_node, to_nodes in digraph.iteritems():
+ for from_node, to_nodes in digraph.items():
from_prime = prime_node_mapping[from_node]
- for to_node, value in to_nodes.iteritems():
+ for to_node, value in to_nodes.items():
to_prime = prime_node_mapping[to_node]
result[from_prime][to_node] = value
result[to_node][from_prime] = value
@@ -71,8 +85,8 @@ def _kruskals_graph_MST(graph):
# collect edges: every edge is present twice (due to the graph
# representation), so normalise.
edges = set()
- for from_node, to_nodes in graph.iteritems():
- for to_node, value in to_nodes.iteritems():
+ for from_node, to_nodes in graph.items():
+ for to_node, value in to_nodes.items():
edge = (value,) + tuple(sorted([from_node, to_node]))
edges.add(edge)
edges = list(edges)
@@ -86,7 +100,7 @@ def _kruskals_graph_MST(graph):
continue # already joined
# combine g1 and g2 into g1
graphs -= 1
- for from_node, to_nodes in g2.iteritems():
+ for from_node, to_nodes in g2.items():
#remember its symmetric, don't need to do 'to'.
forest[from_node] = g1
g1.setdefault(from_node, {}).update(to_nodes)
@@ -95,10 +109,10 @@ def _kruskals_graph_MST(graph):
g1[edge[2]][edge[1]] = edge[0]
# union the remaining graphs
_, result = forest.popitem()
- for _, g2 in forest.iteritems():
+ for _, g2 in forest.items():
if g2 is result: # common case
continue
- for from_node, to_nodes in g2.iteritems():
+ for from_node, to_nodes in g2.items():
result.setdefault(from_node, {}).update(to_nodes)
return result
@@ -119,7 +133,7 @@ def _resource_graph(resource_sets):
for resource in resource_set:
edges.setdefault(resource, []).append(node)
# populate the adjacent members of nodes
- for node, connected in nodes.iteritems():
+ for node, connected in nodes.items():
for resource in node:
connected.update(edges[resource])
connected.discard(node)
@@ -364,7 +378,7 @@ class OptimisingTestSuite(unittest.TestSuite):
node = root
cycle = [node]
steps = 2 * (len(mst) - 1)
- for step in xrange(steps):
+ for step in range(steps):
found = False
outgoing = None # For clearer debugging.
for outgoing in mst[node]:
diff --git a/lib/testresources/tests/TestUtil.py b/lib/testresources/tests/TestUtil.py
index a55dea7..b6621c2 100644
--- a/lib/testresources/tests/TestUtil.py
+++ b/lib/testresources/tests/TestUtil.py
@@ -56,7 +56,7 @@ def visitTests(suite, visitor):
visitor.visitSuite(test)
visitTests(test, visitor)
else:
- print "unvisitable non-unittest.TestCase element %r (%r)" % (test, test.__class__)
+ print("unvisitable non-unittest.TestCase element %r (%r)" % (test, test.__class__))
class TestSuite(unittest.TestSuite):
diff --git a/lib/testresources/tests/test_resource_graph.py b/lib/testresources/tests/test_resource_graph.py
index ec39300..86a3a49 100644
--- a/lib/testresources/tests/test_resource_graph.py
+++ b/lib/testresources/tests/test_resource_graph.py
@@ -132,8 +132,8 @@ class TestKruskalsMST(testtools.TestCase):
F:{ D:6},
G:{ E:9}}
result = testresources._kruskals_graph_MST(graph)
- e_weight = sum(sum(row.itervalues()) for row in expected.itervalues())
- r_weight = sum(sum(row.itervalues()) for row in result.itervalues())
+ e_weight = sum(sum(row.values()) for row in expected.values())
+ r_weight = sum(sum(row.values()) for row in result.values())
self.assertEqual(e_weight, r_weight)
self.assertEqual(expected,
testresources._kruskals_graph_MST(graph))
diff --git a/lib/testresources/tests/test_test_resource.py b/lib/testresources/tests/test_test_resource.py
index 7cde13b..fbc883b 100644
--- a/lib/testresources/tests/test_test_resource.py
+++ b/lib/testresources/tests/test_test_resource.py
@@ -36,6 +36,9 @@ class MockResourceInstance(object):
def __init__(self, name):
self._name = name
+ def __eq__(self, other):
+ return self.__dict__ == other.__dict__
+
def __cmp__(self, other):
return cmp(self.__dict__, other.__dict__)
diff --git a/setup.py b/setup.py
index bbc9252..c5f61c7 100755
--- a/setup.py
+++ b/setup.py
@@ -3,10 +3,10 @@
from distutils.core import setup
import os.path
-description = file(os.path.join(os.path.dirname(__file__), 'README'), 'rb').read()
+description = open(os.path.join(os.path.dirname(__file__), 'README'), 'rt').read()
setup(name="testresources",
- version="0.2.5",
+ version="0.2.6",
description="Testresources, a pyunit extension for managing expensive "
"test resources",
long_description=description,
@@ -15,6 +15,7 @@ setup(name="testresources",
url="https://launchpad.net/testresources",
packages=['testresources', 'testresources.tests'],
package_dir = {'':'lib'},
+ keywords="unittest testing fixtures",
classifiers = [
'Development Status :: 6 - Mature',
'Intended Audience :: Developers',
@@ -22,6 +23,7 @@ setup(name="testresources",
'License :: OSI Approved :: Apache Software License',
'Operating System :: OS Independent',
'Programming Language :: Python',
+ 'Programming Language :: Python :: 3',
'Topic :: Software Development :: Quality Assurance',
'Topic :: Software Development :: Testing',
],