Merge lp:~free.ekanayaka/testresources/fix-lints into lp:~testresources-developers/testresources/trunk

Proposed by Free Ekanayaka
Status: Merged
Approved by: Jonathan Lange
Approved revision: 61
Merged at revision: 61
Proposed branch: lp:~free.ekanayaka/testresources/fix-lints
Merge into: lp:~testresources-developers/testresources/trunk
Diff against target: 270 lines (+42/-39)
1 file modified
lib/testresources/__init__.py (+42/-39)
To merge this branch: bzr merge lp:~free.ekanayaka/testresources/fix-lints
Reviewer Review Type Date Requested Status
Jonathan Lange Approve
Review via email: mp+119140@code.launchpad.net

Description of the change

This just fixes a few pep8 issues. There's just one pyflake issue left:

lib/testresources/__init__.py:49: local variable 'to_prime' is assigned to but never used

I think it'd be safe to drop that line at all.

To post a comment you must log in.
Revision history for this message
Jonathan Lange (jml) wrote :

Thanks!

review: Approve

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-08-10 15:10:50 +0000
4@@ -2,24 +2,23 @@
5 # of resources by test cases.
6 #
7 # Copyright (c) 2005-2010 Testresources Contributors
8-#
9+#
10 # Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
11 # license at the users choice. A copy of both licenses are available in the
12 # project source as Apache-2.0 and BSD. You may not use this file except in
13 # compliance with one of these two licences.
14-#
15-# Unless required by applicable law or agreed to in writing, software distributed
16-# under these licenses is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
17-# CONDITIONS OF ANY KIND, either express or implied. See the license you chose
18-# for the specific language governing permissions and limitations under that
19-# license.
20+#
21+# Unless required by applicable law or agreed to in writing, software
22+# distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
23+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
24+# license you chose for the specific language governing permissions and
25+# limitations under that license.
26 #
27
28 """TestResources: declarative management of external resources for tests."""
29
30 import heapq
31 import inspect
32-import operator
33 import unittest
34
35
36@@ -42,8 +41,8 @@
37 """
38 result = {}
39 for from_node, from_prime_node in prime_node_mapping.iteritems():
40- result[from_node] = {from_prime_node:0}
41- result[from_prime_node] = {from_node:0}
42+ result[from_node] = {from_prime_node: 0}
43+ result[from_prime_node] = {from_node: 0}
44 for from_node, to_nodes in digraph.iteritems():
45 from_prime = prime_node_mapping[from_node]
46 for to_node, value in to_nodes.iteritems():
47@@ -67,7 +66,7 @@
48 forest = {}
49 # graphs is the count of graphs we have yet to combine.
50 for node in graph:
51- forest[node] = {node:{}}
52+ forest[node] = {node: {}}
53 graphs = len(forest)
54 # collect edges: every edge is present twice (due to the graph
55 # representation), so normalise.
56@@ -84,7 +83,7 @@
57 g1 = forest[edge[1]]
58 g2 = forest[edge[2]]
59 if g1 is g2:
60- continue # already joined
61+ continue # already joined
62 # combine g1 and g2 into g1
63 graphs -= 1
64 for from_node, to_nodes in g2.iteritems():
65@@ -97,7 +96,7 @@
66 # union the remaining graphs
67 _, result = forest.popitem()
68 for _, g2 in forest.iteritems():
69- if g2 is result: # common case
70+ if g2 is result: # common case
71 continue
72 for from_node, to_nodes in g2.iteritems():
73 result.setdefault(from_node, {}).update(to_nodes)
74@@ -138,7 +137,8 @@
75 resource_set_tests = {no_resources: []}
76 for test in tests:
77 resources = getattr(test, "resources", ())
78- all_resources = list(resource.neededResources() for _, resource in resources)
79+ all_resources = list(resource.neededResources()
80+ for _, resource in resources)
81 resource_set = set()
82 for resource_list in all_resources:
83 resource_set.update(resource_list)
84@@ -148,7 +148,7 @@
85
86 def _strongly_connected_components(graph, no_resources):
87 """Find the strongly connected components in graph.
88-
89+
90 This is essentially a nonrecursive flatterning of Tarjan's method. It
91 may be worth profiling against an actual Tarjan's implementation at some
92 point, but sets are often faster than python calls.
93@@ -190,7 +190,8 @@
94 except TypeError:
95 unittest.TestSuite.addTest(self, test_case_or_suite)
96 return
97- if test_case_or_suite.__class__ in (unittest.TestSuite, OptimisingTestSuite):
98+ if test_case_or_suite.__class__ in (unittest.TestSuite,
99+ OptimisingTestSuite):
100 for test in tests:
101 self.adsorbSuite(test)
102 else:
103@@ -258,17 +259,17 @@
104 # We group the tests by the resource combinations they use,
105 # since there will usually be fewer resource combinations than
106 # actual tests and there can never be more: This gives us 'nodes' or
107- # 'resource_sets' that represent many tests using the same set of
108+ # 'resource_sets' that represent many tests using the same set of
109 # resources.
110 resource_set_tests = split_by_resources(self._tests)
111 # Partition into separate sets of resources, there is no ordering
112 # preference between sets that do not share members. Rationale:
113 # If resource_set A and B have no common resources, AB and BA are
114 # equally good - the global setup/teardown sums are identical. Secondly
115- # if A shares one or more resources with C, then pairing AC|CA is better
116- # than having B between A and C, because the shared resources can be
117- # reset or reused. Having partitioned we can use connected graph logic
118- # on each partition.
119+ # if A shares one or more resources with C, then pairing AC|CA is
120+ # better than having B between A and C, because the shared resources
121+ # can be reset or reused. Having partitioned we can use connected graph
122+ # logic on each partition.
123 resource_set_graph = _resource_graph(resource_set_tests)
124 no_resources = frozenset()
125 # A list of resource_set_tests, all fully internally connected.
126@@ -276,8 +277,8 @@
127 no_resources)
128 result = []
129 for partition in partitions:
130- # we process these at the end for no particularly good reason (it makes
131- # testing slightly easier).
132+ # we process these at the end for no particularly good reason (it
133+ # makes testing slightly easier).
134 if partition == [no_resources]:
135 continue
136 order = self._makeOrder(partition)
137@@ -311,14 +312,14 @@
138 from_resources = from_set
139 for to_set in resource_sets:
140 if from_set is to_set:
141- continue # no self-edges
142+ continue # no self-edges
143 #if to_set == bottom:
144 # if from_set == root:
145 # continue # no short cuts!
146 # to_resources = no_resources
147 #el
148 if to_set == root:
149- continue # no links to root
150+ continue # no links to root
151 else:
152 to_resources = to_set
153 graph[from_set][to_set] = self.cost_of_switching(
154@@ -327,10 +328,12 @@
155
156 def _makeOrder(self, partition):
157 """Return a order for the resource sets in partition."""
158- # This problem is NP-C - find the lowest cost hamiltonian path. It
159+ # This problem is NP-C - find the lowest cost hamiltonian path. It
160 # also meets the triangle inequality, so we can use an approximation.
161 # TODO: implement Christofides.
162- # See http://en.wikipedia.org/wiki/Travelling_salesman_problem#Metric_TSP
163+ # See:
164+ # http://en.wikipedia.org/wiki/Travelling_salesman_problem#Metric_TSP
165+
166 # We need a root
167 root = frozenset(['root'])
168 partition.add(root)
169@@ -363,7 +366,7 @@
170 steps = 2 * (len(mst) - 1)
171 for step in xrange(steps):
172 found = False
173- outgoing = None # For clearer debugging.
174+ outgoing = None # For clearer debugging.
175 for outgoing in mst[node]:
176 if node in mst[outgoing]:
177 # we have a return path: take it
178@@ -415,7 +418,7 @@
179 dependencies list.
180 :ivar resources: The resources that this resource needs. Calling
181 neededResources will return the closure of this resource and its needed
182- resources. The resources list is in the same format as resources on a
183+ resources. The resources list is in the same format as resources on a
184 test case - a list of tuples (attribute_name, resource).
185 :ivar setUpCost: The relative cost to construct a resource of this type.
186 One good approach is to set this to the number of seconds it normally
187@@ -495,7 +498,7 @@
188
189 def isDirty(self):
190 """Return True if this managers cached resource is dirty.
191-
192+
193 Calling when the resource is not currently held has undefined
194 behaviour.
195 """
196@@ -525,7 +528,7 @@
197
198 def make(self, dependency_resources):
199 """Override this to construct resources.
200-
201+
202 :param dependency_resources: A dict mapping name -> resource instance
203 for the resources specified as dependencies.
204 """
205@@ -534,7 +537,7 @@
206
207 def neededResources(self):
208 """Return the resources needed for this resource, including self.
209-
210+
211 :return: A list of needed resources, in topological deepest-first
212 order.
213 """
214@@ -553,7 +556,7 @@
215 """Overridable method to return a clean version of old_resource.
216
217 By default, the resource will be cleaned then remade if it had
218- previously been `dirtied`.
219+ previously been `dirtied`.
220
221 This function needs to take the dependent resource stack into
222 consideration as _make_all and _clean_all do.
223@@ -574,12 +577,13 @@
224 self._dirty = False
225 TestResource = TestResourceManager
226
227+
228 class GenericResource(TestResource):
229 """A TestResource that decorates an external helper of some kind.
230
231- GenericResource can be used to adapt an external resource so that
232+ GenericResource can be used to adapt an external resource so that
233 testresources can use it. By default the setUp and tearDown methods are
234- called when making and cleaning the resource, and the resource is
235+ called when making and cleaning the resource, and the resource is
236 considered permanently dirty, so it is torn down and brought up again
237 between every use.
238
239@@ -690,7 +694,7 @@
240
241 def setUpResources(test, resources, result):
242 """Set up resources for test.
243-
244+
245 :param test: The test to setup resources for.
246 :param resources: The resources to setup.
247 :param result: A result object for tracing resource activity.
248@@ -701,7 +705,7 @@
249
250 def tearDownResources(test, resources, result):
251 """Tear down resources for test.
252-
253+
254 :param test: The test to tear down resources from.
255 :param resources: The resources to tear down.
256 :param result: A result object for tracing resource activity.
257@@ -718,7 +722,7 @@
258 The result is passed to a run() or a __call__ method 4 or more frames
259 up: that method is what calls setUp and tearDown, and they call their
260 parent setUp etc. Its not guaranteed that the parameter to run will
261- be calls result as its not required to be a keyword parameter in
262+ be calls result as its not required to be a keyword parameter in
263 TestCase. However, in practice, this works.
264 """
265 stack = inspect.stack()
266@@ -730,4 +734,3 @@
267 if (result is not None and
268 getattr(result, 'startTest', None) is not None):
269 return result
270-

Subscribers

People subscribed via source and target branches