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