mirror of https://github.com/django/django.git
Fixed handling of template loader tests.
Previously, the CachedLoaderTests were never run at all.
This commit is contained in:
parent
5ed7ec99b6
commit
8f3aefdec3
|
@ -11,10 +11,15 @@ if __name__ == '__main__':
|
|||
|
||||
import imp
|
||||
import os.path
|
||||
import pkg_resources
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
try:
|
||||
import pkg_resources
|
||||
except ImportError:
|
||||
pkg_resources = None
|
||||
|
||||
|
||||
from django.template import TemplateDoesNotExist, Context
|
||||
from django.template.loaders.eggs import Loader as EggLoader
|
||||
from django.template import loader
|
||||
|
@ -24,23 +29,6 @@ from django.utils.six import StringIO
|
|||
|
||||
|
||||
# Mock classes and objects for pkg_resources functions.
|
||||
class MockProvider(pkg_resources.NullProvider):
|
||||
def __init__(self, module):
|
||||
pkg_resources.NullProvider.__init__(self, module)
|
||||
self.module = module
|
||||
|
||||
def _has(self, path):
|
||||
return path in self.module._resources
|
||||
|
||||
def _isdir(self, path):
|
||||
return False
|
||||
|
||||
def get_resource_stream(self, manager, resource_name):
|
||||
return self.module._resources[resource_name]
|
||||
|
||||
def _get(self, path):
|
||||
return self.module._resources[path].read()
|
||||
|
||||
class MockLoader(object):
|
||||
pass
|
||||
|
||||
|
@ -57,8 +45,27 @@ def create_egg(name, resources):
|
|||
sys.modules[name] = egg
|
||||
|
||||
|
||||
@unittest.skipUnless(pkg_resources, 'setuptools is not installed')
|
||||
class EggLoaderTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
# Defined here b/c at module scope we may not have pkg_resources
|
||||
class MockProvider(pkg_resources.NullProvider):
|
||||
def __init__(self, module):
|
||||
pkg_resources.NullProvider.__init__(self, module)
|
||||
self.module = module
|
||||
|
||||
def _has(self, path):
|
||||
return path in self.module._resources
|
||||
|
||||
def _isdir(self, path):
|
||||
return False
|
||||
|
||||
def get_resource_stream(self, manager, resource_name):
|
||||
return self.module._resources[resource_name]
|
||||
|
||||
def _get(self, path):
|
||||
return self.module._resources[path].read()
|
||||
|
||||
pkg_resources._provider_factories[MockLoader] = MockProvider
|
||||
|
||||
self.empty_egg = create_egg("egg_empty", {})
|
|
@ -8,8 +8,7 @@ if __name__ == '__main__':
|
|||
# before importing 'template'.
|
||||
settings.configure()
|
||||
|
||||
from datetime import date, datetime, timedelta
|
||||
import time
|
||||
from datetime import date, datetime
|
||||
import os
|
||||
import sys
|
||||
import traceback
|
||||
|
@ -31,21 +30,12 @@ from django.test.utils import (setup_test_template_loader,
|
|||
from django.utils.encoding import python_2_unicode_compatible
|
||||
from django.utils.formats import date_format
|
||||
from django.utils._os import upath
|
||||
from django.utils.translation import activate, deactivate, ugettext as _
|
||||
from django.utils.translation import activate, deactivate
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils import six
|
||||
from django.utils.tzinfo import LocalTimezone
|
||||
|
||||
from i18n import TransRealMixin
|
||||
|
||||
try:
|
||||
from .loaders import RenderToStringTest, EggLoaderTest
|
||||
except ImportError as e:
|
||||
if "pkg_resources" in e.args[0]:
|
||||
pass # If setuptools isn't installed, that's fine. Just move on.
|
||||
else:
|
||||
raise
|
||||
|
||||
# NumPy installed?
|
||||
try:
|
||||
import numpy
|
||||
|
|
Loading…
Reference in New Issue