1 # Copyright 2017: Intel Ltd.
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
16 from yardstick.benchmark.scenarios import base
17 from yardstick.tests.unit import base as ut_base
20 class ScenarioTestCase(ut_base.BaseUnitTestCase):
22 def test_get_scenario_type(self):
23 scenario_type = 'dummy scenario'
25 class DummyScenario(base.Scenario):
26 __scenario_type__ = scenario_type
28 self.assertEqual(scenario_type, DummyScenario.get_scenario_type())
30 def test_get_scenario_type_not_defined(self):
31 class DummyScenario(base.Scenario):
34 self.assertEqual(str(None), DummyScenario.get_scenario_type())
36 def test_get_description(self):
37 docstring = """First line
42 class DummyScenario(base.Scenario):
45 self.assertEqual(docstring.splitlines()[0],
46 DummyScenario.get_description())
48 def test_get_description_empty(self):
49 class DummyScenario(base.Scenario):
52 self.assertEqual(str(None), DummyScenario.get_description())
54 def test_get_types(self):
56 scenario.__scenario_type__ for scenario in
57 base.Scenario.get_types() if hasattr(scenario,
59 existing_scenario_class_names = {
60 'Iperf3', 'CACHEstat', 'SpecCPU2006', 'Dummy', 'NSPerf', 'Parser'}
61 self.assertTrue(existing_scenario_class_names.issubset(scenario_names))
63 def test_get_cls_existing_scenario(self):
64 scenario_name = 'NSPerf'
65 scenario = base.Scenario.get_cls(scenario_name)
66 self.assertEqual(scenario_name, scenario.__scenario_type__)
68 def test_get_cls_non_existing_scenario(self):
69 wrong_scenario_name = 'Non-existing-scenario'
70 with self.assertRaises(RuntimeError) as exc:
71 base.Scenario.get_cls(wrong_scenario_name)
72 self.assertEqual('No such scenario type %s' % wrong_scenario_name,
75 def test_get_existing_scenario(self):
76 scenario_name = 'NSPerf'
77 scenario_module = ('yardstick.benchmark.scenarios.networking.'
78 'vnf_generic.NetworkServiceTestCase')
79 self.assertEqual(scenario_module, base.Scenario.get(scenario_name))
81 def test_get_non_existing_scenario(self):
82 wrong_scenario_name = 'Non-existing-scenario'
83 with self.assertRaises(RuntimeError) as exc:
84 base.Scenario.get(wrong_scenario_name)
85 self.assertEqual('No such scenario type %s' % wrong_scenario_name,
88 def test_scenario_abstract_class(self):
89 # pylint: disable=abstract-class-instantiated
90 with self.assertRaises(TypeError):
94 class IterScenarioClassesTestCase(ut_base.BaseUnitTestCase):
96 def test_no_scenario_type_defined(self):
97 some_existing_scenario_class_names = [
98 'Iperf3', 'CACHEstat', 'SpecCPU2006', 'Dummy', 'NSPerf', 'Parser']
99 scenario_types = [scenario.__scenario_type__ for scenario
100 in base._iter_scenario_classes()]
101 for class_name in some_existing_scenario_class_names:
102 self.assertIn(class_name, scenario_types)
104 def test_scenario_type_defined(self):
105 some_existing_scenario_class_names = [
106 'Iperf3', 'CACHEstat', 'SpecCPU2006', 'Dummy', 'NSPerf', 'Parser']
107 for class_name in some_existing_scenario_class_names:
108 scenario_class = next(base._iter_scenario_classes(
109 scenario_type=class_name))
110 self.assertEqual(class_name, scenario_class.__scenario_type__)