From dc820756cf0b9dce31463a1fcb9e2367c3b38389 Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Sat, 5 Jan 2019 13:54:14 +0000 Subject: [PATCH] Accept all known issues (by file) Signed-off-by: Niels Thykier --- tests/test_inst_tester.py | 1 - tests/test_pycodestyle.py | 55 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/tests/test_inst_tester.py b/tests/test_inst_tester.py index b231181..de229b3 100644 --- a/tests/test_inst_tester.py +++ b/tests/test_inst_tester.py @@ -563,4 +563,3 @@ class TestInstTester(unittest.TestCase): if __name__ == '__main__': unittest.main() - diff --git a/tests/test_pycodestyle.py b/tests/test_pycodestyle.py index b336cf3..9bf857a 100644 --- a/tests/test_pycodestyle.py +++ b/tests/test_pycodestyle.py @@ -3,13 +3,60 @@ import unittest import pycodestyle +EXCEPTIONS_BY_FILE = { + 'britney.py': 36, + 'britney2/__init__.py': 2, + 'britney2/excuse.py': 5, + 'britney2/hints.py': 8, + 'britney2/installability/tester.py': 4, + 'britney2/policies/__init__.py': 2, + 'britney2/policies/policy.py': 27, + 'britney2/policies/autopkgtest.py': 9, + 'tests/mock_swift.py': 2, + 'tests/__init__.py': 31, + 'tests/test_autopkgtest.py': 338, + 'tests/test_policy.py': 31, + 'tests/test_yaml.py': 1, +} + + +def _on_error(e): + raise e + + +def all_python_files(project_dir): + + for basedir, subdirs, files in os.walk(project_dir, onerror=_on_error): + if basedir == project_dir: + if '.git' in subdirs: + subdirs.remove('.git') + if 'doc' in subdirs: + subdirs.remove('doc') + + subdirs.sort() + files.sort() + + for file in files: + if file.endswith('.py'): + path = os.path.join(basedir, file) + name = path[len(project_dir)+1:] + yield path, name + + class TestCodeFormat(unittest.TestCase): def test_conformance(self): """Test that we conform to PEP-8.""" project_dir = os.path.dirname(os.path.dirname(__file__)) codestyle_cfg = os.path.join(project_dir, 'setup.cfg') - style = pycodestyle.StyleGuide(config_file=codestyle_cfg) - result = style.check_files('.') - self.assertEqual(result.total_errors, 0, - "Found code style errors (and warnings).") + for python_file, name in all_python_files(project_dir): + options = { + 'config_file': codestyle_cfg, + } + style = pycodestyle.StyleGuide(**options) + result = style.input_file(python_file) + limit = EXCEPTIONS_BY_FILE.get(name, 0) + # The number are the "unfixed" errors at time of introduction. + # As we fix them, this number should be reduced. + self.assertEqual(result, limit, + "Found code style errors (and warnings) in %s (%s)." % (name, python_file))