Skip to content

Commit 3e430cc

Browse files
DaanHooglandsebgoa
authored andcommitted
CLOUDSTACK-3096 format TestCaseExecuteEngine
1 parent d53f1c0 commit 3e430cc

1 file changed

Lines changed: 27 additions & 16 deletions

File tree

‎tools/marvin/marvin/TestCaseExecuteEngine.py‎

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
# to you under the Apache License, Version 2.0 (the
66
# "License"); you may not use this file except in compliance
77
# with the License. You may obtain a copy of the License at
8-
#
8+
#
99
# http://www.apache.org/licenses/LICENSE-2.0
10-
#
10+
#
1111
# Unless required by applicable law or agreed to in writing,
1212
# software distributed under the License is distributed on an
1313
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -21,27 +21,32 @@
2121
import logging
2222
from functools import partial
2323

24+
2425
def testCaseLogger(message, logger=None):
2526
if logger is not None:
2627
logger.debug(message)
2728

29+
2830
class TestCaseExecuteEngine(object):
29-
def __init__(self, testclient, config, testcaseLogFile=None, testResultLogFile=None):
31+
def __init__(self, testclient, config, testcaseLogFile=None,
32+
testResultLogFile=None):
3033
"""
3134
Initialize the testcase execution engine, just the basics here
3235
@var testcaseLogFile: client log file
33-
@var testResultLogFile: summary report file
36+
@var testResultLogFile: summary report file
3437
"""
3538
self.testclient = testclient
3639
self.config = config
37-
self.logformat = logging.Formatter("%(asctime)s - %(levelname)s - %(name)s - %(message)s")
40+
self.logformat =\
41+
logging.Formatter(
42+
"%(asctime)s - %(levelname)s - %(name)s - %(message)s")
3843
self.loader = unittest.loader.TestLoader()
3944
self.suite = None
4045

4146
if testcaseLogFile is not None:
4247
self.logfile = testcaseLogFile
4348
self.logger = logging.getLogger("TestCaseExecuteEngine")
44-
fh = logging.FileHandler(self.logfile)
49+
fh = logging.FileHandler(self.logfile)
4550
fh.setFormatter(self.logformat)
4651
self.logger.addHandler(fh)
4752
self.logger.setLevel(logging.DEBUG)
@@ -59,33 +64,39 @@ def loadTestsFromDir(self, testDirectory):
5964
""" Load the test suites from a package with multiple test files """
6065
self.suite = self.loader.discover(testDirectory)
6166
self.injectTestCase(self.suite)
62-
67+
6368
def loadTestsFromFile(self, file_name):
6469
""" Load the tests from a single script/module """
6570
if os.path.isfile(file_name):
66-
self.suite = self.loader.discover(os.path.dirname(file_name), os.path.basename(file_name))
71+
self.suite = self.loader.discover(os.path.dirname(file_name),
72+
os.path.basename(file_name))
6773
self.injectTestCase(self.suite)
68-
74+
6975
def injectTestCase(self, testSuites):
7076
for test in testSuites:
7177
if isinstance(test, unittest.BaseTestSuite):
7278
self.injectTestCase(test)
7379
else:
7480
#logger bears the name of the test class
7581
testcaselogger = logging.getLogger("%s" % (test))
76-
fh = logging.FileHandler(self.logfile)
82+
fh = logging.FileHandler(self.logfile)
7783
fh.setFormatter(self.logformat)
7884
testcaselogger.addHandler(fh)
7985
testcaselogger.setLevel(logging.DEBUG)
80-
81-
#inject testclient and logger into each unittest
86+
87+
#inject testclient and logger into each unittest
8288
setattr(test, "testClient", self.testclient)
8389
setattr(test, "config", self.config)
84-
setattr(test, "debug", partial(testCaseLogger, logger=testcaselogger))
90+
setattr(test, "debug", partial(testCaseLogger,
91+
logger=testcaselogger))
8592
setattr(test.__class__, "clstestclient", self.testclient)
86-
if hasattr(test, "user"): #attribute when test is entirely executed as user
87-
self.testclient.createUserApiClient(test.UserName, test.DomainName, test.AcctType)
93+
if hasattr(test, "user"):
94+
# attribute when test is entirely executed as user
95+
self.testclient.createUserApiClient(test.UserName,
96+
test.DomainName,
97+
test.AcctType)
8898

8999
def run(self):
90100
if self.suite:
91-
unittest.TextTestRunner(stream=self.testResultLogFile, verbosity=2).run(self.suite)
101+
unittest.TextTestRunner(stream=self.testResultLogFile,
102+
verbosity=2).run(self.suite)

0 commit comments

Comments
 (0)