@@ -43,8 +43,7 @@ def reset(self):
43
43
44
44
def test_register_physical_check (self ):
45
45
def check_dummy (physical_line , line_number ):
46
- if False :
47
- yield
46
+ raise NotImplementedError
48
47
pycodestyle .register_check (check_dummy , ['Z001' ])
49
48
50
49
self .assertTrue (check_dummy in pycodestyle ._checks ['physical_line' ])
@@ -53,13 +52,12 @@ def check_dummy(physical_line, line_number):
53
52
self .assertEqual (args , ['physical_line' , 'line_number' ])
54
53
55
54
options = pycodestyle .StyleGuide ().options
56
- self . assertTrue ( any ( func == check_dummy
57
- for name , func , args in options . physical_checks ) )
55
+ functions = [ func for _ , func , _ in options . physical_checks ]
56
+ self . assertIn ( check_dummy , functions )
58
57
59
58
def test_register_logical_check (self ):
60
59
def check_dummy (logical_line , tokens ):
61
- if False :
62
- yield
60
+ raise NotImplementedError
63
61
pycodestyle .register_check (check_dummy , ['Z401' ])
64
62
65
63
self .assertTrue (check_dummy in pycodestyle ._checks ['logical_line' ])
@@ -74,8 +72,8 @@ def check_dummy(logical_line, tokens):
74
72
self .assertEqual (args , ['logical_line' , 'tokens' ])
75
73
76
74
options = pycodestyle .StyleGuide ().options
77
- self . assertTrue ( any ( func == check_dummy
78
- for name , func , args in options . logical_checks ) )
75
+ functions = [ func for _ , func , _ in options . logical_checks ]
76
+ self . assertIn ( check_dummy , functions )
79
77
80
78
def test_register_ast_check (self ):
81
79
pycodestyle .register_check (DummyChecker , ['Z701' ])
@@ -86,17 +84,17 @@ def test_register_ast_check(self):
86
84
self .assertTrue (args is None )
87
85
88
86
options = pycodestyle .StyleGuide ().options
89
- self . assertTrue ( any ( cls == DummyChecker
90
- for name , cls , args in options . ast_checks ) )
87
+ classes = [ cls for _ , cls , _ in options . ast_checks ]
88
+ self . assertIn ( DummyChecker , classes )
91
89
92
90
def test_register_invalid_check (self ):
93
91
class InvalidChecker (DummyChecker ):
94
92
def __init__ (self , filename ):
95
- pass
93
+ raise NotImplementedError
96
94
97
95
def check_dummy (logical , tokens ):
98
- if False :
99
- yield
96
+ raise NotImplementedError
97
+
100
98
pycodestyle .register_check (InvalidChecker , ['Z741' ])
101
99
pycodestyle .register_check (check_dummy , ['Z441' ])
102
100
@@ -272,28 +270,28 @@ def test_styleguide_checks(self):
272
270
273
271
# Do run E11 checks
274
272
options = pycodestyle .StyleGuide ().options
275
- self . assertTrue ( any ( func == pycodestyle . indentation
276
- for name , func , args in options . logical_checks ) )
273
+ functions = [ func for _ , func , _ in options . logical_checks ]
274
+ self . assertIn ( pycodestyle . indentation , functions )
277
275
options = pycodestyle .StyleGuide (select = ['E' ]).options
278
- self . assertTrue ( any ( func == pycodestyle . indentation
279
- for name , func , args in options . logical_checks ) )
276
+ functions = [ func for _ , func , _ in options . logical_checks ]
277
+ self . assertIn ( pycodestyle . indentation , functions )
280
278
options = pycodestyle .StyleGuide (ignore = ['W' ]).options
281
- self . assertTrue ( any ( func == pycodestyle . indentation
282
- for name , func , args in options . logical_checks ) )
279
+ functions = [ func for _ , func , _ in options . logical_checks ]
280
+ self . assertIn ( pycodestyle . indentation , functions )
283
281
options = pycodestyle .StyleGuide (ignore = ['E12' ]).options
284
- self . assertTrue ( any ( func == pycodestyle . indentation
285
- for name , func , args in options . logical_checks ) )
282
+ functions = [ func for _ , func , _ in options . logical_checks ]
283
+ self . assertIn ( pycodestyle . indentation , functions )
286
284
287
285
# Do not run E11 checks
288
286
options = pycodestyle .StyleGuide (select = ['W' ]).options
289
- self . assertFalse ( any ( func == pycodestyle . indentation
290
- for name , func , args in options . logical_checks ) )
287
+ functions = [ func for _ , func , _ in options . logical_checks ]
288
+ self . assertNotIn ( pycodestyle . indentation , functions )
291
289
options = pycodestyle .StyleGuide (ignore = ['E' ]).options
292
- self . assertFalse ( any ( func == pycodestyle . indentation
293
- for name , func , args in options . logical_checks ) )
290
+ functions = [ func for _ , func , _ in options . logical_checks ]
291
+ self . assertNotIn ( pycodestyle . indentation , functions )
294
292
options = pycodestyle .StyleGuide (ignore = ['E11' ]).options
295
- self . assertFalse ( any ( func == pycodestyle . indentation
296
- for name , func , args in options . logical_checks ) )
293
+ functions = [ func for _ , func , _ in options . logical_checks ]
294
+ self . assertNotIn ( pycodestyle . indentation , functions )
297
295
298
296
def test_styleguide_init_report (self ):
299
297
style = pycodestyle .StyleGuide (paths = [E11 ])
@@ -327,9 +325,7 @@ def test_styleguide_check_files(self):
327
325
def test_check_unicode (self ):
328
326
# Do not crash if lines are Unicode (Python 2.x)
329
327
pycodestyle .register_check (DummyChecker , ['Z701' ])
330
- source = '#\n '
331
- if hasattr (source , 'decode' ):
332
- source = source .decode ('ascii' )
328
+ source = u'#\n '
333
329
334
330
pep8style = pycodestyle .StyleGuide ()
335
331
count_errors = pep8style .input_file ('stdin' , lines = [source ])
@@ -345,13 +341,9 @@ def test_check_nullbytes(self):
345
341
count_errors = pep8style .input_file ('stdin' , lines = ['\x00 \n ' ])
346
342
347
343
stdout = sys .stdout .getvalue ()
348
- if 'SyntaxError' in stdout :
349
- # PyPy 2.2 returns a SyntaxError
350
- expected = "stdin:1:2: E901 SyntaxError"
351
- elif 'ValueError' in stdout :
352
- # Python 3.5.
344
+ if 'ValueError' in stdout : # pragma: no cover (python 3.5+)
353
345
expected = "stdin:1:1: E901 ValueError"
354
- else :
346
+ else : # pragma: no cover (< python3.5)
355
347
expected = "stdin:1:1: E901 TypeError"
356
348
self .assertTrue (stdout .startswith (expected ),
357
349
msg = 'Output %r does not start with %r' %
0 commit comments