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
18 from yardstick.benchmark.scenarios import base
21 class ScenarioTestCase(unittest.TestCase):
23 def test_get_scenario_type(self):
24 scenario_type = 'dummy scenario'
26 class DummyScenario(base.Scenario):
27 __scenario_type__ = scenario_type
29 self.assertEqual(scenario_type, DummyScenario.get_scenario_type())
31 def test_get_scenario_type_not_defined(self):
32 class DummyScenario(base.Scenario):
35 self.assertEqual(str(None), DummyScenario.get_scenario_type())
37 def test_get_description(self):
38 docstring = """First line
43 class DummyScenario(base.Scenario):
46 self.assertEqual(docstring.splitlines()[0],
47 DummyScenario.get_description())
49 def test_get_description_empty(self):
50 class DummyScenario(base.Scenario):
53 self.assertEqual(str(None), DummyScenario.get_description())
55 def test_get_types(self):
57 scenario.__scenario_type__ for scenario in
58 base.Scenario.get_types() if hasattr(scenario,
60 existing_scenario_class_names = {
61 'Iperf3', 'CACHEstat', 'SpecCPU2006', 'Dummy', 'NSPerf', 'Parser'}
62 self.assertTrue(existing_scenario_class_names.issubset(scenario_names))
64 def test_get_cls_existing_scenario(self):
65 scenario_name = 'NSPerf'
66 scenario = base.Scenario.get_cls(scenario_name)
67 self.assertEqual(scenario_name, scenario.__scenario_type__)
69 def test_get_cls_non_existing_scenario(self):
70 wrong_scenario_name = 'Non-existing-scenario'
71 with self.assertRaises(RuntimeError) as exc:
72 base.Scenario.get_cls(wrong_scenario_name)
73 self.assertEqual('No such scenario type %s' % wrong_scenario_name,
76 def test_get_existing_scenario(self):
77 scenario_name = 'NSPerf'
78 scenario_module = ('yardstick.benchmark.scenarios.networking.'
79 'vnf_generic.NetworkServiceTestCase')
80 self.assertEqual(scenario_module, base.Scenario.get(scenario_name))
82 def test_get_non_existing_scenario(self):
83 wrong_scenario_name = 'Non-existing-scenario'
84 with self.assertRaises(RuntimeError) as exc:
85 base.Scenario.get(wrong_scenario_name)
86 self.assertEqual('No such scenario type %s' % wrong_scenario_name,
90 class IterScenarioClassesTestCase(unittest.TestCase):
92 def test_no_scenario_type_defined(self):
93 some_existing_scenario_class_names = [
94 'Iperf3', 'CACHEstat', 'SpecCPU2006', 'Dummy', 'NSPerf', 'Parser']
95 scenario_types = [scenario.__scenario_type__ for scenario
96 in base._iter_scenario_classes()]
97 for class_name in some_existing_scenario_class_names:
98 self.assertIn(class_name, scenario_types)
100 def test_scenario_type_defined(self):
101 some_existing_scenario_class_names = [
102 'Iperf3', 'CACHEstat', 'SpecCPU2006', 'Dummy', 'NSPerf', 'Parser']
103 for class_name in some_existing_scenario_class_names:
104 scenario_class = next(base._iter_scenario_classes(
105 scenario_type=class_name))
106 self.assertEqual(class_name, scenario_class.__scenario_type__)