Backup 1

Committer:
borlanic
Date:
Tue Apr 24 11:45:18 2018 +0000
Revision:
0:02dd72d1d465
BaBoRo_test2 - backup 1

Who changed what in which revision?

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