|
| 1 | +"""A test that all code scores above an 8.5 in pylint""" |
| 2 | + |
| 3 | +import subprocess |
| 4 | +import re |
| 5 | +import os.path |
| 6 | +import sys |
| 7 | + |
| 8 | +SCORE_REGEXP = re.compile( |
| 9 | + r'^Your\ code\ has\ been\ rated\ at\ (\-?[0-9\.]+)/10') |
| 10 | + |
| 11 | +TOOLS_ROOT = os.path.dirname(os.path.dirname(__file__)) |
| 12 | + |
| 13 | + |
| 14 | +def parse_score(pylint_output): |
| 15 | + """Parse the score out of pylint's output as a float If the score is not |
| 16 | + found, return 0.0. |
| 17 | + """ |
| 18 | + for line in pylint_output.splitlines(): |
| 19 | + match = re.match(SCORE_REGEXP, line) |
| 20 | + if match: |
| 21 | + return float(match.group(1)) |
| 22 | + return 0.0 |
| 23 | + |
| 24 | +def execute_pylint(filename): |
| 25 | + """Execute a pylint process and collect it's output |
| 26 | + """ |
| 27 | + process = subprocess.Popen( |
| 28 | + ["pylint", filename], |
| 29 | + stdout=subprocess.PIPE, |
| 30 | + stderr=subprocess.PIPE |
| 31 | + ) |
| 32 | + stout, sterr = process.communicate() |
| 33 | + status = process.poll() |
| 34 | + return status, stout, sterr |
| 35 | + |
| 36 | +FILES = ["build_api.py", "config.py", "colorize.py", "detect_targets.py", |
| 37 | + "hooks.py", "libraries.py", "memap.py", "options.py", "paths.py", |
| 38 | + "targets.py", "test/pylint.py"] |
| 39 | + |
| 40 | +if __name__ == "__main__": |
| 41 | + for python_module in FILES: |
| 42 | + _, stdout, stderr = execute_pylint(os.path.join(TOOLS_ROOT, |
| 43 | + python_module)) |
| 44 | + if parse_score(stdout) < 8.5: |
| 45 | + print(stdout) |
| 46 | + sys.exit(1) |
| 47 | + |
| 48 | + |
| 49 | + |
0 commit comments