Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Negligible formatting changes to tests/regressiontests/templates/load…

…ers.py

git-svn-id: http://code.djangoproject.com/svn/django/trunk@7750 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 345a0967568cf138c8d4b889ced8047f9c716b64 1 parent fbef599
Adrian Holovaty adrianholovaty authored
Showing with 13 additions and 13 deletions.
  1. +13 −13 tests/regressiontests/templates/loaders.py
26 tests/regressiontests/templates/loaders.py
View
@@ -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 @@
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 @@ def get_resource_stream(self, manager, resource_name):
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 @@ def setUp(self):
})
self._old_installed_apps = settings.INSTALLED_APPS
settings.INSTALLED_APPS = []
-
+
def tearDown(self):
settings.INSTALLED_APPS = self._old_installed_apps
@@ -74,19 +75,18 @@ def test_non_existing(self):
"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()
Please sign in to comment.
Something went wrong with that request. Please try again.