mbed-os
Fork of mbed-os by
tools/test/pylint.py@1:3deb71413561, 2017-07-20 (annotated)
- Committer:
- xuaner
- Date:
- Thu Jul 20 14:26:57 2017 +0000
- Revision:
- 1:3deb71413561
- Parent:
- 0:f269e3021894
mbed_os
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
elessair | 0:f269e3021894 | 1 | """A test that all code scores above a 9.25 in pylint""" |
elessair | 0:f269e3021894 | 2 | |
elessair | 0:f269e3021894 | 3 | import subprocess |
elessair | 0:f269e3021894 | 4 | import re |
elessair | 0:f269e3021894 | 5 | import os.path |
elessair | 0:f269e3021894 | 6 | |
elessair | 0:f269e3021894 | 7 | SCORE_REGEXP = re.compile( |
elessair | 0:f269e3021894 | 8 | r'^Your\ code\ has\ been\ rated\ at\ (\-?[0-9\.]+)/10') |
elessair | 0:f269e3021894 | 9 | |
elessair | 0:f269e3021894 | 10 | TOOLS_ROOT = os.path.dirname(os.path.dirname(__file__)) |
elessair | 0:f269e3021894 | 11 | |
elessair | 0:f269e3021894 | 12 | |
elessair | 0:f269e3021894 | 13 | def parse_score(pylint_output): |
elessair | 0:f269e3021894 | 14 | """Parse the score out of pylint's output as a float If the score is not |
elessair | 0:f269e3021894 | 15 | found, return 0.0. |
elessair | 0:f269e3021894 | 16 | """ |
elessair | 0:f269e3021894 | 17 | for line in pylint_output.splitlines(): |
elessair | 0:f269e3021894 | 18 | match = re.match(SCORE_REGEXP, line) |
elessair | 0:f269e3021894 | 19 | if match: |
elessair | 0:f269e3021894 | 20 | return float(match.group(1)) |
elessair | 0:f269e3021894 | 21 | return 0.0 |
elessair | 0:f269e3021894 | 22 | |
elessair | 0:f269e3021894 | 23 | def execute_pylint(filename): |
elessair | 0:f269e3021894 | 24 | """Execute a pylint process and collect it's output |
elessair | 0:f269e3021894 | 25 | """ |
elessair | 0:f269e3021894 | 26 | process = subprocess.Popen( |
elessair | 0:f269e3021894 | 27 | ["pylint", filename], |
elessair | 0:f269e3021894 | 28 | stdout=subprocess.PIPE, |
elessair | 0:f269e3021894 | 29 | stderr=subprocess.PIPE |
elessair | 0:f269e3021894 | 30 | ) |
elessair | 0:f269e3021894 | 31 | stout, sterr = process.communicate() |
elessair | 0:f269e3021894 | 32 | status = process.poll() |
elessair | 0:f269e3021894 | 33 | return status, stout, sterr |
elessair | 0:f269e3021894 | 34 | |
elessair | 0:f269e3021894 | 35 | FILES = ["build_api.py", "config.py", "colorize.py", "detect_targets.py", |
elessair | 0:f269e3021894 | 36 | "hooks.py", "libraries.py", "memap.py", "options.py", "paths.py", |
elessair | 0:f269e3021894 | 37 | "targets.py", "test/pylint.py"] |
elessair | 0:f269e3021894 | 38 | |
elessair | 0:f269e3021894 | 39 | if __name__ == "__main__": |
elessair | 0:f269e3021894 | 40 | for python_module in FILES: |
elessair | 0:f269e3021894 | 41 | _, stdout, stderr = execute_pylint(os.path.join(TOOLS_ROOT, |
elessair | 0:f269e3021894 | 42 | python_module)) |
elessair | 0:f269e3021894 | 43 | score = parse_score(stdout) |
elessair | 0:f269e3021894 | 44 | if score < 9.25: |
elessair | 0:f269e3021894 | 45 | print(stdout) |
elessair | 0:f269e3021894 | 46 | |
elessair | 0:f269e3021894 | 47 | |
elessair | 0:f269e3021894 | 48 |