summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYAMAMOTO Takashi <yamamoto@valinux.co.jp>2013-09-11 16:53:26 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2013-09-24 02:55:27 +0900
commitd8d88fc06a66ef5e24d3b6f61332002678f5144b (patch)
tree85a13c6a7b33c8b61e00de1b24671fa281a4866b
parentdd06396803df422bc50320a8a7f8b3d53557e060 (diff)
unit test for import_module
Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/tests/unit/lib/test_import_module.py71
-rw-r--r--ryu/tests/unit/lib/test_mod/__init__.py15
-rw-r--r--ryu/tests/unit/lib/test_mod/fuga/__init__.py15
-rw-r--r--ryu/tests/unit/lib/test_mod/fuga/mod.py17
-rw-r--r--ryu/tests/unit/lib/test_mod/hoge/__init__.py15
-rw-r--r--ryu/tests/unit/lib/test_mod/hoge/mod.py17
6 files changed, 150 insertions, 0 deletions
diff --git a/ryu/tests/unit/lib/test_import_module.py b/ryu/tests/unit/lib/test_import_module.py
new file mode 100644
index 00000000..71ff984b
--- /dev/null
+++ b/ryu/tests/unit/lib/test_import_module.py
@@ -0,0 +1,71 @@
+# Copyright (C) 2013 Nippon Telegraph and Telephone Corporation.
+# Copyright (C) 2013 YAMAMOTO Takashi <yamamoto at valinux co jp>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import unittest
+from nose.tools import eq_
+
+from ryu.utils import import_module
+import ryu.tests.unit.lib.test_mod.fuga.mod
+
+
+class Test_import_module(unittest.TestCase):
+ """ Test case for ryu.utils.import_module
+ """
+
+ def setUp(self):
+ pass
+
+ def tearDown(self):
+ pass
+
+ @staticmethod
+ def _my_import(name):
+ mod = __import__(name)
+ components = name.split('.')
+ for c in components[1:]:
+ mod = getattr(mod, c)
+ return mod
+
+ def test_import_module_with_same_basename(self):
+ fuga = import_module('ryu.tests.unit.lib.test_mod.fuga.mod')
+ eq_("this is fuga", fuga.name)
+ hoge = import_module('ryu.tests.unit.lib.test_mod.hoge.mod')
+ eq_("this is hoge", hoge.name)
+
+ def test_import_module_by_filename(self):
+ fuga = import_module('./lib/test_mod/fuga/mod.py')
+ eq_("this is fuga", fuga.name)
+ hoge = import_module('./lib/test_mod/hoge/mod.py')
+ eq_("this is hoge", hoge.name)
+
+ def test_import_same_module1(self):
+ fuga1 = import_module('./lib/test_mod/fuga/mod.py')
+ eq_("this is fuga", fuga1.name)
+ eq_(ryu.tests.unit.lib.test_mod.fuga.mod, fuga1)
+
+ def test_import_same_module2(self):
+ fuga1 = import_module('./lib/test_mod/fuga/mod.py')
+ eq_("this is fuga", fuga1.name)
+ fuga2 = import_module('ryu.tests.unit.lib.test_mod.fuga.mod')
+ eq_("this is fuga", fuga2.name)
+ eq_(fuga1, fuga2)
+
+ def test_import_same_module3(self):
+ fuga1 = import_module('./lib/test_mod/fuga/mod.py')
+ eq_("this is fuga", fuga1.name)
+ fuga3 = self._my_import('ryu.tests.unit.lib.test_mod.fuga.mod')
+ eq_("this is fuga", fuga3.name)
+ eq_(fuga1, fuga3)
diff --git a/ryu/tests/unit/lib/test_mod/__init__.py b/ryu/tests/unit/lib/test_mod/__init__.py
new file mode 100644
index 00000000..ca8ef539
--- /dev/null
+++ b/ryu/tests/unit/lib/test_mod/__init__.py
@@ -0,0 +1,15 @@
+# Copyright (C) 2013 Nippon Telegraph and Telephone Corporation.
+# Copyright (C) 2013 YAMAMOTO Takashi <yamamoto at valinux co jp>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
diff --git a/ryu/tests/unit/lib/test_mod/fuga/__init__.py b/ryu/tests/unit/lib/test_mod/fuga/__init__.py
new file mode 100644
index 00000000..ca8ef539
--- /dev/null
+++ b/ryu/tests/unit/lib/test_mod/fuga/__init__.py
@@ -0,0 +1,15 @@
+# Copyright (C) 2013 Nippon Telegraph and Telephone Corporation.
+# Copyright (C) 2013 YAMAMOTO Takashi <yamamoto at valinux co jp>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
diff --git a/ryu/tests/unit/lib/test_mod/fuga/mod.py b/ryu/tests/unit/lib/test_mod/fuga/mod.py
new file mode 100644
index 00000000..551cb6c0
--- /dev/null
+++ b/ryu/tests/unit/lib/test_mod/fuga/mod.py
@@ -0,0 +1,17 @@
+# Copyright (C) 2013 Nippon Telegraph and Telephone Corporation.
+# Copyright (C) 2013 YAMAMOTO Takashi <yamamoto at valinux co jp>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+name = "this is fuga"
diff --git a/ryu/tests/unit/lib/test_mod/hoge/__init__.py b/ryu/tests/unit/lib/test_mod/hoge/__init__.py
new file mode 100644
index 00000000..ca8ef539
--- /dev/null
+++ b/ryu/tests/unit/lib/test_mod/hoge/__init__.py
@@ -0,0 +1,15 @@
+# Copyright (C) 2013 Nippon Telegraph and Telephone Corporation.
+# Copyright (C) 2013 YAMAMOTO Takashi <yamamoto at valinux co jp>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
diff --git a/ryu/tests/unit/lib/test_mod/hoge/mod.py b/ryu/tests/unit/lib/test_mod/hoge/mod.py
new file mode 100644
index 00000000..2f363d0b
--- /dev/null
+++ b/ryu/tests/unit/lib/test_mod/hoge/mod.py
@@ -0,0 +1,17 @@
+# Copyright (C) 2013 Nippon Telegraph and Telephone Corporation.
+# Copyright (C) 2013 YAMAMOTO Takashi <yamamoto at valinux co jp>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+name = "this is hoge"