1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
#!/usr/bin/env python
##############################################################################
# Copyright (c) 2016 Huan Li and others
# lihuansse@tongji.edu.cn
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
# Unittest for yardstick.benchmark.scenarios.availability.result_checker
# .baseresultchecker
from __future__ import absolute_import
import mock
import unittest
from yardstick.benchmark.scenarios.availability.result_checker import \
baseresultchecker
@mock.patch('yardstick.benchmark.scenarios.availability.result_checker'
'.baseresultchecker.BaseResultChecker')
class ResultCheckerMgrTestCase(unittest.TestCase):
def setUp(self):
config = {
'checker_type': 'general-result-checker',
'key': 'process-checker'
}
self.checker_configs = []
self.checker_configs.append(config)
def test_ResultCheckerMgr_setup_successful(self, mock_basechacer):
mgr_ins = baseresultchecker.ResultCheckerMgr()
mgr_ins.init_ResultChecker(self.checker_configs, None)
mgr_ins.verify()
def test_getitem_succeessful(self, mock_basechacer):
mgr_ins = baseresultchecker.ResultCheckerMgr()
mgr_ins.init_ResultChecker(self.checker_configs, None)
checker_ins = mgr_ins["process-checker"]
def test_getitem_fail(self, mock_basechacer):
mgr_ins = baseresultchecker.ResultCheckerMgr()
mgr_ins.init_ResultChecker(self.checker_configs, None)
with self.assertRaises(KeyError):
checker_ins = mgr_ins["checker-not-exist"]
class BaseResultCheckerTestCase(unittest.TestCase):
class ResultCheckeSimple(baseresultchecker.BaseResultChecker):
__result_checker__type__ = "ResultCheckeForTest"
def setup(self):
self.success = False
def verify(self):
return self.success
def setUp(self):
self.checker_cfg = {
'checker_type': 'general-result-checker',
'key': 'process-checker'
}
def test_baseresultchecker_setup_verify_successful(self):
ins = baseresultchecker.BaseResultChecker(self.checker_cfg, None)
ins.setup()
ins.verify()
def test_baseresultchecker_verfiy_pass(self):
ins = baseresultchecker.BaseResultChecker(self.checker_cfg, None)
ins.setup()
ins.actualResult = True
ins.expectedResult = True
ins.verify()
def test_get_script_fullpath(self):
ins = baseresultchecker.BaseResultChecker(self.checker_cfg, None)
path = ins.get_script_fullpath("test.bash")
def test_get_resultchecker_cls_successful(self):
baseresultchecker.BaseResultChecker.get_resultchecker_cls(
"ResultCheckeForTest")
def test_get_resultchecker_cls_fail(self):
with self.assertRaises(RuntimeError):
baseresultchecker.BaseResultChecker.get_resultchecker_cls(
"ResultCheckeNotExist")
|