summaryrefslogtreecommitdiff
path: root/tests/regressiontests/templates/loaders.py
diff options
context:
space:
mode:
authorBrian Rosner <brosner@gmail.com>2008-06-26 15:42:33 +0000
committerBrian Rosner <brosner@gmail.com>2008-06-26 15:42:33 +0000
commitc8da0874c78ed4c6e1ad08cc78228799a333f76c (patch)
treebef645a8eb2c1a17f013a1031ed34494547dced0 /tests/regressiontests/templates/loaders.py
parentf15845c573f019fc7f6d7404add122f9b7c52dc4 (diff)
newforms-admin: Merged from trunk up to [7766].
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@7770 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/templates/loaders.py')
-rw-r--r--tests/regressiontests/templates/loaders.py26
1 files changed, 13 insertions, 13 deletions
diff --git a/tests/regressiontests/templates/loaders.py b/tests/regressiontests/templates/loaders.py
index 82e3c622d1..db37116b94 100644
--- a/tests/regressiontests/templates/loaders.py
+++ b/tests/regressiontests/templates/loaders.py
@@ -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()