Committer:
borlanic
Date:
Thu Mar 29 07:02:09 2018 +0000
Revision:
0:380207fcb5c1
Encoder, IMU --> OK; Controller --> in bearbeitung

Who changed what in which revision?

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