mirror of https://github.com/ARMmbed/mbed-os.git
Add pylint testing to Travis
parent
af5d35dd1d
commit
6d70a7a1e2
|
@ -3,6 +3,7 @@ python:
|
|||
|
||||
script:
|
||||
- PYTHONPATH=. python tools/test/config_test/config_test.py
|
||||
- python tools/test/pylint.py
|
||||
- py.test tools/test/toolchains/api.py
|
||||
- python tools/build_travis.py
|
||||
before_install:
|
||||
|
@ -17,3 +18,4 @@ install:
|
|||
- sudo pip install prettytable
|
||||
- sudo pip install jinja2
|
||||
- sudo pip install pytest
|
||||
- sudo pip install pylint
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
"""A test that all code scores above an 8.5 in pylint"""
|
||||
|
||||
import subprocess
|
||||
import re
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
SCORE_REGEXP = re.compile(
|
||||
r'^Your\ code\ has\ been\ rated\ at\ (\-?[0-9\.]+)/10')
|
||||
|
||||
TOOLS_ROOT = os.path.dirname(os.path.dirname(__file__))
|
||||
|
||||
|
||||
def parse_score(pylint_output):
|
||||
"""Parse the score out of pylint's output as a float If the score is not
|
||||
found, return 0.0.
|
||||
"""
|
||||
for line in pylint_output.splitlines():
|
||||
match = re.match(SCORE_REGEXP, line)
|
||||
if match:
|
||||
return float(match.group(1))
|
||||
return 0.0
|
||||
|
||||
def execute_pylint(filename):
|
||||
"""Execute a pylint process and collect it's output
|
||||
"""
|
||||
process = subprocess.Popen(
|
||||
["pylint", filename],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE
|
||||
)
|
||||
stout, sterr = process.communicate()
|
||||
status = process.poll()
|
||||
return status, stout, sterr
|
||||
|
||||
FILES = ["build_api.py", "config.py", "colorize.py", "detect_targets.py",
|
||||
"hooks.py", "libraries.py", "memap.py", "options.py", "paths.py",
|
||||
"targets.py", "test/pylint.py"]
|
||||
|
||||
if __name__ == "__main__":
|
||||
for python_module in FILES:
|
||||
_, stdout, stderr = execute_pylint(os.path.join(TOOLS_ROOT,
|
||||
python_module))
|
||||
if parse_score(stdout) < 8.5:
|
||||
print(stdout)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue