未验证 提交 4ea4332a 编写于 作者: C Cleber Rosa

Merge remote-tracking branch 'ldoktor/avocado-version2'

Signed-off-by: NCleber Rosa <crosa@redhat.com>
...@@ -131,6 +131,7 @@ class Job(object): ...@@ -131,6 +131,7 @@ class Job(object):
#: has not been attempted. If set to an empty list, it means that no #: has not been attempted. If set to an empty list, it means that no
#: test was found during resolution. #: test was found during resolution.
self.test_suite = None self.test_suite = None
self.test_runner = None
# The result events dispatcher is shared with the test runner. # The result events dispatcher is shared with the test runner.
# Because of our goal to support using the phases of a job # Because of our goal to support using the phases of a job
...@@ -284,8 +285,8 @@ class Job(object): ...@@ -284,8 +285,8 @@ class Job(object):
""" """
Prepares a test suite to be used for running tests Prepares a test suite to be used for running tests
:param references: String with tests references to be resolved, and then :param references: String with tests references to be resolved, and
run, separated by whitespace. Optionally, a then run, separated by whitespace. Optionally, a
list of tests (each test a string). list of tests (each test a string).
:returns: a test suite (a list of test factories) :returns: a test suite (a list of test factories)
""" """
...@@ -327,15 +328,21 @@ class Job(object): ...@@ -327,15 +328,21 @@ class Job(object):
git = path.find_command('git') git = path.find_command('git')
except path.CmdNotFoundError: except path.CmdNotFoundError:
return return
git_root = process.run('%s rev-parse --show-toplevel' % git, # We need to get git root as `py2to3` creates this file in BUILD
ignore_status=True, verbose=False) olddir = os.getcwd()
if git_root.exit_status == 0 and os.path.exists(os.path.join( try:
git_root.stdout.strip(), 'python-avocado.spec')): os.chdir(os.path.dirname(__file__))
cmd = "%s show --summary --pretty='%%H'" % git git_root = process.run('%s rev-parse --show-toplevel' % git,
result = process.run(cmd, ignore_status=True, verbose=False) ignore_status=True, verbose=False)
if result.exit_status == 0: if git_root.exit_status == 0 and os.path.exists(os.path.join(
top_commit = result.stdout.splitlines()[0][:8] git_root.stdout.strip(), 'python-avocado.spec')):
return " (GIT commit %s)" % top_commit cmd = "%s show --summary --pretty='%%H'" % git
res = process.run(cmd, ignore_status=True, verbose=False)
if res.exit_status == 0:
top_commit = res.stdout.splitlines()[0][:8]
return " (GIT commit %s)" % top_commit
finally:
os.chdir(olddir)
def _log_avocado_version(self): def _log_avocado_version(self):
version_log = version.VERSION version_log = version.VERSION
...@@ -377,12 +384,14 @@ class Job(object): ...@@ -377,12 +384,14 @@ class Job(object):
LOG_JOB.info('logs ' + self.logdir) LOG_JOB.info('logs ' + self.logdir)
LOG_JOB.info('') LOG_JOB.info('')
def _log_variants(self, variants): @staticmethod
def _log_variants(variants):
lines = variants.to_str(summary=1, variants=1, use_utf8=False) lines = variants.to_str(summary=1, variants=1, use_utf8=False)
for line in lines.splitlines(): for line in lines.splitlines():
LOG_JOB.info(line) LOG_JOB.info(line)
def _log_tmp_dir(self): @staticmethod
def _log_tmp_dir():
LOG_JOB.info('Temporary dir: %s', data_dir.get_tmp_dir()) LOG_JOB.info('Temporary dir: %s', data_dir.get_tmp_dir())
LOG_JOB.info('') LOG_JOB.info('')
...@@ -418,8 +427,8 @@ class Job(object): ...@@ -418,8 +427,8 @@ class Job(object):
"'avocado list -V %s' for details" % references) "'avocado list -V %s' for details" % references)
else: else:
e_msg = ("No test references provided nor any other arguments " e_msg = ("No test references provided nor any other arguments "
"resolved into tests. Please double check the executed" "resolved into tests. Please double check the "
" command.") "executed command.")
raise exceptions.OptionValidationError(e_msg) raise exceptions.OptionValidationError(e_msg)
def pre_tests(self): def pre_tests(self):
...@@ -432,6 +441,9 @@ class Job(object): ...@@ -432,6 +441,9 @@ class Job(object):
self._result_events_dispatcher.map_method('pre_tests', self) self._result_events_dispatcher.map_method('pre_tests', self)
def run_tests(self): def run_tests(self):
"""
The actual test execution phase
"""
variant = getattr(self.args, "avocado_variants", None) variant = getattr(self.args, "avocado_variants", None)
if variant is None: if variant is None:
variant = varianter.Varianter() variant = varianter.Varianter()
...@@ -547,23 +559,25 @@ class TestProgram(object): ...@@ -547,23 +559,25 @@ class TestProgram(object):
sys.exit(exit_codes.AVOCADO_FAIL) sys.exit(exit_codes.AVOCADO_FAIL)
os.environ['AVOCADO_STANDALONE_IN_MAIN'] = 'True' os.environ['AVOCADO_STANDALONE_IN_MAIN'] = 'True'
self.progName = os.path.basename(sys.argv[0]) self.prog_name = os.path.basename(sys.argv[0])
output.add_log_handler("", output.ProgressStreamHandler, output.add_log_handler("", output.ProgressStreamHandler,
fmt="%(message)s") fmt="%(message)s")
self.parseArgs(sys.argv[1:]) self.parse_args(sys.argv[1:])
self.args.reference = [sys.argv[0]] self.args.reference = [sys.argv[0]]
self.runTests() self.run_tests()
def parseArgs(self, argv): def parse_args(self, argv):
self.parser = argparse.ArgumentParser(prog=self.progName) self.parser = argparse.ArgumentParser(prog=self.prog_name)
self.parser.add_argument('-r', '--remove-test-results', action='store_true', self.parser.add_argument('-r', '--remove-test-results',
help='remove all test results files after test execution') action='store_true', help="remove all test "
self.parser.add_argument('-d', '--test-results-dir', dest='logdir', default=None, "results files after test execution")
metavar='TEST_RESULTS_DIR', self.parser.add_argument('-d', '--test-results-dir', dest='logdir',
help='use an alternative test results directory') default=None, metavar='TEST_RESULTS_DIR',
help="use an alternative test results "
"directory")
self.args = self.parser.parse_args(argv) self.args = self.parser.parse_args(argv)
def runTests(self): def run_tests(self):
self.args.standalone = True self.args.standalone = True
self.args.show = ["test"] self.args.show = ["test"]
output.reconfigure(self.args) output.reconfigure(self.args)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册