提交 6d0a2553 编写于 作者: L Lukáš Doktor 提交者: Lucas Meneghel Rodrigues

examples.tests.gendata: Split it into two subtests

The gendata is a nice example of multiple-subtests test. Add
a functional test that checks gendata creates the files
correctly and that two subtests are spawned.
Signed-off-by: NLukáš Doktor <ldoktor@redhat.com>
上级 0e5d1a86
......@@ -12,7 +12,7 @@ class GenDataTest(Test):
Simple test that generates data to be persisted after the test is run
"""
def generate_bsod(self):
def test_bsod(self):
try:
from PIL import Image
from PIL import ImageDraw
......@@ -34,16 +34,13 @@ class GenDataTest(Test):
y += 12
bsod.save(os.path.join(self.outputdir, "bsod.png"))
def generate_json(self):
def test_json(self):
import json
output_path = os.path.join(self.outputdir, "test.json")
output = {"basedir": self.basedir,
"outputdir": self.outputdir}
json.dump(output, open(output_path, "w"))
def test(self):
self.generate_bsod()
self.generate_json()
if __name__ == "__main__":
main()
......@@ -8,3 +8,4 @@ inspektor==0.1.15
pep8==1.6.2
requests==1.2.3
PyYAML==3.11
Pillow==2.2.1
......@@ -255,6 +255,45 @@ class OutputPluginTest(unittest.TestCase):
except OSError:
pass
def test_gendata(self):
tmpfile = tempfile.mktemp()
try:
os.chdir(basedir)
cmd_line = ("./scripts/avocado run --job-results-dir %s "
"--sysinfo=off gendata --json %s" %
(self.tmpdir, tmpfile))
result = process.run(cmd_line, ignore_status=True)
expected_rc = 0
self.assertEqual(result.exit_status, expected_rc,
"Avocado did not return rc %d:\n%s" %
(expected_rc, result))
with open(tmpfile, 'r') as fp:
json_results = json.load(fp)
bsod_dir = None
json_dir = None
for test in json_results['tests']:
if "test_bsod" in test['url']:
bsod_dir = test['logfile']
elif "test_json" in test['url']:
json_dir = test['logfile']
self.assertTrue(bsod_dir, "Failed to get test_bsod output "
"directory")
self.assertTrue(json_dir, "Failed to get test_json output "
"directory")
bsod_dir = os.path.join(os.path.dirname(bsod_dir), "data",
"bsod.png")
json_dir = os.path.join(os.path.dirname(json_dir), "data",
"test.json")
self.assertTrue(os.path.exists(bsod_dir), "File %s produced by"
"test does not exist" % bsod_dir)
self.assertTrue(os.path.exists(json_dir), "File %s produced by"
"test does not exist" % json_dir)
finally:
try:
os.remove(tmpfile)
except OSError:
pass
def test_redirect_output(self):
redirected_output_path = tempfile.mktemp()
try:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册