test_style.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. (c) 2017 - Copyright Red Hat Inc
  5. Authors:
  6. Pierre-Yves Chibon <pingou@pingoured.fr>
  7. Tests for flake8 compliance of the code
  8. """
  9. from __future__ import unicode_literals
  10. import os
  11. import subprocess
  12. import sys
  13. import unittest
  14. REPO_PATH = os.path.abspath(
  15. os.path.join(os.path.dirname(__file__), '..', 'pagure'))
  16. class TestStyle(unittest.TestCase):
  17. """This test class contains tests pertaining to code style."""
  18. def test_code_with_flake8(self):
  19. """Enforce PEP-8 compliance on the codebase.
  20. This test runs flake8 on the code, and will fail if it returns a non-zero exit code.
  21. """
  22. # We ignore E712, which disallows non-identity comparisons with True and False
  23. flake8_command = [sys.executable, '-m', 'flake8', '--ignore=E712,W503', REPO_PATH]
  24. proc = subprocess.Popen(flake8_command, stdout=subprocess.PIPE)
  25. print(proc.communicate())
  26. self.assertEqual(proc.returncode, 0)
  27. if __name__ == '__main__':
  28. unittest.main(verbosity=2)