avocado.job: Refactor code to detect conflicting use of stdout

Add a helper method on TestResultProxy() to get information
of output plugins using stdout, making up for a cleaner
way of letting the user know about the conflict.

Also, rephrase the error messages and update functional
tests to reflect the new status quo.
Signed-off-by: NLucas Meneghel Rodrigues <lmr@redhat.com>
上级 e201327f
......@@ -330,25 +330,12 @@ class Job(object):
test_result=self.result_proxy)
def _set_output_plugins(self):
plugin_using_stdout = None
e_msg = ("Avocado could not set %s and %s both to output to stdout. ")
e_msg_2 = ("Please set the output flag of one of them to a file "
"to avoid conflicts.")
for key in self.args.__dict__:
if key.endswith('_result'):
result_class = getattr(self.args, key)
if issubclass(result_class, result.TestResult):
result_plugin = result_class(self.view,
self.args)
if result_plugin.output == '-':
if plugin_using_stdout is not None:
e_msg %= (plugin_using_stdout.command_line_arg_name,
result_plugin.command_line_arg_name)
self.view.notify(event='error', msg=e_msg)
self.view.notify(event='error', msg=e_msg_2)
sys.exit(error_codes.numeric_status['AVOCADO_JOB_FAIL'])
else:
plugin_using_stdout = result_plugin
self.result_proxy.add_output_plugin(result_plugin)
def _make_test_result(self):
......@@ -381,8 +368,17 @@ class Job(object):
json_plugin = jsonresult.JSONTestResult(self.view, args)
self.result_proxy.add_output_plugin(json_plugin)
outputs = [op.output for op in self.result_proxy.output_plugins]
if '-' not in outputs:
op_set_stdout = self.result_proxy.output_plugins_using_stdout()
if len(op_set_stdout) > 1:
msg = ('Options %s are trying to use stdout simultaneously' %
" ".join(op_set_stdout))
self.view.notify(event='error', msg=msg)
msg = ('Please set at least one of them to a file to avoid '
'conflicts')
self.view.notify(event='error', msg=msg)
sys.exit(error_codes.numeric_status['AVOCADO_JOB_FAIL'])
if not op_set_stdout:
human_plugin = result.HumanTestResult(self.view, self.args)
self.result_proxy.add_output_plugin(human_plugin)
......
......@@ -48,6 +48,13 @@ class TestResultProxy(object):
"TestResult" % plugin)
self.output_plugins.append(plugin)
def output_plugins_using_stdout(self):
using_stdout = []
for op in self.output_plugins:
if op.output == '-':
using_stdout.append(op.command_line_arg_name)
return using_stdout
def start_tests(self):
for output_plugin in self.output_plugins:
output_plugin.start_tests()
......
......@@ -68,9 +68,9 @@ class OutputPluginTest(unittest.TestCase):
self.assertEqual(result.exit_status, expected_rc,
"Avocado did not return rc %d:\n%s" %
(expected_rc, result))
error_excerpt = "Avocado could not set --json and --xunit both to output to stdout."
error_excerpt = "Options --json --xunit are trying to use stdout simultaneously"
self.assertIn(error_excerpt, output,
"Missing excepted error message from output:\n%s" % output)
"Missing excerpt error message from output:\n%s" % output)
def test_output_incompatible_setup_2(self):
os.chdir(basedir)
......@@ -81,9 +81,9 @@ class OutputPluginTest(unittest.TestCase):
self.assertEqual(result.exit_status, expected_rc,
"Avocado did not return rc %d:\n%s" %
(expected_rc, result))
error_excerpt = "Avocado could not set --json and --vm both to output to stdout."
error_excerpt = "Options --json --vm are trying to use stdout simultaneously"
self.assertIn(error_excerpt, output,
"Missing excepted error message from output:\n%s" % output)
"Missing excerpt error message from output:\n%s" % output)
def test_output_compatible_setup(self):
tmpfile = tempfile.mktemp()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册