summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/contrib/tts/runner.py
diff options
context:
space:
mode:
authorAlexandru DAMIAN <alexandru.damian@intel.com>2015-07-30 19:25:09 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-08-01 11:26:13 +0100
commit1640a65091c56eeed0f6bb1020fd156cdc279a6e (patch)
treeee36a0a10c1fea4d5e10e645b9077f80d6d67567 /bitbake/lib/toaster/contrib/tts/runner.py
parent160d610604fff0b119de2b70a9da8a5f73d93715 (diff)
downloadpoky-1640a65091c56eeed0f6bb1020fd156cdc279a6e.tar.gz
bitbake: toaster: tts: fix pylint warnings
This patch brings TTS to the pylint coding standards. Pylint was run with some disables: disable=logging-too-many-args,line-too-long,missing-docstring and achieved Your code has been rated at 10.00/10 There are no functional changes. (Bitbake rev: 2b40b412ff6a7e3fd4cc32707bd3cd713bc09ddb) Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com> Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster/contrib/tts/runner.py')
-rwxr-xr-xbitbake/lib/toaster/contrib/tts/runner.py87
1 files changed, 45 insertions, 42 deletions
diff --git a/bitbake/lib/toaster/contrib/tts/runner.py b/bitbake/lib/toaster/contrib/tts/runner.py
index e7e4dd2d2e..809fb35c5c 100755
--- a/bitbake/lib/toaster/contrib/tts/runner.py
+++ b/bitbake/lib/toaster/contrib/tts/runner.py
@@ -28,24 +28,22 @@
28 28
29 29
30from __future__ import print_function 30from __future__ import print_function
31import optparse
32import sys, os 31import sys, os
33import unittest, inspect, importlib 32import unittest, importlib
34import logging, pprint, json 33import logging, pprint, json
35 34
36from shellutils import * 35from shellutils import ShellCmdException, mkdirhier, run_shell_cmd
37 36
38import config 37import config
39 38
40# we also log to a file, in addition to console, because our output is important 39# we also log to a file, in addition to console, because our output is important
41__log_file_name =os.path.join(os.path.dirname(__file__),"log/tts_%d.log" % config.OWN_PID) 40__log_file_name__ = os.path.join(os.path.dirname(__file__), "log/tts_%d.log" % config.OWN_PID)
42mkdirhier(os.path.dirname(__log_file_name)) 41mkdirhier(os.path.dirname(__log_file_name__))
43__log_file = open(__log_file_name, "w") 42__log_file__ = open(__log_file_name__, "w")
44__file_handler = logging.StreamHandler(__log_file) 43__file_handler__ = logging.StreamHandler(__log_file__)
45__file_handler.setFormatter(logging.Formatter("%(asctime)s %(levelname)s: %(message)s")) 44__file_handler__.setFormatter(logging.Formatter("%(asctime)s %(levelname)s: %(message)s"))
46
47config.logger.addHandler(__file_handler)
48 45
46config.logger.addHandler(__file_handler__)
49 47
50# set up log directory 48# set up log directory
51try: 49try:
@@ -54,12 +52,12 @@ try:
54 else: 52 else:
55 if not os.path.isdir(config.LOGDIR): 53 if not os.path.isdir(config.LOGDIR):
56 raise Exception("Expected log dir '%s' is not actually a directory." % config.LOGDIR) 54 raise Exception("Expected log dir '%s' is not actually a directory." % config.LOGDIR)
57except OSError as e: 55except OSError as exc:
58 raise e 56 raise exc
59 57
60# creates the under-test-branch as a separate directory 58# creates the under-test-branch as a separate directory
61def set_up_test_branch(settings, branch_name): 59def set_up_test_branch(settings, branch_name):
62 testdir = "%s/%s.%d" % (settings['workdir'], config.TEST_DIR_NAME, config.OWN_PID) 60 testdir = "%s/%s.%d" % (settings['workdir'], config.TEST_DIR_NAME, config.OWN_PID)
63 61
64 # creates the host dir 62 # creates the host dir
65 if os.path.exists(testdir): 63 if os.path.exists(testdir):
@@ -70,11 +68,11 @@ def set_up_test_branch(settings, branch_name):
70 run_shell_cmd("cp -a '%s'/.git '%s'" % (settings['localclone'], testdir)) 68 run_shell_cmd("cp -a '%s'/.git '%s'" % (settings['localclone'], testdir))
71 69
72 # add the remote if it doesn't exist 70 # add the remote if it doesn't exist
73 crt_remotes = run_shell_cmd("git remote -v", cwd = testdir) 71 crt_remotes = run_shell_cmd("git remote -v", cwd=testdir)
74 remotes = [word for line in crt_remotes.split("\n") for word in line.split()] 72 remotes = [word for line in crt_remotes.split("\n") for word in line.split()]
75 if not config.CONTRIB_REPO in remotes: 73 if not config.CONTRIB_REPO in remotes:
76 remote_name = "tts_contrib" 74 remote_name = "tts_contrib"
77 run_shell_cmd("git remote add %s %s" % (remote_name, config.CONTRIB_REPO), cwd = testdir) 75 run_shell_cmd("git remote add %s %s" % (remote_name, config.CONTRIB_REPO), cwd=testdir)
78 else: 76 else:
79 remote_name = remotes[remotes.index(config.CONTRIB_REPO) - 1] 77 remote_name = remotes[remotes.index(config.CONTRIB_REPO) - 1]
80 78
@@ -82,7 +80,7 @@ def set_up_test_branch(settings, branch_name):
82 run_shell_cmd("git fetch %s -p" % remote_name, cwd=testdir) 80 run_shell_cmd("git fetch %s -p" % remote_name, cwd=testdir)
83 81
84 # do the checkout 82 # do the checkout
85 run_shell_cmd("git checkout origin/master && git branch -D %s; git checkout %s/%s -b %s && git reset --hard" % (branch_name,remote_name,branch_name,branch_name), cwd=testdir) 83 run_shell_cmd("git checkout origin/master && git branch -D %s; git checkout %s/%s -b %s && git reset --hard" % (branch_name, remote_name, branch_name, branch_name), cwd=testdir)
86 84
87 return testdir 85 return testdir
88 86
@@ -90,15 +88,15 @@ def set_up_test_branch(settings, branch_name):
90def __search_for_tests(): 88def __search_for_tests():
91 # we find all classes that can run, and run them 89 # we find all classes that can run, and run them
92 tests = [] 90 tests = []
93 for dir_name, dirs_list, files_list in os.walk(os.path.dirname(os.path.abspath(__file__))): 91 for _, _, files_list in os.walk(os.path.dirname(os.path.abspath(__file__))):
94 for f in [f[:-3] for f in files_list if f.endswith(".py") and not f.startswith("__init__")]: 92 for module_file in [f[:-3] for f in files_list if f.endswith(".py") and not f.startswith("__init__")]:
95 config.logger.debug("Inspecting module %s", f) 93 config.logger.debug("Inspecting module %s", module_file)
96 current_module = importlib.import_module(f) 94 current_module = importlib.import_module(module_file)
97 crtclass_names = vars(current_module) 95 crtclass_names = vars(current_module)
98 for v in crtclass_names: 96 for name in crtclass_names:
99 t = crtclass_names[v] 97 tested_value = crtclass_names[name]
100 if isinstance(t, type(unittest.TestCase)) and issubclass(t, unittest.TestCase): 98 if isinstance(tested_value, type(unittest.TestCase)) and issubclass(tested_value, unittest.TestCase):
101 tests.append((f,v)) 99 tests.append((module_file, name))
102 break 100 break
103 return tests 101 return tests
104 102
@@ -117,27 +115,31 @@ def execute_tests(dir_under_test, testname):
117 os.chdir(dir_under_test) 115 os.chdir(dir_under_test)
118 116
119 # execute each module 117 # execute each module
118 # pylint: disable=broad-except
119 # we disable the broad-except because we want to actually catch all possible exceptions
120 try: 120 try:
121 config.logger.debug("Discovered test clases: %s" % pprint.pformat(tests)) 121 config.logger.debug("Discovered test clases: %s", pprint.pformat(tests))
122 suite = unittest.TestSuite() 122 suite = unittest.TestSuite()
123 loader = unittest.TestLoader() 123 loader = unittest.TestLoader()
124 result = unittest.TestResult() 124 result = unittest.TestResult()
125 for m,t in tests: 125 for module_file, name in tests:
126 suite.addTest(loader.loadTestsFromName("%s.%s" % (m,t))) 126 suite.addTest(loader.loadTestsFromName("%s.%s" % (module_file, name)))
127 config.logger.info("Running %d test(s)", suite.countTestCases()) 127 config.logger.info("Running %d test(s)", suite.countTestCases())
128 suite.run(result) 128 suite.run(result)
129 129
130 if len(result.errors) > 0: 130 for error in result.errors:
131 map(lambda x: config.logger.error("Exception on test: %s" % pprint.pformat(x)), result.errors) 131 config.logger.error("Exception on test: %s\n%s", error[0],
132 "\n".join(["-- %s" % x for x in error[1].split("\n")]))
132 133
133 if len(result.failures) > 0: 134 for failure in result.failures:
134 map(lambda x: config.logger.error("Failed test: %s:\n%s\n" % (pprint.pformat(x[0]), "\n".join(["-- %s" % x for x in eval(pprint.pformat(x[1])).split("\n")]))), result.failures) 135 config.logger.error("Failed test: %s:\n%s\n", failure[0],
136 "\n".join(["-- %s" % x for x in failure[1].split("\n")]))
135 137
136 config.logger.info("Test results: %d ran, %d errors, %d failures" % (result.testsRun, len(result.errors), len(result.failures))) 138 config.logger.info("Test results: %d ran, %d errors, %d failures", result.testsRun, len(result.errors), len(result.failures))
137 139
138 except Exception as e: 140 except Exception as exc:
139 import traceback 141 import traceback
140 config.logger.error("Exception while running test. Tracedump: \n%s", traceback.format_exc(e)) 142 config.logger.error("Exception while running test. Tracedump: \n%s", traceback.format_exc(exc))
141 finally: 143 finally:
142 os.chdir(crt_dir) 144 os.chdir(crt_dir)
143 return len(result.failures) 145 return len(result.failures)
@@ -161,17 +163,15 @@ def validate_args():
161# load the configuration options 163# load the configuration options
162def read_settings(): 164def read_settings():
163 if not os.path.exists(config.SETTINGS_FILE) or not os.path.isfile(config.SETTINGS_FILE): 165 if not os.path.exists(config.SETTINGS_FILE) or not os.path.isfile(config.SETTINGS_FILE):
164 raise Exception("Config file '%s' cannot be openend" % config.SETTINGS_FILE); 166 raise Exception("Config file '%s' cannot be openend" % config.SETTINGS_FILE)
165 return json.loads(open(config.SETTINGS_FILE, "r").read()) 167 return json.loads(open(config.SETTINGS_FILE, "r").read())
166 168
167 169
168# cleanup ! 170# cleanup !
169def clean_up(testdir): 171def clean_up(testdir):
170 # TODO: delete the test dir
171 run_shell_cmd("rm -rf -- '%s'" % testdir) 172 run_shell_cmd("rm -rf -- '%s'" % testdir)
172 pass
173 173
174if __name__ == "__main__": 174def main():
175 (options, args) = validate_args() 175 (options, args) = validate_args()
176 176
177 settings = read_settings() 177 settings = read_settings()
@@ -182,19 +182,22 @@ if __name__ == "__main__":
182 try: 182 try:
183 if options.testdir is not None and os.path.exists(options.testdir): 183 if options.testdir is not None and os.path.exists(options.testdir):
184 testdir = os.path.abspath(options.testdir) 184 testdir = os.path.abspath(options.testdir)
185 config.logger.info("No checkout, using %s" % testdir) 185 config.logger.info("No checkout, using %s", testdir)
186 else: 186 else:
187 need_cleanup = True 187 need_cleanup = True
188 testdir = set_up_test_branch(settings, args[0]) # we expect a branch name as first argument 188 testdir = set_up_test_branch(settings, args[0]) # we expect a branch name as first argument
189 189
190 config.testdir = testdir # we let tests know where to run 190 config.TESTDIR = testdir # we let tests know where to run
191 no_failures = execute_tests(testdir, options.singletest) 191 no_failures = execute_tests(testdir, options.singletest)
192 192
193 except ShellCmdException as e : 193 except ShellCmdException as exc:
194 import traceback 194 import traceback
195 config.logger.error("Error while setting up testing. Traceback: \n%s" % traceback.format_exc(e)) 195 config.logger.error("Error while setting up testing. Traceback: \n%s", traceback.format_exc(exc))
196 finally: 196 finally:
197 if need_cleanup and testdir is not None: 197 if need_cleanup and testdir is not None:
198 clean_up(testdir) 198 clean_up(testdir)
199 199
200 sys.exit(no_failures) 200 sys.exit(no_failures)
201
202if __name__ == "__main__":
203 main()