Merge lp:~gz/brz/flake8_source_test into lp:brz

Proposed by Martin Packman
Status: Merged
Approved by: Martin Packman
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~gz/brz/flake8_source_test
Merge into: lp:brz
Diff against target: 374 lines (+58/-71)
6 files modified
breezy/bzr/__init__.py (+1/-1)
breezy/git/tests/test_tree.py (+26/-23)
breezy/tests/__init__.py (+7/-0)
breezy/tests/blackbox/test_big_file.py (+0/-3)
breezy/tests/test_source.py (+20/-42)
setup.cfg (+4/-2)
To merge this branch: bzr merge lp:~gz/brz/flake8_source_test
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+407491@code.launchpad.net

Commit message

Make flake8 source test behave

Description of the change

Using the new 'legacy' api where possible, skipping only on compat issues.

Next text_log_file() test method to get context for writing text in.

Ignore some more error types, fix a few lint complaints.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/bzr/__init__.py'
2--- breezy/bzr/__init__.py 2020-07-28 02:11:05 +0000
3+++ breezy/bzr/__init__.py 2021-08-21 13:33:23 +0000
4@@ -51,7 +51,7 @@
5 raise errors.NotBranchError(path=transport.base)
6 except errors.BadHttpRequest as e:
7 if e.reason == 'no such method: .bzr':
8- # hgweb
9+ # hgweb
10 raise errors.NotBranchError(path=transport.base)
11 raise
12
13
14=== modified file 'breezy/git/tests/test_tree.py'
15--- breezy/git/tests/test_tree.py 2021-08-20 15:04:24 +0000
16+++ breezy/git/tests/test_tree.py 2021-08-21 13:33:23 +0000
17@@ -34,6 +34,9 @@
18 from breezy.git.mapping import default_mapping
19
20
21+REG_MODE = stat.S_IFREG | 0o644
22+
23+
24 class ChangesFromGitChangesTests(TestCase):
25
26 def setUp(self):
27@@ -62,7 +65,7 @@
28 (False, False), False)
29 ], self.transform([
30 ('modify',
31- (b'a', stat.S_IFREG|0o644, a), (b'a', stat.S_IFREG|0o644, b))]))
32+ (b'a', REG_MODE, a), (b'a', REG_MODE, b))]))
33
34 def test_kind_changed(self):
35 a = Blob.from_string(b'a')
36@@ -74,7 +77,7 @@
37 (False, False), False)
38 ], self.transform([
39 ('modify',
40- (b'a', stat.S_IFREG|0o644, a), (b'a', stat.S_IFLNK, b))]))
41+ (b'a', REG_MODE, a), (b'a', stat.S_IFLNK, b))]))
42
43 def test_rename_no_changes(self):
44 a = Blob.from_string(b'a')
45@@ -85,7 +88,7 @@
46 ('file', 'file'), (False, False), False)
47 ], self.transform([
48 ('rename',
49- (b'old', stat.S_IFREG|0o644, a), (b'a', stat.S_IFREG|0o644, a))]))
50+ (b'old', REG_MODE, a), (b'a', REG_MODE, a))]))
51
52 def test_rename_and_modify(self):
53 a = Blob.from_string(b'a')
54@@ -97,7 +100,7 @@
55 ('file', 'file'), (False, False), False)
56 ], self.transform([
57 ('rename',
58- (b'a', stat.S_IFREG|0o644, a), (b'b', stat.S_IFREG|0o644, b))]))
59+ (b'a', REG_MODE, a), (b'b', REG_MODE, b))]))
60
61 def test_copy_no_changes(self):
62 a = Blob.from_string(b'a')
63@@ -108,7 +111,7 @@
64 ('file', 'file'), (False, False), True)
65 ], self.transform([
66 ('copy',
67- (b'old', stat.S_IFREG|0o644, a), (b'a', stat.S_IFREG|0o644, a))]))
68+ (b'old', REG_MODE, a), (b'a', REG_MODE, a))]))
69
70 def test_copy_and_modify(self):
71 a = Blob.from_string(b'a')
72@@ -120,7 +123,7 @@
73 ('file', 'file'), (False, False), True)
74 ], self.transform([
75 ('copy',
76- (b'a', stat.S_IFREG|0o644, a), (b'b', stat.S_IFREG|0o644, b))]))
77+ (b'a', REG_MODE, a), (b'b', REG_MODE, b))]))
78
79 def test_add(self):
80 b = Blob.from_string(b'b')
81@@ -130,7 +133,7 @@
82 (None, 'a'), (None, 'file'), (None, False), False)
83 ], self.transform([
84 ('add',
85- (None, None, None), (b'a', stat.S_IFREG|0o644, b))]))
86+ (None, None, None), (b'a', REG_MODE, b))]))
87
88 def test_delete(self):
89 b = Blob.from_string(b'b')
90@@ -140,7 +143,7 @@
91 ('a', None), ('file', None), (False, None), False)
92 ], self.transform([
93 ('remove',
94- (b'a', stat.S_IFREG|0o644, b), (None, None, None))]))
95+ (b'a', REG_MODE, b), (None, None, None))]))
96
97 def test_unchanged(self):
98 b = Blob.from_string(b'b')
99@@ -151,11 +154,11 @@
100 (False, False), False)
101 ], self.transform([
102 ('unchanged',
103- (b'a', stat.S_IFREG|0o644, b), (b'a', stat.S_IFREG|0o644, b))],
104+ (b'a', REG_MODE, b), (b'a', REG_MODE, b))],
105 include_unchanged=True))
106 self.assertEqual([], self.transform([
107 ('unchanged',
108- (b'a', stat.S_IFREG|0o644, b), (b'a', stat.S_IFREG|0o644, b))],
109+ (b'a', REG_MODE, b), (b'a', REG_MODE, b))],
110 include_unchanged=False))
111
112 def test_unversioned(self):
113@@ -167,7 +170,7 @@
114 (None, False), False)
115 ], self.transform([
116 ('add',
117- (None, None, None), (b'a', stat.S_IFREG|0o644, b))],
118+ (None, None, None), (b'a', REG_MODE, b))],
119 target_extras=set([b'a'])))
120 self.assertEqual([
121 TreeChange(
122@@ -176,7 +179,7 @@
123 (False, False), False)
124 ], self.transform([
125 ('add',
126- (b'a', stat.S_IFREG|0o644, b), (b'a', stat.S_IFREG|0o644, b))],
127+ (b'a', REG_MODE, b), (b'a', REG_MODE, b))],
128 source_extras=set([b'a']),
129 target_extras=set([b'a'])))
130
131@@ -206,7 +209,7 @@
132 b = Blob.from_string(b'b')
133 delta = self.transform([
134 ('modify',
135- (b'a', stat.S_IFREG|0o644, a), (b'a', stat.S_IFREG|0o644, b))])
136+ (b'a', REG_MODE, a), (b'a', REG_MODE, b))])
137 expected_delta = TreeDelta()
138 expected_delta.modified.append(TreeChange(
139 b'git:a', ('a', 'a'), True, (True, True),
140@@ -218,7 +221,7 @@
141 a = Blob.from_string(b'a')
142 delta = self.transform([
143 ('rename',
144- (b'old', stat.S_IFREG|0o644, a), (b'a', stat.S_IFREG|0o644, a))])
145+ (b'old', REG_MODE, a), (b'a', REG_MODE, a))])
146 expected_delta = TreeDelta()
147 expected_delta.renamed.append(
148 TreeChange(
149@@ -232,7 +235,7 @@
150 b = Blob.from_string(b'b')
151 delta = self.transform([
152 ('rename',
153- (b'a', stat.S_IFREG|0o644, a), (b'b', stat.S_IFREG|0o644, b))])
154+ (b'a', REG_MODE, a), (b'b', REG_MODE, b))])
155 expected_delta = TreeDelta()
156 expected_delta.renamed.append(
157 TreeChange(
158@@ -245,7 +248,7 @@
159 a = Blob.from_string(b'a')
160 delta = self.transform([
161 ('copy',
162- (b'old', stat.S_IFREG|0o644, a), (b'a', stat.S_IFREG|0o644, a))])
163+ (b'old', REG_MODE, a), (b'a', REG_MODE, a))])
164 expected_delta = TreeDelta()
165 expected_delta.copied.append(TreeChange(
166 b'git:a', ('old', 'a'), False, (True, True),
167@@ -258,7 +261,7 @@
168 b = Blob.from_string(b'b')
169 delta = self.transform([
170 ('copy',
171- (b'a', stat.S_IFREG|0o644, a), (b'b', stat.S_IFREG|0o644, b))])
172+ (b'a', REG_MODE, a), (b'b', REG_MODE, b))])
173 expected_delta = TreeDelta()
174 expected_delta.copied.append(TreeChange(
175 b'git:b', ('a', 'b'), True, (True, True),
176@@ -270,7 +273,7 @@
177 b = Blob.from_string(b'b')
178 delta = self.transform([
179 ('add',
180- (None, None, None), (b'a', stat.S_IFREG|0o644, b))])
181+ (None, None, None), (b'a', REG_MODE, b))])
182 expected_delta = TreeDelta()
183 expected_delta.added.append(TreeChange(
184 b'git:a', (None, 'a'), True, (False, True), (None, b'TREE_ROOT'),
185@@ -281,7 +284,7 @@
186 b = Blob.from_string(b'b')
187 delta = self.transform([
188 ('remove',
189- (b'a', stat.S_IFREG | 0o644, b),
190+ (b'a', REG_MODE, b),
191 (None, None, None))])
192 expected_delta = TreeDelta()
193 expected_delta.removed.append(TreeChange(
194@@ -293,7 +296,7 @@
195 b = Blob.from_string(b'b')
196 delta = self.transform([
197 ('unchanged',
198- (b'a', stat.S_IFREG|0o644, b), (b'a', stat.S_IFREG|0o644, b))])
199+ (b'a', REG_MODE, b), (b'a', REG_MODE, b))])
200 expected_delta = TreeDelta()
201 expected_delta.unchanged.append(TreeChange(
202 b'git:a', ('a', 'a'), False, (True, True),
203@@ -304,7 +307,7 @@
204 b = Blob.from_string(b'b')
205 delta = self.transform([
206 ('add',
207- (None, None, None), (b'a', stat.S_IFREG|0o644, b))],
208+ (None, None, None), (b'a', REG_MODE, b))],
209 target_extras=set([b'a']))
210 expected_delta = TreeDelta()
211 expected_delta.unversioned.append(
212@@ -315,7 +318,7 @@
213 self.assertEqual(delta, expected_delta)
214 delta = self.transform([
215 ('add',
216- (b'a', stat.S_IFREG|0o644, b), (b'a', stat.S_IFREG|0o644, b))],
217+ (b'a', REG_MODE, b), (b'a', REG_MODE, b))],
218 source_extras=set([b'a']),
219 target_extras=set([b'a']))
220 expected_delta = TreeDelta()
221@@ -330,7 +333,7 @@
222 b = Blob.from_string(b'target')
223 delta = self.transform([
224 ('modify',
225- (b'a', stat.S_IFREG|0o644, a), (b'a', stat.S_IFLNK, b))])
226+ (b'a', REG_MODE, a), (b'a', stat.S_IFLNK, b))])
227 expected_delta = TreeDelta()
228 expected_delta.kind_changed.append(TreeChange(
229 b'git:a', ('a', 'a'), True, (True, True),
230
231=== modified file 'breezy/tests/__init__.py'
232--- breezy/tests/__init__.py 2021-08-20 15:32:58 +0000
233+++ breezy/tests/__init__.py 2021-08-21 13:33:23 +0000
234@@ -23,6 +23,7 @@
235
236 import atexit
237 import codecs
238+import contextlib
239 import copy
240 import difflib
241 import doctest
242@@ -1692,6 +1693,12 @@
243 self._log_memento = trace.push_log_file(self._log_file)
244 self.addCleanup(self._finishLogFile)
245
246+ @contextlib.contextmanager
247+ def text_log_file(self, **kwargs):
248+ stream = TextIOWrapper(self._log_file, encoding='utf-8', **kwargs)
249+ yield stream
250+ stream.detach()
251+
252 def _finishLogFile(self):
253 """Flush and dereference the in-memory log for this testcase"""
254 if trace._trace_file:
255
256=== modified file 'breezy/tests/blackbox/test_big_file.py'
257--- breezy/tests/blackbox/test_big_file.py 2020-05-30 03:06:21 +0000
258+++ breezy/tests/blackbox/test_big_file.py 2021-08-21 13:33:23 +0000
259@@ -41,9 +41,6 @@
260 RESOURCE = resource.RLIMIT_AS
261 LIMIT = 1024 * 1024 * 100
262
263-if sys.version_info[0] == 2:
264- range = xrange
265-
266
267 def make_big_file(path):
268 blob_1mb = BIG_FILE_CHUNK_SIZE * b'\x0c'
269
270=== modified file 'breezy/tests/test_source.py'
271--- breezy/tests/test_source.py 2021-08-20 14:07:13 +0000
272+++ breezy/tests/test_source.py 2021-08-21 13:33:23 +0000
273@@ -319,49 +319,27 @@
274 self.fail('\n\n'.join(problems))
275
276 def test_flake8(self):
277- try:
278- self.requireFeature(features.flake8)
279- except (SyntaxError, NameError):
280- # importlib_metadata uses ModuleNotFoundError, which is
281- # python 3.6 only
282- if sys.version_info[:2] <= (3, 5):
283- self.skipTest('python version too old')
284- raise
285- # Older versions of flake8 don't support the 'paths'
286- # variable
287- new_path = list(sys.path)
288- new_path.insert(
289- 0, os.path.join(os.path.dirname(__file__), '..', '..', 'tools'))
290- self.overrideAttr(sys, 'path', new_path)
291- import argparse
292- from flake8.main.application import Application
293- from flake8.formatting.base import BaseFormatter
294- app = Application()
295- app.config = u'setup.cfg'
296- app.jobs = 1
297-
298- class Formatter(BaseFormatter):
299-
300- def __init__(self):
301- self.errors = []
302-
303- def start(self):
304- pass
305-
306- def stop(self):
307- app.file_checker_manager.report()
308-
309- def handle(self, error):
310- self.errors.append(error)
311-
312- try:
313- app.initialize([])
314- except argparse.ArgumentError as e:
315+ self.requireFeature(features.flake8)
316+ try:
317+ from flake8.api.legacy import get_style_guide
318+ from flake8.main.options import JobsArgument
319+ from flake8.formatting.default import Default
320+
321+ style = get_style_guide(jobs=JobsArgument("1"))
322+ except Exception as e:
323 self.skipTest('broken flake8: %r' % e)
324- app.formatter = Formatter()
325- app.run_checks()
326- app.report()
327- self.assertEqual(app.formatter.errors, [])
328+
329+ with self.text_log_file() as log_file:
330+
331+ class Formatter(Default):
332+
333+ def after_init(self):
334+ self.output_fd = log_file
335+
336+ style.init_report(Formatter)
337+ report = style.check_files()
338+
339+ self.assertEqual(report.total_errors, 0)
340
341 def test_no_asserts(self):
342 """bzr shouldn't use the 'assert' statement."""
343
344=== modified file 'setup.cfg'
345--- setup.cfg 2018-11-20 23:50:57 +0000
346+++ setup.cfg 2021-08-21 13:33:23 +0000
347@@ -2,10 +2,11 @@
348 # Ignore E402 ("module level import not at top of file"),
349 # because even with the lazy import plugin it still triggers
350 # for lazy_import statements before other imports.
351+exclude = .git,__pycache__,build,dist,target
352 ignore =
353 D
354 I
355- E123
356+ E12
357 E261
358 E265
359 E266
360@@ -31,10 +32,11 @@
361 F812
362 F821
363 F841
364+ W391
365 W503
366 W504
367 W605
368-filename = *.py,brz
369+filename = *.py
370
371 [flake8:local-plugins]
372 extension =
373
374=== removed directory 'src'

Subscribers

People subscribed via source and target branches