@@ -43,8 +43,7 @@ def reset(self):
4343
4444 def test_register_physical_check (self ):
4545 def check_dummy (physical_line , line_number ):
46- if False :
47- yield
46+ raise NotImplementedError
4847 pycodestyle .register_check (check_dummy , ['Z001' ])
4948
5049 self .assertTrue (check_dummy in pycodestyle ._checks ['physical_line' ])
@@ -53,13 +52,12 @@ def check_dummy(physical_line, line_number):
5352 self .assertEqual (args , ['physical_line' , 'line_number' ])
5453
5554 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 )
5857
5958 def test_register_logical_check (self ):
6059 def check_dummy (logical_line , tokens ):
61- if False :
62- yield
60+ raise NotImplementedError
6361 pycodestyle .register_check (check_dummy , ['Z401' ])
6462
6563 self .assertTrue (check_dummy in pycodestyle ._checks ['logical_line' ])
@@ -74,8 +72,8 @@ def check_dummy(logical_line, tokens):
7472 self .assertEqual (args , ['logical_line' , 'tokens' ])
7573
7674 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 )
7977
8078 def test_register_ast_check (self ):
8179 pycodestyle .register_check (DummyChecker , ['Z701' ])
@@ -86,17 +84,17 @@ def test_register_ast_check(self):
8684 self .assertTrue (args is None )
8785
8886 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 )
9189
9290 def test_register_invalid_check (self ):
9391 class InvalidChecker (DummyChecker ):
9492 def __init__ (self , filename ):
95- pass
93+ raise NotImplementedError
9694
9795 def check_dummy (logical , tokens ):
98- if False :
99- yield
96+ raise NotImplementedError
97+
10098 pycodestyle .register_check (InvalidChecker , ['Z741' ])
10199 pycodestyle .register_check (check_dummy , ['Z441' ])
102100
@@ -272,28 +270,28 @@ def test_styleguide_checks(self):
272270
273271 # Do run E11 checks
274272 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 )
277275 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 )
280278 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 )
283281 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 )
286284
287285 # Do not run E11 checks
288286 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 )
291289 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 )
294292 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 )
297295
298296 def test_styleguide_init_report (self ):
299297 style = pycodestyle .StyleGuide (paths = [E11 ])
@@ -327,9 +325,7 @@ def test_styleguide_check_files(self):
327325 def test_check_unicode (self ):
328326 # Do not crash if lines are Unicode (Python 2.x)
329327 pycodestyle .register_check (DummyChecker , ['Z701' ])
330- source = '#\n '
331- if hasattr (source , 'decode' ):
332- source = source .decode ('ascii' )
328+ source = u'#\n '
333329
334330 pep8style = pycodestyle .StyleGuide ()
335331 count_errors = pep8style .input_file ('stdin' , lines = [source ])
@@ -345,13 +341,9 @@ def test_check_nullbytes(self):
345341 count_errors = pep8style .input_file ('stdin' , lines = ['\x00 \n ' ])
346342
347343 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+)
353345 expected = "stdin:1:1: E901 ValueError"
354- else :
346+ else : # pragma: no cover (< python3.5)
355347 expected = "stdin:1:1: E901 TypeError"
356348 self .assertTrue (stdout .startswith (expected ),
357349 msg = 'Output %r does not start with %r' %
0 commit comments