nkjnm

Dependencies:   MAX44000 nexpaq_mdk

Fork of LED_Demo by Maxim nexpaq

Committer:
nexpaq
Date:
Sat Sep 17 16:32:05 2016 +0000
Revision:
1:55a6170b404f
checking in for sharing

Who changed what in which revision?

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