Refs #23919 -- Removed an obsolete test for a Python 2 code path (refs #15662).

Fixed #21628 by removing the last usage of the imp module.
This commit is contained in:
Tim Graham 2017-01-27 17:39:49 -05:00 committed by GitHub
parent b09faa497e
commit 9e9e73735e
1 changed files with 0 additions and 35 deletions

View File

@ -1,4 +1,3 @@
import imp
import os import os
import sys import sys
import unittest import unittest
@ -13,11 +12,6 @@ from django.utils.module_loading import (
class DefaultLoader(unittest.TestCase): class DefaultLoader(unittest.TestCase):
def setUp(self):
sys.meta_path.insert(0, ProxyFinder())
def tearDown(self):
sys.meta_path.pop(0)
def test_loader(self): def test_loader(self):
"Normal module existence can be tested" "Normal module existence can be tested"
@ -178,35 +172,6 @@ class AutodiscoverModulesTestCase(SimpleTestCase):
self.assertEqual(site._registry, {'lorem': 'ipsum'}) self.assertEqual(site._registry, {'lorem': 'ipsum'})
class ProxyFinder:
def __init__(self):
self._cache = {}
def find_module(self, fullname, path=None):
tail = fullname.rsplit('.', 1)[-1]
try:
fd, fn, info = imp.find_module(tail, path)
if fullname in self._cache:
old_fd = self._cache[fullname][0]
if old_fd:
old_fd.close()
self._cache[fullname] = (fd, fn, info)
except ImportError:
return None
else:
return self # this is a loader as well
def load_module(self, fullname):
if fullname in sys.modules:
return sys.modules[fullname]
fd, fn, info = self._cache[fullname]
try:
return imp.load_module(fullname, fd, fn, info)
finally:
if fd:
fd.close()
class TestFinder: class TestFinder:
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.importer = zipimporter(*args, **kwargs) self.importer = zipimporter(*args, **kwargs)