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.
17 from yardstick.common import exceptions as y_exc
18 from yardstick.common import import_tools
21 @import_tools.decorator_banned_modules
22 class DummyClass(object):
26 class DecoratorBannedModule(unittest.TestCase):
28 MODULE = 'yardstick.tests.unit.common.banned_modules.banned_module'
31 self.assertIsNotNone(DummyClass())
33 def test_banned_module(self):
34 import_tools.BANNED_MODULES[self.MODULE] = 'Banned module!!'
35 from yardstick.tests.unit.common.banned_modules import importing_module
36 self.addCleanup(self._remove_module)
38 with self.assertRaises(y_exc.YardstickBannedModuleImported) as exc:
39 importing_module.ImportingClass()
41 msg = ('Module "%s" cannnot be imported. Reason: "Banned module!!"'
43 self.assertEqual(msg, str(exc.exception))
45 def _remove_module(self):
46 del import_tools.BANNED_MODULES[self.MODULE]