diff options
| author | Claude Paroz <claude@2xlibre.net> | 2013-02-02 22:58:02 +0100 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2013-02-04 16:38:25 +0100 |
| commit | 7c5b244826be636429791a8ca76b2adc678e82e7 (patch) | |
| tree | 7a7f8d23cecd8c55f2f2f9c243376d036d20a0bb /tests/regressiontests/utils/module_loading.py | |
| parent | 3f1c7b70537330435e2ec2fca9550f7b7fa4372e (diff) | |
Fixed #17061 -- Factored out importing object from a dotted path
Thanks Carl Meyer for the report.
Diffstat (limited to 'tests/regressiontests/utils/module_loading.py')
| -rw-r--r-- | tests/regressiontests/utils/module_loading.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/tests/regressiontests/utils/module_loading.py b/tests/regressiontests/utils/module_loading.py index 3fc92b0862..a9e3706bb9 100644 --- a/tests/regressiontests/utils/module_loading.py +++ b/tests/regressiontests/utils/module_loading.py @@ -3,9 +3,10 @@ import sys import imp from zipimport import zipimporter +from django.core.exceptions import ImproperlyConfigured from django.utils import unittest from django.utils.importlib import import_module -from django.utils.module_loading import module_has_submodule +from django.utils.module_loading import import_by_path, module_has_submodule from django.utils._os import upath @@ -103,6 +104,23 @@ class EggLoader(unittest.TestCase): self.assertFalse(module_has_submodule(egg_module, 'no_such_module')) self.assertRaises(ImportError, import_module, 'egg_module.sub1.sub2.no_such_module') + +class ModuleImportTestCase(unittest.TestCase): + def test_import_by_path(self): + cls = import_by_path( + 'django.utils.module_loading.import_by_path') + self.assertEqual(cls, import_by_path) + + # Test exceptions raised + for path in ('no_dots_in_path', 'unexistent.path', + 'tests.regressiontests.utils.unexistent'): + self.assertRaises(ImproperlyConfigured, import_by_path, path) + + with self.assertRaises(ImproperlyConfigured) as cm: + import_by_path('unexistent.module.path', error_prefix="Foo") + self.assertTrue(str(cm.exception).startswith('Foo')) + + class ProxyFinder(object): def __init__(self): self._cache = {} |
