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,6 +29,26 @@ from django.utils.six import StringIO
|
|||
|
||||
|
||||
# Mock classes and objects for pkg_resources functions.
|
||||
class MockLoader(object):
|
||||
pass
|
||||
|
||||
def create_egg(name, resources):
|
||||
"""
|
||||
Creates a mock egg with a list of resources.
|
||||
|
||||
name: The name of the module.
|
||||
resources: A dictionary of resources. Keys are the names and values the data.
|
||||
"""
|
||||
egg = imp.new_module(name)
|
||||
egg.__loader__ = MockLoader()
|
||||
egg._resources = 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)
|
||||
|
@ -41,24 +66,6 @@ class MockProvider(pkg_resources.NullProvider):
|
|||
def _get(self, path):
|
||||
return self.module._resources[path].read()
|
||||
|
||||
class MockLoader(object):
|
||||
pass
|
||||
|
||||
def create_egg(name, resources):
|
||||
"""
|
||||
Creates a mock egg with a list of resources.
|
||||
|
||||
name: The name of the module.
|
||||
resources: A dictionary of resources. Keys are the names and values the data.
|
||||
"""
|
||||
egg = imp.new_module(name)
|
||||
egg.__loader__ = MockLoader()
|
||||
egg._resources = resources
|
||||
sys.modules[name] = egg
|
||||
|
||||
|
||||
class EggLoaderTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
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