Maxim mbed development library

Dependents:   sensomed

Committer:
switches
Date:
Tue Nov 08 18:27:11 2016 +0000
Revision:
0:0e018d759a2a
Initial commit

Who changed what in which revision?

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