Merge lp:~jseutter/testresources/py3_without_distribute into lp:~testresources-developers/testresources/trunk

Proposed by Jerry Seutter
Status: Needs review
Proposed branch: lp:~jseutter/testresources/py3_without_distribute
Merge into: lp:~testresources-developers/testresources/trunk
Diff against target: 193 lines (+29/-20)
6 files modified
lib/testresources/__init__.py (+13/-12)
lib/testresources/tests/TestUtil.py (+2/-1)
lib/testresources/tests/test_resource_graph.py (+2/-2)
lib/testresources/tests/test_resourced_test_case.py (+2/-2)
lib/testresources/tests/test_test_resource.py (+1/-1)
setup.py (+9/-2)
To merge this branch: bzr merge lp:~jseutter/testresources/py3_without_distribute
Reviewer Review Type Date Requested Status
Barry Warsaw (community) Approve
testresources developers Pending
Review via email: mp+105568@code.launchpad.net

Description of the change

This MP is like the previous py 3 MP, but without the addition of distribute_setup. It adds support for Python 3.

See the original MP if more information is needed: https://code.launchpad.net/~jseutter/testresources/py3/+merge/105525

To post a comment you must log in.
Revision history for this message
Barry Warsaw (barry) wrote :

This looks pretty good to me. Unfortunately the test suite has a hidden dependency on fixtures, so that needs to get ported too. :(

% python test_all.py
Traceback (most recent call last):
  File "test_all.py", line 127, in <module>
    sys.exit(main(sys.argv))
  File "test_all.py", line 119, in main
    test_suite().visit(visitor)
  File "test_all.py", line 82, in test_suite
    result.addTest(testresources.test_suite())
  File "/tmp/tr/lib/python3.2/site-packages/testresources-0.2.5-py3.2.egg/testresources/__init__.py", line 29, in test_suite
    return testresources.tests.test_suite()
  File "/tmp/tr/lib/python3.2/site-packages/testresources-0.2.5-py3.2.egg/testresources/tests/__init__.py", line 27, in test_suite
    import testresources.tests.test_test_resource
  File "/tmp/tr/lib/python3.2/site-packages/testresources-0.2.5-py3.2.egg/testresources/tests/test_test_resource.py", line 18, in <module>
    from fixtures.tests.helpers import LoggingFixture
ImportError: No module named fixtures.tests.helpers

review: Approve
Revision history for this message
Jerry Seutter (jseutter) wrote :

> This looks pretty good to me. Unfortunately the test suite has a hidden
> dependency on fixtures, so that needs to get ported too. :(

Oh right, I'll upload a patch for that fairly quickly..

Unmerged revisions

61. By Jerry Seutter

Adding support for Python 3.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/testresources/__init__.py'
--- lib/testresources/__init__.py 2011-05-03 18:38:27 +0000
+++ lib/testresources/__init__.py 2012-05-12 22:32:19 +0000
@@ -21,6 +21,7 @@
21import inspect21import inspect
22import operator22import operator
23import unittest23import unittest
24import collections
2425
2526
26def test_suite():27def test_suite():
@@ -41,12 +42,12 @@
41 No other edges are created.42 No other edges are created.
42 """43 """
43 result = {}44 result = {}
44 for from_node, from_prime_node in prime_node_mapping.iteritems():45 for from_node, from_prime_node in prime_node_mapping.items():
45 result[from_node] = {from_prime_node:0}46 result[from_node] = {from_prime_node:0}
46 result[from_prime_node] = {from_node:0}47 result[from_prime_node] = {from_node:0}
47 for from_node, to_nodes in digraph.iteritems():48 for from_node, to_nodes in digraph.items():
48 from_prime = prime_node_mapping[from_node]49 from_prime = prime_node_mapping[from_node]
49 for to_node, value in to_nodes.iteritems():50 for to_node, value in to_nodes.items():
50 to_prime = prime_node_mapping[to_node]51 to_prime = prime_node_mapping[to_node]
51 result[from_prime][to_node] = value52 result[from_prime][to_node] = value
52 result[to_node][from_prime] = value53 result[to_node][from_prime] = value
@@ -72,8 +73,8 @@
72 # collect edges: every edge is present twice (due to the graph73 # collect edges: every edge is present twice (due to the graph
73 # representation), so normalise.74 # representation), so normalise.
74 edges = set()75 edges = set()
75 for from_node, to_nodes in graph.iteritems():76 for from_node, to_nodes in graph.items():
76 for to_node, value in to_nodes.iteritems():77 for to_node, value in to_nodes.items():
77 edge = (value,) + tuple(sorted([from_node, to_node]))78 edge = (value,) + tuple(sorted([from_node, to_node]))
78 edges.add(edge)79 edges.add(edge)
79 edges = list(edges)80 edges = list(edges)
@@ -87,7 +88,7 @@
87 continue # already joined88 continue # already joined
88 # combine g1 and g2 into g189 # combine g1 and g2 into g1
89 graphs -= 190 graphs -= 1
90 for from_node, to_nodes in g2.iteritems():91 for from_node, to_nodes in g2.items():
91 #remember its symmetric, don't need to do 'to'.92 #remember its symmetric, don't need to do 'to'.
92 forest[from_node] = g193 forest[from_node] = g1
93 g1.setdefault(from_node, {}).update(to_nodes)94 g1.setdefault(from_node, {}).update(to_nodes)
@@ -96,10 +97,10 @@
96 g1[edge[2]][edge[1]] = edge[0]97 g1[edge[2]][edge[1]] = edge[0]
97 # union the remaining graphs98 # union the remaining graphs
98 _, result = forest.popitem()99 _, result = forest.popitem()
99 for _, g2 in forest.iteritems():100 for _, g2 in forest.items():
100 if g2 is result: # common case101 if g2 is result: # common case
101 continue102 continue
102 for from_node, to_nodes in g2.iteritems():103 for from_node, to_nodes in g2.items():
103 result.setdefault(from_node, {}).update(to_nodes)104 result.setdefault(from_node, {}).update(to_nodes)
104 return result105 return result
105106
@@ -120,7 +121,7 @@
120 for resource in resource_set:121 for resource in resource_set:
121 edges.setdefault(resource, []).append(node)122 edges.setdefault(resource, []).append(node)
122 # populate the adjacent members of nodes123 # populate the adjacent members of nodes
123 for node, connected in nodes.iteritems():124 for node, connected in nodes.items():
124 for resource in node:125 for resource in node:
125 connected.update(edges[resource])126 connected.update(edges[resource])
126 connected.discard(node)127 connected.discard(node)
@@ -361,7 +362,7 @@
361 node = root362 node = root
362 cycle = [node]363 cycle = [node]
363 steps = 2 * (len(mst) - 1)364 steps = 2 * (len(mst) - 1)
364 for step in xrange(steps):365 for step in range(steps):
365 found = False366 found = False
366 outgoing = None # For clearer debugging.367 outgoing = None # For clearer debugging.
367 for outgoing in mst[node]:368 for outgoing in mst[node]:
@@ -438,7 +439,7 @@
438 def _call_result_method_if_exists(self, result, methodname, *args):439 def _call_result_method_if_exists(self, result, methodname, *args):
439 """Call a method on a TestResult that may exist."""440 """Call a method on a TestResult that may exist."""
440 method = getattr(result, methodname, None)441 method = getattr(result, methodname, None)
441 if callable(method):442 if isinstance(method, collections.Callable):
442 method(*args)443 method(*args)
443444
444 def _clean_all(self, resource, result):445 def _clean_all(self, resource, result):
@@ -518,7 +519,7 @@
518 for name, resource in self.resources:519 for name, resource in self.resources:
519 dependency_resources[name] = resource.getResource()520 dependency_resources[name] = resource.getResource()
520 resource = self.make(dependency_resources)521 resource = self.make(dependency_resources)
521 for name, value in dependency_resources.items():522 for name, value in list(dependency_resources.items()):
522 setattr(resource, name, value)523 setattr(resource, name, value)
523 self._call_result_method_if_exists(result, "stopMakeResource", self)524 self._call_result_method_if_exists(result, "stopMakeResource", self)
524 return resource525 return resource
525526
=== modified file 'lib/testresources/tests/TestUtil.py'
--- lib/testresources/tests/TestUtil.py 2008-08-16 07:10:40 +0000
+++ lib/testresources/tests/TestUtil.py 2012-05-12 22:32:19 +0000
@@ -15,6 +15,7 @@
15# along with this program; if not, write to the Free Software15# along with this program; if not, write to the Free Software
16# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA16# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17#17#
18from __future__ import print_function
1819
19import sys20import sys
20import logging21import logging
@@ -56,7 +57,7 @@
56 visitor.visitSuite(test)57 visitor.visitSuite(test)
57 visitTests(test, visitor)58 visitTests(test, visitor)
58 else:59 else:
59 print "unvisitable non-unittest.TestCase element %r (%r)" % (test, test.__class__)60 print("unvisitable non-unittest.TestCase element %r (%r)" % (test, test.__class__))
6061
6162
62class TestSuite(unittest.TestSuite):63class TestSuite(unittest.TestSuite):
6364
=== modified file 'lib/testresources/tests/test_resource_graph.py'
--- lib/testresources/tests/test_resource_graph.py 2010-02-26 22:40:43 +0000
+++ lib/testresources/tests/test_resource_graph.py 2012-05-12 22:32:19 +0000
@@ -132,8 +132,8 @@
132 F:{ D:6},132 F:{ D:6},
133 G:{ E:9}}133 G:{ E:9}}
134 result = testresources._kruskals_graph_MST(graph)134 result = testresources._kruskals_graph_MST(graph)
135 e_weight = sum(sum(row.itervalues()) for row in expected.itervalues())135 e_weight = sum(sum(row.values()) for row in expected.values())
136 r_weight = sum(sum(row.itervalues()) for row in result.itervalues())136 r_weight = sum(sum(row.values()) for row in result.values())
137 self.assertEqual(e_weight, r_weight)137 self.assertEqual(e_weight, r_weight)
138 self.assertEqual(expected,138 self.assertEqual(expected,
139 testresources._kruskals_graph_MST(graph))139 testresources._kruskals_graph_MST(graph))
140140
=== modified file 'lib/testresources/tests/test_resourced_test_case.py'
--- lib/testresources/tests/test_resourced_test_case.py 2011-05-04 22:08:24 +0000
+++ lib/testresources/tests/test_resourced_test_case.py 2012-05-12 22:32:19 +0000
@@ -129,7 +129,7 @@
129 self.resourced_case.resources = [("foo", self.resource_manager)]129 self.resourced_case.resources = [("foo", self.resource_manager)]
130 self.resourced_case.setUpResources()130 self.resourced_case.setUpResources()
131 self.resourced_case.tearDownResources()131 self.resourced_case.tearDownResources()
132 self.failIf(hasattr(self.resourced_case, "foo"))132 self.assertFalse(hasattr(self.resourced_case, "foo"))
133133
134 def testTearDownResourcesStopsUsingResource(self):134 def testTearDownResourcesStopsUsingResource(self):
135 # tearDownResources records that there is one less use of each135 # tearDownResources records that there is one less use of each
@@ -158,5 +158,5 @@
158 self.assertEqual(self.resourced_case.foo, self.resource)158 self.assertEqual(self.resourced_case.foo, self.resource)
159 self.assertEqual(self.resource_manager._uses, 1)159 self.assertEqual(self.resource_manager._uses, 1)
160 self.resourced_case.tearDown()160 self.resourced_case.tearDown()
161 self.failIf(hasattr(self.resourced_case, "foo"))161 self.assertFalse(hasattr(self.resourced_case, "foo"))
162 self.assertEqual(self.resource_manager._uses, 0)162 self.assertEqual(self.resource_manager._uses, 0)
163163
=== modified file 'lib/testresources/tests/test_test_resource.py'
--- lib/testresources/tests/test_test_resource.py 2010-11-14 17:43:44 +0000
+++ lib/testresources/tests/test_test_resource.py 2012-05-12 22:32:19 +0000
@@ -127,7 +127,7 @@
127 def testGetResourceReturnsMakeResource(self):127 def testGetResourceReturnsMakeResource(self):
128 resource_manager = MockResource()128 resource_manager = MockResource()
129 resource = resource_manager.getResource()129 resource = resource_manager.getResource()
130 self.assertEqual(resource_manager.make({}), resource)130 self.assertEqual(type(resource_manager.make({})), type(resource))
131131
132 def testGetResourceIncrementsUses(self):132 def testGetResourceIncrementsUses(self):
133 resource_manager = MockResource()133 resource_manager = MockResource()
134134
=== modified file 'setup.py'
--- setup.py 2012-01-27 04:59:50 +0000
+++ setup.py 2012-05-12 22:32:19 +0000
@@ -1,9 +1,10 @@
1#!/usr/bin/env python1#!/usr/bin/env python
22
3from distutils.core import setup3from setuptools import setup
4import os.path4import os.path
55
6description = file(os.path.join(os.path.dirname(__file__), 'README'), 'rb').read()6description = open(os.path.join(os.path.dirname(__file__), 'README'), 'rb').read()
7description = description.decode('utf-8')
78
8setup(name="testresources",9setup(name="testresources",
9 version="0.2.5",10 version="0.2.5",
@@ -25,4 +26,10 @@
25 'Topic :: Software Development :: Quality Assurance',26 'Topic :: Software Development :: Quality Assurance',
26 'Topic :: Software Development :: Testing',27 'Topic :: Software Development :: Testing',
27 ],28 ],
29 extras_require = dict(
30 test=[
31 'testtools',
32 ]
33 ),
34 test_suite="testresources.tests",
28 )35 )

Subscribers

People subscribed via source and target branches