Check everything with pylint (not only errors)
Benjamin Drung
7 years ago
44 | 44 | $(foreach python,$(shell pyversions -r && py3versions -r),cd python && $(python) setup.py test$(\n)) |
45 | 45 | |
46 | 46 | clean: |
47 | rm -rf debian-distro-info ubuntu-distro-info python/build python/*.egg-info | |
47 | rm -rf debian-distro-info ubuntu-distro-info python/build python/*.egg-info python/.pylint.d | |
48 | 48 | find python -name '*.pyc' -delete |
49 | 49 | |
50 | 50 | .PHONY: build clean install test test-commandline test-perl test-python |
5 | 5 | Build-Depends: debhelper (>= 9), |
6 | 6 | distro-info-data (>= 0.7~), |
7 | 7 | pylint, |
8 | pylint3, | |
8 | 9 | python-all (>= 2.6.3-3~), |
9 | 10 | python-setuptools, |
10 | 11 | python-unittest2, |
0 | [MESSAGES CONTROL] | |
1 | ||
2 | # Disable the message, report, category or checker with the given id(s). You | |
3 | # can either give multiple identifiers separated by comma (,) or put this | |
4 | # option multiple times (only on the command line, not in the configuration | |
5 | # file where it should appear only once).You can also use "--disable=all" to | |
6 | # disable everything first and then reenable specific checks. For example, if | |
7 | # you want to run only the similarities checker, you can use "--disable=all | |
8 | # --enable=similarities". If you want to run only the classes checker, but have | |
9 | # no Warning level messages displayed, use"--disable=all --enable=classes | |
10 | # --disable=W" | |
11 | disable=invalid-name,locally-disabled,missing-docstring | |
12 | ||
13 | ||
0 | 14 | [FORMAT] |
1 | 15 | |
2 | 16 | # Maximum number of characters on a single line. |
3 | max-line-length=80 | |
17 | max-line-length=99 | |
4 | 18 | |
5 | # String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 | |
19 | # String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 | |
6 | 20 | # tab). |
7 | 21 | indent-string=' ' |
22 | ||
23 | [SIMILARITIES] | |
24 | ||
25 | # Minimum lines number of a similarity. | |
26 | min-similarity-lines=11 |
0 | # test_pylint.py - Run pylint in errors-only mode. | |
0 | # test_pylint.py - Run pylint | |
1 | 1 | # |
2 | 2 | # Copyright (C) 2010, Stefano Rivera <stefanor@debian.org> |
3 | # Copyright (C) 2017, Benjamin Drung <bdrung@debian.org> | |
3 | 4 | # |
4 | 5 | # Permission to use, copy, modify, and/or distribute this software for any |
5 | 6 | # purpose with or without fee is hereby granted, provided that the above |
14 | 15 | # PERFORMANCE OF THIS SOFTWARE. |
15 | 16 | |
16 | 17 | import subprocess |
18 | import sys | |
17 | 19 | |
18 | 20 | import setup |
19 | 21 | from distro_info_test import unittest |
20 | ||
21 | WHITELIST = [] | |
22 | 22 | |
23 | 23 | |
24 | 24 | class PylintTestCase(unittest.TestCase): |
25 | 25 | def test_pylint(self): |
26 | 26 | "Test: Run pylint on Python source code" |
27 | files = ['distro_info.py'] | |
27 | files = setup.PACKAGES + [m + '.py' for m in setup.PY_MODULES] + ['setup.py'] | |
28 | 28 | for script in setup.SCRIPTS: |
29 | 29 | script_file = open(script, 'r') |
30 | 30 | if 'python' in script_file.readline(): |
31 | 31 | files.append(script) |
32 | 32 | script_file.close() |
33 | cmd = ['pylint', '--rcfile=distro_info_test/pylint.conf', '-E', | |
34 | '--include-ids=y', '--'] + files | |
35 | process = subprocess.Popen(cmd, stdout=subprocess.PIPE, | |
33 | if sys.version_info[0] == 3: | |
34 | pylint_binary = 'pylint3' | |
35 | else: | |
36 | pylint_binary = 'pylint' | |
37 | cmd = [pylint_binary, '--rcfile=distro_info_test/pylint.conf', '--reports=n', '--'] + files | |
38 | process = subprocess.Popen(cmd, env={'PYLINTHOME': '.pylint.d'}, stdout=subprocess.PIPE, | |
36 | 39 | stderr=subprocess.PIPE, close_fds=True) |
37 | 40 | |
38 | 41 | out, err = process.communicate() |
39 | if err != '': | |
40 | raise unittest.SkipTest('pylint crashed :/') | |
41 | ||
42 | filtered_out = [] | |
43 | detected_in = '' | |
44 | for line in out.splitlines(): | |
45 | if line.startswith('************* '): | |
46 | detected_in = line | |
47 | continue | |
48 | ||
49 | for reg_exp in WHITELIST: | |
50 | if reg_exp.search(line): | |
51 | break | |
52 | else: | |
53 | filtered_out.append(detected_in) | |
54 | filtered_out.append(line) | |
55 | ||
56 | self.assertEqual(filtered_out, [], | |
57 | "pylint found errors.\n" | |
58 | "Filtered Output:\n" + '\n'.join(filtered_out)) | |
42 | self.assertFalse(err, pylint_binary + ' crashed. Error output:\n' + err.decode()) | |
43 | self.assertFalse(out, pylint_binary + " found errors:\n" + out.decode()) |
5 | 5 | from setuptools import setup |
6 | 6 | |
7 | 7 | |
8 | PACKAGES = ['distro_info_test'] | |
9 | PY_MODULES = ['distro_info'] | |
8 | 10 | SCRIPTS = [ |
9 | 11 | 'debian-distro-info', |
10 | 12 | 'ubuntu-distro-info', |
27 | 29 | setup( |
28 | 30 | name='distro-info', |
29 | 31 | version=get_debian_version(), |
30 | py_modules=['distro_info'], | |
31 | packages=['distro_info_test'], | |
32 | py_modules=PY_MODULES, | |
33 | packages=PACKAGES, | |
32 | 34 | test_suite='distro_info_test.discover', |
33 | 35 | ) |