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