Merge lp:~jelmer/brz/sort-changes into lp:brz

Proposed by Jelmer Vernooij on 2018-08-18
Status: Merged
Approved by: Jelmer Vernooij on 2018-08-20
Approved revision: 7069
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/sort-changes
Merge into: lp:brz
Diff against target: 321 lines (+50/-38)
3 files modified
breezy/delta.py (+3/-1)
breezy/tests/per_intertree/test_compare.py (+42/-35)
breezy/transform.py (+5/-2)
To merge this branch: bzr merge lp:~jelmer/brz/sort-changes
Reviewer Review Type Date Requested Status
Martin Packman 2018-08-18 Approve on 2018-08-20
Review via email: mp+353368@code.launchpad.net

Commit message

Fix sorting of changes in some tests on Python 3.

Description of the change

Fix sorting of changes in some tests on Python 3.

To post a comment you must log in.
Martin Packman (gz) wrote :

Thanks! See inline nit about where to put key functions.

review: Approve
lp:~jelmer/brz/sort-changes updated on 2018-08-20
7069. By Jelmer Vernooij on 2018-08-20

Move key function to top-level.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/delta.py'
2--- breezy/delta.py 2018-08-03 02:26:35 +0000
3+++ breezy/delta.py 2018-08-20 21:52:41 +0000
4@@ -165,7 +165,9 @@
5 delta.removed.sort()
6 delta.added.sort()
7 delta.renamed.sort()
8- delta.missing.sort()
9+ def missing_key(change):
10+ return (change[0] or '', change[1])
11+ delta.missing.sort(key=missing_key)
12 # TODO: jam 20060529 These lists shouldn't need to be sorted
13 # since we added them in alphabetical order.
14 delta.modified.sort()
15
16=== modified file 'breezy/tests/per_intertree/test_compare.py'
17--- breezy/tests/per_intertree/test_compare.py 2018-08-02 01:10:26 +0000
18+++ breezy/tests/per_intertree/test_compare.py 2018-08-20 21:52:41 +0000
19@@ -47,6 +47,15 @@
20 # that should just be the default for these tests, by changing
21 # make_branch_and_tree. mbp 20070307
22
23+
24+def _change_key(change):
25+ """Return a valid key for sorting Tree.iter_changes entries."""
26+ (file_id, paths, content_changed, versioned, parent, name, kind,
27+ executable) = change
28+ return (file_id or b'', (paths[0] or '', paths[1] or ''), versioned,
29+ parent, name, kind, executable)
30+
31+
32 class TestCompare(TestCaseWithTwoTrees):
33
34 def _make_abc_tree(self, tree):
35@@ -414,8 +423,8 @@
36 :param left_changes: A list of the output from iter_changes.
37 :param right_changes: A list of the output from iter_changes.
38 """
39- left_changes = sorted(left_changes)
40- right_changes = sorted(right_changes)
41+ left_changes = self.sorted(left_changes)
42+ right_changes = self.sorted(right_changes)
43 if left_changes == right_changes:
44 return
45 # setify to get item by item differences, but we can only do this
46@@ -448,15 +457,10 @@
47 :param **extra_args: Extra args to pass to iter_changes. This is not
48 inspected by this test helper.
49 """
50- tree1.lock_read()
51- tree2.lock_read()
52- try:
53+ with tree1.lock_read(), tree2.lock_read():
54 # sort order of output is not strictly defined
55- return sorted(self.intertree_class(tree1, tree2)
56+ return self.sorted(self.intertree_class(tree1, tree2)
57 .iter_changes(**extra_args))
58- finally:
59- tree1.unlock()
60- tree2.unlock()
61
62 def check_has_changes(self, expected, tree1, tree2):
63 # has_changes is defined for mutable trees only
64@@ -623,13 +627,16 @@
65 (None, basename), (None, kind),
66 (None, False))
67
68+ def sorted(self, changes):
69+ return sorted(changes, key=_change_key)
70+
71 def test_empty_to_abc_content(self):
72 tree1 = self.make_branch_and_tree('1')
73 tree2 = self.make_to_branch_and_tree('2')
74 tree1 = self.get_tree_no_parents_no_content(tree1)
75 tree2 = self.get_tree_no_parents_abc_content(tree2)
76 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
77- expected_results = sorted([
78+ expected_results = self.sorted([
79 self.added(tree2, b'root-id'),
80 self.added(tree2, b'a-id'),
81 self.added(tree2, b'b-id'),
82@@ -653,7 +660,7 @@
83 tree1 = self.get_tree_no_parents_no_content(tree1)
84 tree2 = self.get_tree_no_parents_abc_content(tree2)
85 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
86- expected_results = sorted([
87+ expected_results = self.sorted([
88 self.added(tree2, b'root-id'),
89 self.added(tree2, b'a-id'),
90 self.added(tree2, b'b-id'),
91@@ -669,7 +676,7 @@
92 tree2 = self.get_tree_no_parents_abc_content(tree2)
93 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
94 self.assertEqual(
95- sorted([self.added(tree2, b'root-id'),
96+ self.sorted([self.added(tree2, b'root-id'),
97 self.added(tree2, b'a-id'),
98 self.deleted(tree1, b'empty-root-id')]),
99 self.do_iter_changes(tree1, tree2, specific_files=['a']))
100@@ -702,7 +709,7 @@
101 tree1 = self.get_tree_no_parents_no_content(tree1)
102 tree2 = self.get_tree_no_parents_abc_content(tree2)
103 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
104- expected_result = sorted([self.added(tree2, b'root-id'),
105+ expected_result = self.sorted([self.added(tree2, b'root-id'),
106 self.added(tree2, b'a-id'), self.added(tree2, b'b-id'),
107 self.added(tree2, b'c-id'), self.deleted(tree1, b'empty-root-id')])
108 self.assertEqual(expected_result,
109@@ -714,7 +721,7 @@
110 tree1 = self.get_tree_no_parents_abc_content(tree1)
111 tree2 = self.get_tree_no_parents_no_content(tree2)
112 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
113- expected_results = sorted([
114+ expected_results = self.sorted([
115 self.added(tree2, b'empty-root-id'),
116 self.deleted(tree1, b'root-id'), self.deleted(tree1, b'a-id'),
117 self.deleted(tree1, b'b-id'), self.deleted(tree1, b'c-id')])
118@@ -1047,7 +1054,7 @@
119 tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
120 self.not_applicable_if_missing_in('a', tree2)
121 self.not_applicable_if_missing_in('b', tree2)
122- expected = sorted([
123+ expected = self.sorted([
124 self.missing(b'a-id', 'a', 'a', b'root-id', 'file'),
125 self.missing(b'b-id', 'b', 'b', b'root-id', 'directory'),
126 self.missing(b'c-id', 'b/c', 'b/c', b'b-id', 'file'),
127@@ -1067,7 +1074,7 @@
128 self.not_applicable_if_missing_in('directory', tree2)
129
130 root_id = tree1.path2id('')
131- expected = sorted([
132+ expected = self.sorted([
133 self.missing(b'file-id', 'file', 'directory', root_id, 'file'),
134 ])
135 self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
136@@ -1217,7 +1224,7 @@
137
138 # We should ignore the fact that 'b' exists in tree-2
139 # because the want_unversioned parameter was not given.
140- expected = sorted([
141+ expected = self.sorted([
142 self.content_changed(tree2, b'a-id'),
143 self.content_changed(tree2, b'c-id'),
144 ])
145@@ -1242,7 +1249,7 @@
146 ]
147 if links_supported:
148 expected.append(self.unversioned(tree2, 'link'))
149- expected = sorted(expected)
150+ expected = self.sorted(expected)
151 self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
152 want_unversioned=True))
153
154@@ -1265,7 +1272,7 @@
155 if links_supported:
156 expected.append(self.unversioned(tree2, 'link'))
157 specific_files.append('link')
158- expected = sorted(expected)
159+ expected = self.sorted(expected)
160 self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
161 specific_files=specific_files, require_versioned=False,
162 want_unversioned=True))
163@@ -1310,7 +1317,7 @@
164 expected.append(self.renamed(tree1, tree2, b'link-id', False))
165 expected.append(self.unversioned(tree2, 'link'))
166 specific_files.append('link')
167- expected = sorted(expected)
168+ expected = self.sorted(expected)
169 # run once with, and once without specific files, to catch
170 # potentially different code paths.
171 self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
172@@ -1351,7 +1358,7 @@
173
174 self.assertEqual([], self.do_iter_changes(tree1, tree2,
175 want_unversioned=True))
176- expected = sorted([
177+ expected = self.sorted([
178 self.unchanged(tree2, tree2.get_root_id()),
179 self.unchanged(tree2, b'a-id'),
180 self.unchanged(tree2, b'b-id'),
181@@ -1436,7 +1443,7 @@
182 self.kind_changed(tree1, tree2, b'todir'),
183 self.kind_changed(tree1, tree2, b'tofile'),
184 ]
185- expected = sorted(expected)
186+ expected = self.sorted(expected)
187 self.assertEqual(expected,
188 self.do_iter_changes(tree1, tree2, include_unchanged=True,
189 want_unversioned=True))
190@@ -1455,7 +1462,7 @@
191 self.kind_changed(tree1, tree2, b'todir'),
192 self.kind_changed(tree1, tree2, b'tofile'),
193 ]
194- expected = sorted(expected)
195+ expected = self.sorted(expected)
196 # we should get back just the changed links. We pass in 'unchanged' to
197 # make sure that it is correctly not returned - and neither is the
198 # unknown path 'unknown' which it points at.
199@@ -1466,13 +1473,13 @@
200
201 def test_tree_with_special_names(self):
202 tree1, tree2, paths, path_ids = self.make_tree_with_special_names()
203- expected = sorted(self.added(tree2, f_id) for f_id in path_ids)
204+ expected = self.sorted(self.added(tree2, f_id) for f_id in path_ids)
205 self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
206 self.check_has_changes(True, tree1, tree2)
207
208 def test_trees_with_special_names(self):
209 tree1, tree2, paths, path_ids = self.make_trees_with_special_names()
210- expected = sorted(self.content_changed(tree2, f_id) for f_id in path_ids
211+ expected = self.sorted(self.content_changed(tree2, f_id) for f_id in path_ids
212 if f_id.endswith(b'_f-id'))
213 self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
214 self.check_has_changes(True, tree1, tree2)
215@@ -1650,7 +1657,7 @@
216
217 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
218
219- expected = sorted([
220+ expected = self.sorted([
221 self.unchanged(tree1, root_id),
222 self.unchanged(tree1, a_id),
223 self.unchanged(tree1, subfile_id),
224@@ -1661,7 +1668,7 @@
225 include_unchanged=True))
226
227 # We should also be able to select just a subset
228- expected = sorted([
229+ expected = self.sorted([
230 self.unchanged(tree1, a_id),
231 self.unchanged(tree1, subfile_id),
232 ])
233@@ -1693,7 +1700,7 @@
234 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
235 self.not_applicable_if_cannot_represent_unversioned(tree2)
236
237- expected = sorted([
238+ expected = self.sorted([
239 self.unversioned(tree2, u'\u03b1/unknown_dir'),
240 self.unversioned(tree2, u'\u03b1/unknown_file'),
241 self.unversioned(tree2, u'\u03c9-unknown_root_file'),
242@@ -1710,7 +1717,7 @@
243 self.check_has_changes(False, tree1, tree2)
244
245 # We should also be able to select just a subset
246- expected = sorted([
247+ expected = self.sorted([
248 self.unversioned(tree2, u'\u03b1/unknown_dir'),
249 self.unversioned(tree2, u'\u03b1/unknown_file'),
250 ])
251@@ -1745,7 +1752,7 @@
252 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
253 self.not_applicable_if_cannot_represent_unversioned(tree2)
254
255- expected = sorted([
256+ expected = self.sorted([
257 self.unversioned(tree2, u'a/file'),
258 self.unversioned(tree2, u'a/dir'),
259 ])
260@@ -1780,7 +1787,7 @@
261
262 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
263
264- expected = sorted([
265+ expected = self.sorted([
266 self.deleted(tree1, b'a-id'),
267 self.deleted(tree1, b'd-id'),
268 self.renamed(tree1, tree2, b'b-id', False),
269@@ -1814,14 +1821,14 @@
270 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
271 self.not_applicable_if_cannot_represent_unversioned(tree2)
272
273- expected = sorted([
274+ expected = self.sorted([
275 self.deleted(tree1, b'b-id'),
276 self.unversioned(tree2, 'b'),
277 ])
278 self.assertEqual(expected,
279 self.do_iter_changes(tree1, tree2,
280 want_unversioned=True))
281- expected = sorted([
282+ expected = self.sorted([
283 self.deleted(tree1, b'b-id'),
284 ])
285 self.assertEqual(expected,
286@@ -1854,7 +1861,7 @@
287
288 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
289
290- expected = sorted([
291+ expected = self.sorted([
292 self.renamed(tree1, tree2, b'b1-id', False),
293 self.renamed(tree1, tree2, b'c1-id', False),
294 self.added(tree2, b'b2-id'),
295@@ -1888,7 +1895,7 @@
296 tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
297 self.not_applicable_if_missing_in('a', tree2)
298
299- expected = sorted([
300+ expected = self.sorted([
301 self.missing(b'a-id', 'a', 'a', tree2.get_root_id(), 'file'),
302 self.unversioned(tree2, 'a2'),
303 ])
304
305=== modified file 'breezy/transform.py'
306--- breezy/transform.py 2018-08-07 20:43:32 +0000
307+++ breezy/transform.py 2018-08-20 21:52:41 +0000
308@@ -1960,8 +1960,11 @@
309 path = self._tree_id_paths[parent_id]
310 except KeyError:
311 return
312- entry = next(self._tree.iter_entries_by_dir(
313- specific_files=[path]))[1]
314+ try:
315+ entry = next(self._tree.iter_entries_by_dir(
316+ specific_files=[path]))[1]
317+ except StopIteration:
318+ return
319 children = getattr(entry, 'children', {})
320 for child in children:
321 childpath = joinpath(path, child)

Subscribers

People subscribed via source and target branches