Devuan deployment of britney2
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

71 lines
2.1 KiB

  1. import os
  2. import unittest
  3. import pycodestyle
  4. def should_skip_codestyle():
  5. if 'nocodestyle' in os.environ.get('TEST_FLAGS', ''):
  6. return True
  7. return False
  8. EXCEPTIONS_BY_FILE = {
  9. 'britney.py': 0,
  10. 'britney2/excuse.py': 0,
  11. 'britney2/excusefinder.py': 0,
  12. 'britney2/hints.py': 8,
  13. 'britney2/installability/tester.py': 4,
  14. 'britney2/policies/__init__.py': 0,
  15. 'britney2/policies/policy.py': 0,
  16. 'britney2/policies/autopkgtest.py': 0,
  17. 'tests/mock_swift.py': 2,
  18. 'tests/__init__.py': 31,
  19. 'tests/test_autopkgtest.py': 2,
  20. 'tests/test_yaml.py': 1,
  21. }
  22. def _on_error(e):
  23. raise e
  24. def all_python_files(project_dir):
  25. for basedir, subdirs, files in os.walk(project_dir, onerror=_on_error):
  26. if basedir == project_dir:
  27. if '.git' in subdirs:
  28. subdirs.remove('.git')
  29. if 'doc' in subdirs:
  30. subdirs.remove('doc')
  31. if 'britney2-tests' in subdirs:
  32. subdirs.remove('britney2-tests')
  33. subdirs.sort()
  34. files.sort()
  35. for file in files:
  36. if file.endswith('.py'):
  37. path = os.path.join(basedir, file)
  38. name = path[len(project_dir)+1:]
  39. yield path, name
  40. class TestCodeFormat(unittest.TestCase):
  41. @unittest.skipIf(should_skip_codestyle(), 'codestyle conformance skipped as requested')
  42. def test_conformance(self):
  43. """Test that we conform to PEP-8."""
  44. project_dir = os.path.dirname(os.path.dirname(__file__))
  45. codestyle_cfg = os.path.join(project_dir, 'setup.cfg')
  46. for python_file, name in all_python_files(project_dir):
  47. options = {
  48. 'config_file': codestyle_cfg,
  49. }
  50. style = pycodestyle.StyleGuide(**options)
  51. result = style.input_file(python_file)
  52. limit = EXCEPTIONS_BY_FILE.get(name, 0)
  53. # The number are the "unfixed" errors at time of introduction.
  54. # As we fix them, this number should be reduced.
  55. self.assertEqual(result, limit,
  56. "Found code style errors (and warnings) in %s (%s)." % (name, python_file))