forked from stb-tester/stb-tester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stbt-lint
executable file
·95 lines (76 loc) · 2.94 KB
/
stbt-lint
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python
# Copyright 2014-2017 Stb-tester.com Ltd.
# Copyright 2013 YouView TV Ltd.
# License: LGPL v2.1 or (at your option) any later version (see
# https://github.com/stb-tester/stb-tester/blob/master/LICENSE for details).
"""Run static analysis over the specified stb-tester python scripts.
"stbt lint" runs "pylint" with the following additional checkers:
* E7001: The image path given to "stbt.match" (and similar functions)
does not exist on disk.
* E7002: The return value from is_screen_black, match, match_text, ocr,
or wait_until isn't used (perhaps you've forgotten to use "assert").
* E7003: The argument given to "wait_until" must be a callable (such as
a function or lambda expression).
* E7004: FrameObject properties must always provide "self._frame" as the
"frame" parameter to functions such as "stbt.match".
"""
import argparse
import os
import re
import subprocess
import sys
import threading
def main(argv):
parser = argparse.ArgumentParser(
prog="stbt lint",
usage="stbt lint [--help] [pylint options] filename [filename...]",
description=__doc__,
epilog="Any other command-line arguments are passed through to pylint.",
formatter_class=argparse.RawDescriptionHelpFormatter)
_, pylint_args = parser.parse_known_args(argv[1:])
if not pylint_args:
parser.print_usage(sys.stderr)
return 1
try:
with open("/dev/null", "w") as devnull:
subprocess.check_call(["pylint", "--help"],
stdout=devnull, stderr=devnull)
except OSError as e:
if e.errno == 2:
sys.stderr.write(
"stbt lint: error: Couldn't find 'pylint' executable\n")
return 1
env = os.environ
env["PYTHONPATH"] = os.pathsep.join([
os.path.dirname(__file__),
env.get("PYTHONPATH", "")])
pylint = subprocess.Popen(
["pylint", "--load-plugins=_stbt.pylint_plugin"] + pylint_args,
env=env, stderr=subprocess.PIPE)
t = threading.Thread(target=filter_warnings,
args=(pylint.stderr, sys.stderr))
t.start()
pylint.wait()
t.join()
return pylint.returncode
def filter_warnings(input_, output):
while True:
line = input_.readline()
if not line:
break
if any(re.search(pattern, line) for pattern in WARNINGS):
continue
output.write(line)
WARNINGS = [
# pylint:disable=line-too-long
r"libdc1394 error: Failed to initialize libdc1394",
r"pygobject_register_sinkfunc is deprecated",
r"assertion .G_TYPE_IS_BOXED \(boxed_type\). failed",
r"assertion .G_IS_PARAM_SPEC \(pspec\). failed",
r"return isinstance\(object, \(type, types.ClassType\)\)",
r"gsignal.c:.*: parameter 1 of type '<invalid>' for signal \".*\" is not a value type",
r"astroid.* Use gi.require_version",
r"^ __import__\(m\)$",
]
if __name__ == "__main__":
sys.exit(main(sys.argv))