diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-06-14 17:24:04 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-06-14 17:24:04 +0000 |
| commit | 23d78dddf216cba0471b092fa615e6da6b1b4ebb (patch) | |
| tree | 646335bbc1ced809aaef48618d66a597f5515f60 /tests/unit/test_importutils.py | |
| parent | cb0a0497e896634243a0e0a03da54e807bed0b46 (diff) | |
| parent | b744609fb5c714acf8282f92933d80a48303f833 (diff) | |
Merge "add more realistic unit tests for importutils"
Diffstat (limited to 'tests/unit/test_importutils.py')
| -rw-r--r-- | tests/unit/test_importutils.py | 20 |
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)) |
