init

Dependencies:   mbed

Committer:
Nathan Yonkee
Date:
Fri Mar 02 07:16:49 2018 -0700
Revision:
10:46a4cf51ee38
Parent:
9:d58e77ebd769
remove mbed-os

Who changed what in which revision?

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