backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / tests / unit / lib / test_import_module.py
1 # Copyright (C) 2013 Nippon Telegraph and Telephone Corporation.
2 # Copyright (C) 2013 YAMAMOTO Takashi <yamamoto at valinux co jp>
3 #
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
7 #
8 #    http://www.apache.org/licenses/LICENSE-2.0
9 #
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
13 # implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 import unittest
18 from nose.tools import eq_
19
20 from ryu.utils import import_module
21
22
23 class Test_import_module(unittest.TestCase):
24     """
25     Test case for ryu.utils.import_module
26     """
27
28     @staticmethod
29     def _my_import(name):
30         mod = __import__(name)
31         components = name.split('.')
32         for c in components[1:]:
33             mod = getattr(mod, c)
34         return mod
35
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)
41
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)
49
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)
55
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)
61
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)