mbed-os

Dependents:   cobaLCDJoyMotor_Thread odometry_omni_3roda_v3 odometry_omni_3roda_v1 odometry_omni_3roda_v2 ... more

Committer:
be_bryan
Date:
Mon Dec 11 17:54:04 2017 +0000
Revision:
0:b74591d5ab33
motor ++

Who changed what in which revision?

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