forked from stb-tester/stb-tester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stbt_lint.py
executable file
·69 lines (55 loc) · 2.33 KB
/
stbt_lint.py
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
#!/usr/bin/python3
# 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,
press_and_wait, 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".
* E7005: The image path given to "stbt.match" (and similar functions)
exists on disk, but isn't committed to git.
* E7006: FrameObject properties must use "self._frame", not
"stbt.get_frame()".
* E7007: FrameObject properties must not have side-effects that change
the state of the device-under-test by calling "stbt.press()" or
"stbt.press_and_wait()".
* E7008: "assert True" has no effect.
"""
import argparse
import subprocess
import sys
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
executable_name = "pylint"
try:
with open("/dev/null", "w") as devnull:
subprocess.check_call([executable_name, "--help"],
stdout=devnull, stderr=devnull)
except OSError as e:
if e.errno == 2:
sys.stderr.write(
"stbt lint: error: Couldn't find '%s' executable\n"
% executable_name)
return 1
return subprocess.call(
[executable_name, "--load-plugins=_stbt.pylint_plugin"] +
pylint_args)
if __name__ == "__main__":
sys.exit(main(sys.argv))