提交 0ca04fc9 编写于 作者: C Cleber Rosa

Plugins: port JSON plugin

Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 d396ccd5
......@@ -41,8 +41,8 @@ from . import multiplexer
from . import tree
from . import test
from . import xunit
from . import jsonresult
from .settings import settings
from .plugins import jsonresult
from ..utils import archive
from ..utils import astring
from ..utils import path
......
......@@ -18,9 +18,8 @@ JSON output module.
import json
from . import plugin
from .. import output
from ..result import TestResult
from . import output
from .result import TestResult
class JSONTestResult(TestResult):
......@@ -89,29 +88,3 @@ class JSONTestResult(TestResult):
self.view.notify(event='minor', msg=self.json)
else:
self._save_json()
class JSON(plugin.Plugin):
"""
JSON output
"""
name = 'json'
enabled = True
def configure(self, parser):
self.parser = parser
self.parser.runner.output.add_argument(
'--json', type=str,
dest='json_output', metavar='FILE',
help='Enable JSON result format and write it to FILE. '
"Use '-' to redirect to the standard output.")
self.configured = True
def activate(self, app_args):
try:
if app_args.json_output:
self.parser.application.set_defaults(json_result=JSONTestResult)
except AttributeError:
pass
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See LICENSE for more details.
#
# Copyright: Red Hat Inc. 2014
# Author: Ruda Moura <rmoura@redhat.com>
"""
JSON output module.
"""
from avocado.core.jsonresult import JSONTestResult
from .base import CLI
class JSON(CLI):
"""
JSON output
"""
name = 'json'
description = "JSON output options for 'run' command"
def configure(self, parser):
run_subcommand_parser = parser.subcommands.choices.get('run', None)
if run_subcommand_parser is None:
return
run_subcommand_parser.output.add_argument(
'--json', type=str,
dest='json_output', metavar='FILE',
help='Enable JSON result format and write it to FILE. '
"Use '-' to redirect to the standard output.")
def run(self, args):
if 'json_output' in args and args.json_output is not None:
args.json_result = JSONTestResult
......@@ -120,7 +120,6 @@ class RunnerOperationTest(unittest.TestCase):
output,
"Test did not fail with action exception:\n%s" % output)
@unittest.skip("Temporary plugin infrastructure removal")
def test_uncaught_exception(self):
os.chdir(basedir)
cmd_line = ("./scripts/avocado run --sysinfo=off --job-results-dir %s "
......@@ -132,7 +131,6 @@ class RunnerOperationTest(unittest.TestCase):
result))
self.assertIn('"status": "ERROR"', result.stdout)
@unittest.skip("Temporary plugin infrastructure removal")
def test_fail_on_exception(self):
os.chdir(basedir)
cmd_line = ("./scripts/avocado run --sysinfo=off --job-results-dir %s "
......@@ -225,7 +223,6 @@ class RunnerOperationTest(unittest.TestCase):
self.assertNotIn('needs to be a 40 digit hex', result.stderr)
self.assertIn('PASS', result.stdout)
@unittest.skip("Temporary plugin infrastructure removal")
def test_automatic_unique_id(self):
cmd_line = './scripts/avocado run --job-results-dir %s --sysinfo=off passtest --json -' % self.tmpdir
result = process.run(cmd_line, ignore_status=True)
......@@ -234,7 +231,6 @@ class RunnerOperationTest(unittest.TestCase):
int(r['job_id'], 16) # it's an hex number
self.assertEqual(len(r['job_id']), 40)
@unittest.skip("Temporary plugin infrastructure removal")
def test_skip_outside_setup(self):
os.chdir(basedir)
cmd_line = ("./scripts/avocado run --sysinfo=off --job-results-dir %s "
......@@ -264,7 +260,6 @@ class RunnerOperationTest(unittest.TestCase):
self.assertTrue(os.path.exists(link))
self.assertTrue(os.path.islink(link))
@unittest.skip("Temporary plugin infrastructure removal")
def test_dry_run(self):
os.chdir(basedir)
cmd = ("./scripts/avocado run --sysinfo=off passtest failtest "
......@@ -729,27 +724,22 @@ class PluginsJSONTest(AbsPluginsTest, unittest.TestCase):
"Different number of skipped tests")
return json_data
@unittest.skip("Temporary plugin infrastructure removal")
def test_json_plugin_passtest(self):
self.run_and_check('passtest', exit_codes.AVOCADO_ALL_OK,
1, 0, 0, 0)
@unittest.skip("Temporary plugin infrastructure removal")
def test_json_plugin_failtest(self):
self.run_and_check('failtest', exit_codes.AVOCADO_TESTS_FAIL,
1, 0, 1, 0)
@unittest.skip("Temporary plugin infrastructure removal")
def test_json_plugin_skiponsetuptest(self):
self.run_and_check('skiponsetup', exit_codes.AVOCADO_ALL_OK,
1, 0, 0, 1)
@unittest.skip("Temporary plugin infrastructure removal")
def test_json_plugin_errortest(self):
self.run_and_check('errortest', exit_codes.AVOCADO_TESTS_FAIL,
1, 1, 0, 0)
@unittest.skip("Temporary plugin infrastructure removal")
def test_ugly_echo_cmd(self):
if not os.path.exists("/bin/echo"):
self.skipTest("Program /bin/echo does not exist")
......
......@@ -65,7 +65,6 @@ class OutputPluginTest(unittest.TestCase):
self.assertTrue(os.path.isfile(json_output))
minidom.parse(xunit_output)
@unittest.skip("Temporary plugin infrastructure removal")
def test_output_incompatible_setup(self):
os.chdir(basedir)
cmd_line = './scripts/avocado run --job-results-dir %s --sysinfo=off --xunit - --json - passtest' % self.tmpdir
......@@ -93,7 +92,6 @@ class OutputPluginTest(unittest.TestCase):
self.assertIn(error_excerpt, output,
"Missing excerpt error message from output:\n%s" % output)
@unittest.skip("Temporary plugin infrastructure removal")
def test_output_compatible_setup(self):
tmpfile = tempfile.mktemp()
os.chdir(basedir)
......@@ -115,7 +113,6 @@ class OutputPluginTest(unittest.TestCase):
except OSError:
pass
@unittest.skip("Temporary plugin infrastructure removal")
def test_output_compatible_setup_2(self):
tmpfile = tempfile.mktemp()
os.chdir(basedir)
......@@ -174,7 +171,6 @@ class OutputPluginTest(unittest.TestCase):
except OSError:
pass
@unittest.skip("Temporary plugin infrastructure removal")
def test_output_compatible_setup_nooutput(self):
tmpfile = tempfile.mktemp()
tmpfile2 = tempfile.mktemp()
......@@ -248,7 +244,6 @@ class OutputPluginTest(unittest.TestCase):
debug_log = second_line.split()[-1]
self.check_output_files(debug_log)
@unittest.skip("Temporary plugin infrastructure removal")
def test_verify_whiteboard_save(self):
tmpfile = tempfile.mktemp()
try:
......@@ -273,7 +268,6 @@ class OutputPluginTest(unittest.TestCase):
except OSError:
pass
@unittest.skip("Temporary plugin infrastructure removal")
@unittest.skipIf(image_output_uncapable(),
"Uncapable of generating images with PIL library")
def test_gendata(self):
......
......@@ -6,7 +6,7 @@ import tempfile
import shutil
from avocado import Test
from avocado.core.plugins import jsonresult
from avocado.core import jsonresult
from avocado.core import job
......
......@@ -130,6 +130,7 @@ if __name__ == '__main__':
'gdb = avocado.plugins.gdb:GDB',
'wrapper = avocado.plugins.wrapper:Wrapper',
'xunit = avocado.plugins.xunit:XUnit',
'json = avocado.plugins.json:JSON',
],
'avocado.plugins.cli.cmd': [
'config = avocado.plugins.config:Config',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册