提交 1db1d9ae 编写于 作者: L Lukáš Doktor

varianter: Support for human readable output

Instead of custom handling of human readable output let's create a
varianter method which produces it and use it from the core.
Signed-off-by: NLukáš Doktor <ldoktor@redhat.com>
上级 ecd6477a
......@@ -39,7 +39,6 @@ from . import exceptions
from . import job_id
from . import output
from . import varianter
from . import tree
from . import test
from . import jobdata
from .output import STD_OUTPUT
......@@ -366,31 +365,16 @@ class Job(object):
job_log.info('logs ' + self.logdir)
job_log.info('')
def _log_variants_tree(self, variant):
job_log = _TEST_LOGGER
tree_repr = tree.tree_view(variant.variants.root, verbose=True,
use_utf8=False)
if tree_repr:
job_log.info('Multiplex tree representation:')
for line in tree_repr.splitlines():
job_log.info(line)
job_log.info('')
def _log_variants(self, variants):
lines = variants.to_str(summary=1, variants=1, use_utf8=False)
for line in lines.splitlines():
_TEST_LOGGER.info(line)
def _log_tmp_dir(self):
job_log = _TEST_LOGGER
job_log.info('Temporary dir: %s', data_dir.get_tmp_dir())
job_log.info('')
def _log_variants(self, variant):
job_log = _TEST_LOGGER
for (index, tpl) in enumerate(variant.variants):
paths = ', '.join([x.path for x in tpl])
job_log.info('Variant %s: %s', index + 1, paths)
if variant.variants:
job_log.info('')
def _log_job_debug_info(self, mux):
"""
Log relevant debug information to the job log.
......@@ -399,9 +383,8 @@ class Job(object):
self._log_avocado_version()
self._log_avocado_config()
self._log_avocado_datadir()
self._log_variants_tree(mux)
self._log_tmp_dir()
self._log_variants(mux)
self._log_tmp_dir()
self._log_job_id()
def create_test_suite(self):
......
......@@ -24,6 +24,7 @@ import itertools
import logging
import re
from . import output
from . import tree
......@@ -459,6 +460,60 @@ class Varianter(object):
return
self.data.merge(tree)
def to_str(self, summary=0, variants=0, **kwargs):
"""
Return human readable representation
The summary/variants accepts verbosity where 0 means do not display
at all and maximum is up to the plugin.
:param summary: How verbose summary to output (int)
:param variants: How verbose list of variants to output (int)
:param kwargs: Other free-form arguments
:rtype: str
"""
if not self.variants:
return ""
out = []
if summary:
# Log tree representation
out.append("Multiplex tree representation:")
# summary == 0 means disable, but in plugin it's brief
tree_repr = tree.tree_view(self.variants.root, verbose=summary - 1,
use_utf8=kwargs.get("use_utf8"))
out.append(tree_repr)
out.append("")
if variants:
# variants == 0 means disable, but in plugin it's brief
contents = variants - 1
out.append("Multiplex variants:")
for (index, tpl) in enumerate(self.variants):
if not self.debug:
paths = ', '.join([x.path for x in tpl])
else:
color = output.TERM_SUPPORT.LOWLIGHT
cend = output.TERM_SUPPORT.ENDC
paths = ', '.join(["%s%s@%s%s" % (_.name, color,
getattr(_, 'yaml',
"Unknown"),
cend)
for _ in tpl])
out.append('%sVariant %s: %s' % ('\n' if contents else '',
index + 1, paths))
if contents:
env = set()
for node in tpl:
for key, value in node.environment.iteritems():
origin = node.environment_origin[key].path
env.add(("%s:%s" % (origin, key), str(value)))
if not env:
continue
fmt = ' %%-%ds => %%s' % max([len(_[0]) for _ in env])
for record in sorted(env):
out.append(fmt % record)
return "\n".join(out)
def get_number_of_tests(self, test_suite):
"""
:return: overall number of tests * number of variants
......
......@@ -371,19 +371,7 @@ class Diff(CLICmd):
results = []
variants = jobdata.retrieve_variants(resultsdir)
if variants is not None:
env = set()
for (index, tpl) in enumerate(variants.variants):
paths = ', '.join([x.path for x in tpl])
results.append('Variant %s: %s\n' % (index + 1, paths))
for node in tpl:
for key, value in node.environment.iteritems():
origin = node.environment_origin[key].path
env.add(("%s:%s" % (origin, key), str(value)))
if not env:
continue
fmt = ' %%-%ds => %%s\n' % max([len(_[0]) for _ in env])
for record in sorted(env):
results.append(fmt % record)
results.extend(variants.to_str(0, 2).splitlines())
else:
results.append('Not found\n')
......
......@@ -15,7 +15,7 @@
import logging
import sys
from avocado.core import exit_codes, output
from avocado.core import exit_codes
from avocado.core import tree
from avocado.core.plugin_interfaces import CLICmd
from avocado.core.settings import settings
......@@ -82,29 +82,13 @@ class Multiplex(CLICmd):
sys.exit(exit_codes.AVOCADO_ALL_OK)
log.info('Variants generated:')
for (index, tpl) in enumerate(variants.variants):
if not args.mux_debug:
paths = ', '.join([x.path for x in tpl])
else:
color = output.TERM_SUPPORT.LOWLIGHT
cend = output.TERM_SUPPORT.ENDC
paths = ', '.join(["%s%s@%s%s" % (_.name, color,
getattr(_, 'yaml',
"Unknown"),
cend)
for _ in tpl])
log.debug('%sVariant %s: %s', '\n' if args.contents else '',
index + 1, paths)
if args.contents:
env = set()
for node in tpl:
for key, value in node.environment.iteritems():
origin = node.environment_origin[key].path
env.add(("%s:%s" % (origin, key), str(value)))
if not env:
continue
fmt = ' %%-%ds => %%s' % max([len(_[0]) for _ in env])
for record in sorted(env):
log.debug(fmt, *record)
if args.mux_debug:
# In this version `avocado_variants.debug` is not set properly,
# let's force-enable it before calling to_str to
# get the expected results.
args.avocado_variants.debug = True
variants = args.avocado_variants.to_str(0, 3 if args.contents else 2)
for line in variants.splitlines():
log.debug(line)
sys.exit(exit_codes.AVOCADO_ALL_OK)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册