1 # Copyright (C) 2013 Nippon Telegraph and Telephone Corporation.
2 # Copyright (C) 2013 YAMAMOTO Takashi <yamamoto at valinux co jp>
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain 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,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 from nose.tools import eq_
20 from ryu.utils import import_module
23 class Test_import_module(unittest.TestCase):
25 Test case for ryu.utils.import_module
30 mod = __import__(name)
31 components = name.split('.')
32 for c in components[1:]:
36 def test_import_module_with_same_basename(self):
37 aaa = import_module('ryu.tests.unit.lib.test_mod.aaa.mod')
38 eq_("this is aaa", aaa.name)
39 bbb = import_module('ryu.tests.unit.lib.test_mod.bbb.mod')
40 eq_("this is bbb", bbb.name)
42 def test_import_module_by_filename(self):
43 ccc = import_module('./lib/test_mod/ccc/mod.py')
44 eq_("this is ccc", ccc.name)
45 ddd = import_module('./lib/test_mod/ddd/mod.py')
46 # Note: When importing a module by filename, if module file name
47 # is duplicated, import_module reload (override) a module instance.
48 eq_("this is ddd", ddd.name)
50 def test_import_same_module1(self):
51 from ryu.tests.unit.lib.test_mod import eee as eee1
52 eq_("this is eee", eee1.name)
53 eee2 = import_module('./lib/test_mod/eee.py')
54 eq_("this is eee", eee2.name)
56 def test_import_same_module2(self):
57 fff1 = import_module('./lib/test_mod/fff.py')
58 eq_("this is fff", fff1.name)
59 fff2 = import_module('ryu.tests.unit.lib.test_mod.fff')
60 eq_("this is fff", fff2.name)
62 def test_import_same_module3(self):
63 ggg1 = import_module('./lib/test_mod/ggg.py')
64 eq_("this is ggg", ggg1.name)
65 ggg2 = self._my_import('ryu.tests.unit.lib.test_mod.ggg')
66 eq_("this is ggg", ggg2.name)