未验证 提交 207422bd 编写于 作者: R Rudá Moura

selftests: Introduce unit test for remote plugin.

Introduce a new unit test for remote plugin.

Since the remote plugin and the vm plugin share the same RemoteTest
class, we need to update the vm_unittest to use this class.
Signed-off-by: NRudá Moura <rmoura@redhat.com>
上级 fbdca011
#!/usr/bin/env python
# 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>
import unittest
import os
import sys
import json
import argparse
# simple magic for using scripts within a source tree
basedir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
basedir = os.path.dirname(basedir)
if os.path.isdir(os.path.join(basedir, 'avocado')):
sys.path.append(basedir)
from avocado.core import status
from avocado.core import job_id
from avocado.plugins import remote
class _Stream(object):
job_unique_id = job_id.create_unique_job_id()
def start_file_logging(self, param1, param2):
pass
def stop_file_logging(self):
pass
def set_tests_info(self, info):
pass
def notify(self, event, msg):
pass
def add_test(self, state):
pass
def set_test_status(self, status, state):
pass
class RemoteResultTest(unittest.TestCase):
def setUp(self):
args = argparse.Namespace()
stream = _Stream()
stream.logfile = 'debug.log'
self.test_result = remote.RemoteTestResult(stream, args)
j = '''{"tests": [{"test": "sleeptest.1", "url": "sleeptest", "status": "PASS", "time": 1.23}],
"debuglog": "/home/user/avocado/logs/run-2014-05-26-15.45.37/debug.log",
"errors": 0, "skip": 0, "time": 1.4,
"pass": 1, "failures": 0, "total": 1}'''
self.results = json.loads(j)
def test_check(self):
failures = []
self.test_result.start_tests()
for tst in self.results['tests']:
test = remote.RemoteTest(name=tst['test'],
time=tst['time'],
status=tst['status'])
self.test_result.start_test(test.get_state())
self.test_result.check_test(test.get_state())
if not status.mapping[test.status]:
failures.append(test.tagged_name)
self.test_result.end_tests()
self.assertEqual(self.test_result.tests_total, 1)
self.assertEqual(len(self.test_result.passed), 1)
self.assertEqual(len(self.test_result.failed), 0)
self.assertEqual(len(failures), 0)
if __name__ == '__main__':
unittest.main()
......@@ -70,9 +70,9 @@ class VMResultTest(unittest.TestCase):
failures = []
self.test_result.start_tests()
for tst in self.results['tests']:
test = vm.Test(name=tst['test'],
time=tst['time'],
status=tst['status'])
test = vm.RemoteTest(name=tst['test'],
time=tst['time'],
status=tst['status'])
self.test_result.start_test(test.get_state())
self.test_result.check_test(test.get_state())
if not status.mapping[test.status]:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册