1 # Copyright (c) 2018 Intel Corporation
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 from yardstick.benchmark.contexts import base
16 from yardstick.tests.unit import base as ut_base
19 class DummyContextClass(base.Context):
21 def _get_network(self, *args):
24 def _get_server(self, *args):
34 class FlagsTestCase(ut_base.BaseUnitTestCase):
37 self.flags = base.Flags()
39 def test___init__(self):
40 self.assertFalse(self.flags.no_setup)
41 self.assertFalse(self.flags.no_teardown)
43 def test___init__with_flags(self):
44 flags = base.Flags(no_setup=True)
45 self.assertTrue(flags.no_setup)
46 self.assertFalse(flags.no_teardown)
49 self.flags.parse(no_setup=True, no_teardown="False")
51 self.assertTrue(self.flags.no_setup)
52 self.assertEqual(self.flags.no_teardown, "False")
54 def test_parse_forbidden_flags(self):
55 self.flags.parse(foo=42)
56 with self.assertRaises(AttributeError):
60 class ContextTestCase(ut_base.BaseUnitTestCase):
63 def _remove_ctx(ctx_obj):
64 if ctx_obj in base.Context.list:
65 base.Context.list.remove(ctx_obj)
67 def test_split_host_name(self):
68 ctx_obj = DummyContextClass()
69 self.addCleanup(self._remove_ctx, ctx_obj)
70 config_name = 'host_name.ctx_name'
71 self.assertEqual(('host_name', 'ctx_name'),
72 ctx_obj.split_host_name(config_name))
74 def test_split_host_name_wrong_separator(self):
75 ctx_obj = DummyContextClass()
76 self.addCleanup(self._remove_ctx, ctx_obj)
77 config_name = 'host_name-ctx_name'
78 self.assertEqual((None, None),
79 ctx_obj.split_host_name(config_name))
81 def test_split_host_name_other_separator(self):
82 ctx_obj = DummyContextClass(host_name_separator='-')
83 self.addCleanup(self._remove_ctx, ctx_obj)
84 config_name = 'host_name-ctx_name'
85 self.assertEqual(('host_name', 'ctx_name'),
86 ctx_obj.split_host_name(config_name))