Negligible formatting changes to tests/regressiontests/templates/loaders.py

git-svn-id: http://code.djangoproject.com/svn/django/trunk@7750 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2008-06-26 04:22:12 +00:00
parent fbef599f60
commit 345a096756
1 changed files with 13 additions and 13 deletions

View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
"""
Test cases for the template loaders
Note: This test requires setuptools!
"""
from django.conf import settings
@ -17,7 +18,7 @@ import StringIO
from django.template import TemplateDoesNotExist
from django.template.loaders.eggs import load_template_source as lts_egg
#Mock classes and objects for pkg_resources functions
# Mock classes and objects for pkg_resources functions.
class MockProvider(pkg_resources.NullProvider):
def __init__(self, module):
pkg_resources.NullProvider.__init__(self, module)
@ -35,25 +36,25 @@ class MockProvider(pkg_resources.NullProvider):
def _get(self, path):
return self.module._resources[path].read()
class MockLoader(object): pass
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 the data.
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 the data.
"""
egg = imp.new_module(name)
egg.__loader__ = MockLoader()
egg._resources = resources
sys.modules[name] = egg
class EggLoader(unittest.TestCase):
def setUp(self):
pkg_resources._provider_factories[MockLoader] = MockProvider
self.empty_egg = create_egg("egg_empty", {})
self.egg_1 = create_egg("egg_1", {
'templates/y.html' : StringIO.StringIO("y"),
@ -61,7 +62,7 @@ class EggLoader(unittest.TestCase):
})
self._old_installed_apps = settings.INSTALLED_APPS
settings.INSTALLED_APPS = []
def tearDown(self):
settings.INSTALLED_APPS = self._old_installed_apps
@ -74,19 +75,18 @@ class EggLoader(unittest.TestCase):
"Template loading fails if the template is not in the egg"
settings.INSTALLED_APPS = ['egg_1']
self.assertRaises(TemplateDoesNotExist, lts_egg, "not-existing.html")
def test_existing(self):
"A template can be loaded from an egg"
settings.INSTALLED_APPS = ['egg_1']
contents, template_name = lts_egg("y.html")
self.assertEqual(contents, "y")
self.assertEqual(template_name, "egg:egg_1:templates/y.html")
def test_not_installed(self):
"Loading an existent template from an egg not included in INSTALLED_APPS should fail"
settings.INSTALLED_APPS = []
self.assertRaises(TemplateDoesNotExist, lts_egg, "y.html")
if __name__ == "__main__":
unittest.main()