Skip to content

Commit 8e7b671

Browse files
committed
Instrument code coverage
1 parent 0e0b958 commit 8e7b671

File tree

5 files changed

+82
-76
lines changed

5 files changed

+82
-76
lines changed

.coveragerc

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[run]
2+
source = .
3+
branch = true
4+
parallel = true
5+
omit =
6+
*/.tox/*
7+
*/__main__.py
8+
*/setup.py
9+
*/venv*/*
10+
# TODO: separate the tests from the test data
11+
testsuite/E*.py
12+
testsuite/W*.py
13+
testsuite/latin-1.py
14+
testsuite/noqa.py
15+
testsuite/python*.py
16+
testsuite/utf-8-bom.py
17+
18+
[report]
19+
show_missing = True
20+
skip_covered = True
21+
# TODO: increase this
22+
fail_under = 90
23+
exclude_lines =
24+
# a more strict default pragma
25+
\# pragma: no cover\b
26+
27+
# allow defensive code
28+
^\s*raise AssertionError\b
29+
^\s*raise NotImplementedError\b
30+
^\s*return NotImplemented\b
31+
^\s*raise$
32+
33+
# typing-related code
34+
^if (False|TYPE_CHECKING):
35+
: \.\.\.$
36+
^ +\.\.\.$
37+
-> ['"]?NoReturn['"]?:
38+
39+
# non-runnable code
40+
if __name__ == ['"]__main__['"]:$

.gitignore

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
*.egg
22
*.egg-info
33
*.pyc
4-
.tox
5-
dist
6-
docs/_build
7-
build/
4+
/.coverage
5+
/.tox
6+
/build/
7+
/dist
88
/venv*/
9+
docs/_build

testsuite/test_all.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -45,31 +45,3 @@ def test_own_dog_food(self):
4545
report = self._style.check_files(files)
4646
self.assertEqual(list(report.messages.keys()), ['W504'],
4747
msg='Failures: %s' % report.messages)
48-
49-
50-
def suite():
51-
from testsuite import (
52-
test_api,
53-
test_blank_lines,
54-
test_parser,
55-
test_shell,
56-
test_util,
57-
)
58-
59-
suite = unittest.TestSuite()
60-
suite.addTest(unittest.makeSuite(PycodestyleTestCase))
61-
suite.addTest(unittest.makeSuite(test_api.APITestCase))
62-
suite.addTest(unittest.makeSuite(test_blank_lines.TestBlankLinesDefault))
63-
suite.addTest(unittest.makeSuite(test_blank_lines.TestBlankLinesTwisted))
64-
suite.addTest(unittest.makeSuite(test_parser.ParserTestCase))
65-
suite.addTest(unittest.makeSuite(test_shell.ShellTestCase))
66-
suite.addTest(unittest.makeSuite(test_util.UtilTestCase))
67-
return suite
68-
69-
70-
def _main():
71-
return unittest.TextTestRunner(verbosity=2).run(suite())
72-
73-
74-
if __name__ == '__main__':
75-
sys.exit(not _main())

testsuite/test_api.py

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -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' %

tox.ini

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@
55

66
[tox]
77
envlist = py27, py34, py35, py36, py37, py38, pypy, pypy3, jython
8-
skipsdist = True
98
skip_missing_interpreters = True
109

1110
[testenv]
11+
deps = coverage
1212
commands =
13-
{envpython} setup.py install
14-
{envpython} pycodestyle.py --max-doc-length=72 --testsuite testsuite
15-
{envpython} pycodestyle.py --statistics pycodestyle.py
16-
{envpython} pycodestyle.py --max-doc-length=72 --doctest
17-
{envpython} setup.py test
13+
python -m pycodestyle --statistics pycodestyle.py
14+
coverage run -m pycodestyle --max-doc-length=72 --testsuite testsuite
15+
coverage run -m pycodestyle --max-doc-length=72 --doctest
16+
coverage run -m unittest discover testsuite -vv
17+
coverage combine
18+
coverage report
1819

1920
[testenv:flake8]
20-
deps =
21-
flake8
21+
skip_install = true
22+
deps = flake8
2223
commands =
2324
flake8 pycodestyle.py

0 commit comments

Comments
 (0)