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
1=== modified file 'lib/testresources/__init__.py'
2--- lib/testresources/__init__.py 2011-05-03 18:38:27 +0000
3+++ lib/testresources/__init__.py 2012-05-12 22:32:19 +0000
4@@ -21,6 +21,7 @@
5 import inspect
6 import operator
7 import unittest
8+import collections
9
10
11 def test_suite():
12@@ -41,12 +42,12 @@
13 No other edges are created.
14 """
15 result = {}
16- for from_node, from_prime_node in prime_node_mapping.iteritems():
17+ for from_node, from_prime_node in prime_node_mapping.items():
18 result[from_node] = {from_prime_node:0}
19 result[from_prime_node] = {from_node:0}
20- for from_node, to_nodes in digraph.iteritems():
21+ for from_node, to_nodes in digraph.items():
22 from_prime = prime_node_mapping[from_node]
23- for to_node, value in to_nodes.iteritems():
24+ for to_node, value in to_nodes.items():
25 to_prime = prime_node_mapping[to_node]
26 result[from_prime][to_node] = value
27 result[to_node][from_prime] = value
28@@ -72,8 +73,8 @@
29 # collect edges: every edge is present twice (due to the graph
30 # representation), so normalise.
31 edges = set()
32- for from_node, to_nodes in graph.iteritems():
33- for to_node, value in to_nodes.iteritems():
34+ for from_node, to_nodes in graph.items():
35+ for to_node, value in to_nodes.items():
36 edge = (value,) + tuple(sorted([from_node, to_node]))
37 edges.add(edge)
38 edges = list(edges)
39@@ -87,7 +88,7 @@
40 continue # already joined
41 # combine g1 and g2 into g1
42 graphs -= 1
43- for from_node, to_nodes in g2.iteritems():
44+ for from_node, to_nodes in g2.items():
45 #remember its symmetric, don't need to do 'to'.
46 forest[from_node] = g1
47 g1.setdefault(from_node, {}).update(to_nodes)
48@@ -96,10 +97,10 @@
49 g1[edge[2]][edge[1]] = edge[0]
50 # union the remaining graphs
51 _, result = forest.popitem()
52- for _, g2 in forest.iteritems():
53+ for _, g2 in forest.items():
54 if g2 is result: # common case
55 continue
56- for from_node, to_nodes in g2.iteritems():
57+ for from_node, to_nodes in g2.items():
58 result.setdefault(from_node, {}).update(to_nodes)
59 return result
60
61@@ -120,7 +121,7 @@
62 for resource in resource_set:
63 edges.setdefault(resource, []).append(node)
64 # populate the adjacent members of nodes
65- for node, connected in nodes.iteritems():
66+ for node, connected in nodes.items():
67 for resource in node:
68 connected.update(edges[resource])
69 connected.discard(node)
70@@ -361,7 +362,7 @@
71 node = root
72 cycle = [node]
73 steps = 2 * (len(mst) - 1)
74- for step in xrange(steps):
75+ for step in range(steps):
76 found = False
77 outgoing = None # For clearer debugging.
78 for outgoing in mst[node]:
79@@ -438,7 +439,7 @@
80 def _call_result_method_if_exists(self, result, methodname, *args):
81 """Call a method on a TestResult that may exist."""
82 method = getattr(result, methodname, None)
83- if callable(method):
84+ if isinstance(method, collections.Callable):
85 method(*args)
86
87 def _clean_all(self, resource, result):
88@@ -518,7 +519,7 @@
89 for name, resource in self.resources:
90 dependency_resources[name] = resource.getResource()
91 resource = self.make(dependency_resources)
92- for name, value in dependency_resources.items():
93+ for name, value in list(dependency_resources.items()):
94 setattr(resource, name, value)
95 self._call_result_method_if_exists(result, "stopMakeResource", self)
96 return resource
97
98=== modified file 'lib/testresources/tests/TestUtil.py'
99--- lib/testresources/tests/TestUtil.py 2008-08-16 07:10:40 +0000
100+++ lib/testresources/tests/TestUtil.py 2012-05-12 22:32:19 +0000
101@@ -15,6 +15,7 @@
102 # along with this program; if not, write to the Free Software
103 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
104 #
105+from __future__ import print_function
106
107 import sys
108 import logging
109@@ -56,7 +57,7 @@
110 visitor.visitSuite(test)
111 visitTests(test, visitor)
112 else:
113- print "unvisitable non-unittest.TestCase element %r (%r)" % (test, test.__class__)
114+ print("unvisitable non-unittest.TestCase element %r (%r)" % (test, test.__class__))
115
116
117 class TestSuite(unittest.TestSuite):
118
119=== modified file 'lib/testresources/tests/test_resource_graph.py'
120--- lib/testresources/tests/test_resource_graph.py 2010-02-26 22:40:43 +0000
121+++ lib/testresources/tests/test_resource_graph.py 2012-05-12 22:32:19 +0000
122@@ -132,8 +132,8 @@
123 F:{ D:6},
124 G:{ E:9}}
125 result = testresources._kruskals_graph_MST(graph)
126- e_weight = sum(sum(row.itervalues()) for row in expected.itervalues())
127- r_weight = sum(sum(row.itervalues()) for row in result.itervalues())
128+ e_weight = sum(sum(row.values()) for row in expected.values())
129+ r_weight = sum(sum(row.values()) for row in result.values())
130 self.assertEqual(e_weight, r_weight)
131 self.assertEqual(expected,
132 testresources._kruskals_graph_MST(graph))
133
134=== modified file 'lib/testresources/tests/test_resourced_test_case.py'
135--- lib/testresources/tests/test_resourced_test_case.py 2011-05-04 22:08:24 +0000
136+++ lib/testresources/tests/test_resourced_test_case.py 2012-05-12 22:32:19 +0000
137@@ -129,7 +129,7 @@
138 self.resourced_case.resources = [("foo", self.resource_manager)]
139 self.resourced_case.setUpResources()
140 self.resourced_case.tearDownResources()
141- self.failIf(hasattr(self.resourced_case, "foo"))
142+ self.assertFalse(hasattr(self.resourced_case, "foo"))
143
144 def testTearDownResourcesStopsUsingResource(self):
145 # tearDownResources records that there is one less use of each
146@@ -158,5 +158,5 @@
147 self.assertEqual(self.resourced_case.foo, self.resource)
148 self.assertEqual(self.resource_manager._uses, 1)
149 self.resourced_case.tearDown()
150- self.failIf(hasattr(self.resourced_case, "foo"))
151+ self.assertFalse(hasattr(self.resourced_case, "foo"))
152 self.assertEqual(self.resource_manager._uses, 0)
153
154=== modified file 'lib/testresources/tests/test_test_resource.py'
155--- lib/testresources/tests/test_test_resource.py 2010-11-14 17:43:44 +0000
156+++ lib/testresources/tests/test_test_resource.py 2012-05-12 22:32:19 +0000
157@@ -127,7 +127,7 @@
158 def testGetResourceReturnsMakeResource(self):
159 resource_manager = MockResource()
160 resource = resource_manager.getResource()
161- self.assertEqual(resource_manager.make({}), resource)
162+ self.assertEqual(type(resource_manager.make({})), type(resource))
163
164 def testGetResourceIncrementsUses(self):
165 resource_manager = MockResource()
166
167=== modified file 'setup.py'
168--- setup.py 2012-01-27 04:59:50 +0000
169+++ setup.py 2012-05-12 22:32:19 +0000
170@@ -1,9 +1,10 @@
171 #!/usr/bin/env python
172
173-from distutils.core import setup
174+from setuptools import setup
175 import os.path
176
177-description = file(os.path.join(os.path.dirname(__file__), 'README'), 'rb').read()
178+description = open(os.path.join(os.path.dirname(__file__), 'README'), 'rb').read()
179+description = description.decode('utf-8')
180
181 setup(name="testresources",
182 version="0.2.5",
183@@ -25,4 +26,10 @@
184 'Topic :: Software Development :: Quality Assurance',
185 'Topic :: Software Development :: Testing',
186 ],
187+ extras_require = dict(
188+ test=[
189+ 'testtools',
190+ ]
191+ ),
192+ test_suite="testresources.tests",
193 )

Subscribers

People subscribed via source and target branches