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