Merge "Docs: Updated NSB installation: VM image build DUT"
[yardstick.git] / yardstick / tests / unit / common / test_import_tools.py
1 # Copyright (c) 2018 Intel Corporation
2 #
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
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 import unittest
16
17 from yardstick.common import exceptions as y_exc
18 from yardstick.common import import_tools
19
20
21 @import_tools.decorator_banned_modules
22 class DummyClass(object):
23     pass
24
25
26 class DecoratorBannedModule(unittest.TestCase):
27
28     MODULE = 'yardstick.tests.unit.common.banned_modules.banned_module'
29
30     def test_passt(self):
31         self.assertIsNotNone(DummyClass())
32
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)
37
38         with self.assertRaises(y_exc.YardstickBannedModuleImported) as exc:
39             importing_module.ImportingClass()
40
41         msg = ('Module "%s" cannnot be imported. Reason: "Banned module!!"'
42                % self.MODULE)
43         self.assertEqual(msg, str(exc.exception))
44
45     def _remove_module(self):
46         del import_tools.BANNED_MODULES[self.MODULE]