Debian Codegraph @

tests/test_code_format.py

raw
1 import os
2 import subprocess
3 import sys
4
5
6 def test_flake8():
7 """Test source code for pyFlakes and PEP8 conformance"""
8 this_dir = os.path.dirname(os.path.abspath(__file__))
9 source_dir = os.path.join(this_dir, '..', 'osrf_pycommon')
10 cmd = [sys.executable, '-m', 'flake8', source_dir, '--count']
11 # if flake8_import_order is installed, set the style to google
12 try:
13 import flake8_import_order # noqa
14 cmd.extend(['--import-order-style=google'])
15 except ImportError:
16 pass
17 # ignore error codes from plugins this package doesn't comply with
18 cmd.extend(['--ignore=C,D,Q,I'])
19 # work around for https://gitlab.com/pycqa/flake8/issues/179
20 cmd.extend(['--jobs', '1'])
21 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
22 stdout, stderr = p.communicate()
23 print(stdout)
24 assert p.returncode == 0, \
25 "Command '{0}' returned non-zero exit code '{1}'".format(' '.join(cmd), p.returncode)