mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Removed utils.module_loading.import_by_path() per deprecation timeline; refs #21674.
This commit is contained in:
parent
c3336e7e4f
commit
d029fafea1
4 changed files with 4 additions and 70 deletions
|
@ -3,15 +3,12 @@ from importlib import import_module
|
|||
import os
|
||||
import sys
|
||||
import unittest
|
||||
import warnings
|
||||
from zipimport import zipimporter
|
||||
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.test import SimpleTestCase, ignore_warnings, modify_settings
|
||||
from django.test import SimpleTestCase, modify_settings
|
||||
from django.test.utils import extend_sys_path
|
||||
from django.utils import six
|
||||
from django.utils.deprecation import RemovedInDjango19Warning
|
||||
from django.utils.module_loading import (autodiscover_modules, import_by_path, import_string,
|
||||
from django.utils.module_loading import (autodiscover_modules, import_string,
|
||||
module_has_submodule)
|
||||
from django.utils._os import upath
|
||||
|
||||
|
@ -110,39 +107,7 @@ class EggLoader(unittest.TestCase):
|
|||
self.assertRaises(ImportError, import_module, 'egg_module.sub1.sub2.no_such_module')
|
||||
|
||||
|
||||
@ignore_warnings(category=RemovedInDjango19Warning)
|
||||
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', 'utils_tests.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'))
|
||||
|
||||
def test_import_error_traceback(self):
|
||||
"""Test preserving the original traceback on an ImportError."""
|
||||
try:
|
||||
import_by_path('test_module.bad_module.content')
|
||||
except ImproperlyConfigured:
|
||||
traceback = sys.exc_info()[2]
|
||||
|
||||
self.assertIsNotNone(traceback.tb_next.tb_next,
|
||||
'Should have more than the calling frame in the traceback.')
|
||||
|
||||
def test_import_by_path_pending_deprecation_warning(self):
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter('always', category=RemovedInDjango19Warning)
|
||||
cls = import_by_path('django.utils.module_loading.import_by_path')
|
||||
self.assertEqual(cls, import_by_path)
|
||||
self.assertEqual(len(w), 1)
|
||||
self.assertTrue(issubclass(w[-1].category, RemovedInDjango19Warning))
|
||||
self.assertIn('deprecated', str(w[-1].message))
|
||||
|
||||
def test_import_string(self):
|
||||
cls = import_string('django.utils.module_loading.import_string')
|
||||
self.assertEqual(cls, import_string)
|
||||
|
@ -150,7 +115,6 @@ class ModuleImportTestCase(unittest.TestCase):
|
|||
# Test exceptions raised
|
||||
self.assertRaises(ImportError, import_string, 'no_dots_in_path')
|
||||
self.assertRaises(ImportError, import_string, 'utils_tests.unexistent')
|
||||
self.assertRaises(ImportError, import_string, 'unexistent.path')
|
||||
|
||||
|
||||
@modify_settings(INSTALLED_APPS={'append': 'utils_tests.test_module'})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue