Skip to content

Commit 6d70a7a

Browse files
theotherjimmy0xc0170
authored andcommitted
Add pylint testing to Travis
1 parent af5d35d commit 6d70a7a

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ python:
33

44
script:
55
- PYTHONPATH=. python tools/test/config_test/config_test.py
6+
- python tools/test/pylint.py
67
- py.test tools/test/toolchains/api.py
78
- python tools/build_travis.py
89
before_install:
@@ -17,3 +18,4 @@ install:
1718
- sudo pip install prettytable
1819
- sudo pip install jinja2
1920
- sudo pip install pytest
21+
- sudo pip install pylint

tools/test/pylint.py

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

0 commit comments

Comments
 (0)