summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-06-14 17:24:04 +0000
committerGerrit Code Review <review@openstack.org>2012-06-14 17:24:04 +0000
commit23d78dddf216cba0471b092fa615e6da6b1b4ebb (patch)
tree646335bbc1ced809aaef48618d66a597f5515f60
parentcb0a0497e896634243a0e0a03da54e807bed0b46 (diff)
parentb744609fb5c714acf8282f92933d80a48303f833 (diff)
downloadoslo-23d78dddf216cba0471b092fa615e6da6b1b4ebb.tar.gz
oslo-23d78dddf216cba0471b092fa615e6da6b1b4ebb.tar.xz
oslo-23d78dddf216cba0471b092fa615e6da6b1b4ebb.zip
Merge "add more realistic unit tests for importutils"
-rw-r--r--tests/unit/fake/__init__.py25
-rw-r--r--tests/unit/test_importutils.py20
2 files changed, 45 insertions, 0 deletions
diff --git a/tests/unit/fake/__init__.py b/tests/unit/fake/__init__.py
new file mode 100644
index 0000000..4941366
--- /dev/null
+++ b/tests/unit/fake/__init__.py
@@ -0,0 +1,25 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2012 IBM
+#
+# 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.
+
+
+class FakeDriver():
+ def __init__(self, first_arg=True):
+ self.first_arg = first_arg
+
+
+class FakeDriver2():
+ def __init__(self, first_arg):
+ self.first_arg = first_arg
diff --git a/tests/unit/test_importutils.py b/tests/unit/test_importutils.py
index e9b5b2e..acdb217 100644
--- a/tests/unit/test_importutils.py
+++ b/tests/unit/test_importutils.py
@@ -23,6 +23,7 @@ from openstack.common import importutils
class ImportUtilsTest(unittest.TestCase):
+
# NOTE(jkoelker) There has GOT to be a way to test this. But mocking
# __import__ is the devil. Right now we just make
# sure we can import something from the stdlib
@@ -38,6 +39,25 @@ class ImportUtilsTest(unittest.TestCase):
dt = importutils.import_module('datetime')
self.assertEqual(sys.modules['datetime'], dt)
+ def test_import_object_optional_arg_not_present(self):
+ obj = importutils.import_object('tests.unit.fake.FakeDriver')
+ self.assertTrue(obj.__class__.__name__, 'FakeDriver')
+
+ def test_import_object_optional_arg_present(self):
+ obj = importutils.import_object('tests.unit.fake.FakeDriver',
+ first_arg=False)
+ self.assertTrue(obj.__class__.__name__, 'FakeDriver')
+
+ def test_import_object_required_arg_not_present(self):
+ # arg 1 isn't optional here
+ self.assertRaises(TypeError, importutils.import_object,
+ 'tests.unit.fake.FakeDriver2')
+
+ def test_import_object_required_arg_present(self):
+ obj = importutils.import_object('tests.unit.fake.FakeDriver2',
+ first_arg=False)
+ self.assertTrue(obj.__class__.__name__, 'FakeDriver2')
+
def test_import_object(self):
dt = importutils.import_object('datetime.time')
self.assertTrue(isinstance(dt, sys.modules['datetime'].time))