summaryrefslogtreecommitdiffstats
path: root/tests/unit/test_importutils.py
diff options
context:
space:
mode:
authorSean Dague <sdague@linux.vnet.ibm.com>2012-06-11 17:05:44 -0400
committerSean Dague <sdague@linux.vnet.ibm.com>2012-06-12 09:24:16 -0400
commitb744609fb5c714acf8282f92933d80a48303f833 (patch)
tree9d70426378a9fca19840403aca4fc3a2b06c6aba /tests/unit/test_importutils.py
parent2d4e7b3177f658a2437297f9495211d0075480b0 (diff)
add more realistic unit tests for importutils
Add realistic tests including objects with and without args to importutils. Change-Id: If23db5ef80cdfa4be95e95b90e647ac2455fffc8
Diffstat (limited to 'tests/unit/test_importutils.py')
-rw-r--r--tests/unit/test_importutils.py20
1 files changed, 20 insertions, 0 deletions
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))