selftests/functional: Add output plugins testing

It's necessary if we're generating valid outputs in
the appropriate places, and that they respect the
rules established so far.
Signed-off-by: NLucas Meneghel Rodrigues <lmr@redhat.com>
上级 35782571
......@@ -14,9 +14,12 @@
# Copyright: Red Hat Inc. 2013-2014
# Author: Lucas Meneghel Rodrigues <lmr@redhat.com>
import json
import tempfile
import unittest
import os
import sys
from xml.dom import minidom
# simple magic for using scripts within a source tree
basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..', '..', '..')
......@@ -44,5 +47,100 @@ class OutputTest(unittest.TestCase):
"doublefree output:\n%s" % output)
class OutputPluginTest(unittest.TestCase):
def test_output_incompatible_setup(self):
os.chdir(basedir)
cmd_line = './scripts/avocado --xunit --json run sleeptest'
result = process.run(cmd_line, ignore_status=True)
expected_rc = 2
output = result.stdout + result.stderr
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."
self.assertIn(error_excerpt, output,
"Missing excepted error message from output:\n%s" % output)
def test_output_incompatible_setup_2(self):
os.chdir(basedir)
cmd_line = './scripts/avocado --vm --json run sleeptest'
result = process.run(cmd_line, ignore_status=True)
expected_rc = 2
output = result.stdout + result.stderr
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."
self.assertIn(error_excerpt, output,
"Missing excepted error message from output:\n%s" % output)
def test_output_compatible_setup(self):
tmpfile = tempfile.mktemp()
os.chdir(basedir)
cmd_line = './scripts/avocado --xunit --xunit-output %s --json run sleeptest' % tmpfile
result = process.run(cmd_line, ignore_status=True)
output = result.stdout + result.stderr
expected_rc = 0
try:
self.assertEqual(result.exit_status, expected_rc,
"Avocado did not return rc %d:\n%s" %
(expected_rc, result))
# Check if we are producing valid outputs
json.loads(output)
minidom.parse(tmpfile)
finally:
try:
os.remove(tmpfile)
except OSError:
pass
def test_output_compatible_setup_2(self):
tmpfile = tempfile.mktemp()
os.chdir(basedir)
cmd_line = './scripts/avocado --xunit --json --json-output %s run sleeptest' % tmpfile
result = process.run(cmd_line, ignore_status=True)
output = result.stdout + result.stderr
expected_rc = 0
try:
self.assertEqual(result.exit_status, expected_rc,
"Avocado did not return rc %d:\n%s" %
(expected_rc, result))
# Check if we are producing valid outputs
with open(tmpfile, 'r') as fp:
json.load(fp)
minidom.parseString(output)
finally:
try:
os.remove(tmpfile)
except OSError:
pass
def test_output_compatible_setup_nooutput(self):
tmpfile = tempfile.mktemp()
tmpfile2 = tempfile.mktemp()
os.chdir(basedir)
cmd_line = './scripts/avocado --xunit --xunit-output %s --json --json-output %s run sleeptest' % (tmpfile, tmpfile2)
result = process.run(cmd_line, ignore_status=True)
output = result.stdout + result.stderr
expected_rc = 0
try:
self.assertEqual(result.exit_status, expected_rc,
"Avocado did not return rc %d:\n%s" %
(expected_rc, result))
self.assertEqual(output, "",
"Output is not empty as expected:\n%s" % output)
# Check if we are producing valid outputs
with open(tmpfile2, 'r') as fp:
json.load(fp)
minidom.parse(tmpfile)
finally:
try:
os.remove(tmpfile)
os.remove(tmpfile2)
except OSError:
pass
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册