Changed template unit test runner to use new template-loader framework from [870]

git-svn-id: http://code.djangoproject.com/svn/django/trunk@871 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2005-10-14 22:28:38 +00:00
parent 7aefff7833
commit 6ee014725e
1 changed files with 6 additions and 3 deletions

View File

@ -217,15 +217,18 @@ TEMPLATE_TESTS = {
'exception04': ("{% extends 'inheritance17' %}{% block first %}{% echo 400 %}5678{% endblock %}", {}, template.TemplateSyntaxError),
}
# This replaces the standard template loader.
def test_template_loader(template_name, template_dirs=None):
"A custom template loader that loads the unit-test templates."
try:
return TEMPLATE_TESTS[template_name][0]
except KeyError:
raise template.TemplateDoesNotExist, template_name
def run_tests(verbosity=0, standalone=False):
loader.load_template_source, old_template_loader = test_template_loader, loader.load_template_source
# Register our custom template loader.
old_template_loaders = loader.template_source_loaders
loader.template_source_loaders = [test_template_loader]
failed_tests = []
tests = TEMPLATE_TESTS.items()
tests.sort()
@ -248,7 +251,7 @@ def run_tests(verbosity=0, standalone=False):
if verbosity:
print "Template test: %s -- FAILED. Expected %r, got %r" % (name, vals[2], output)
failed_tests.append(name)
loader.load_template_source = old_template_loader
loader.template_source_loaders = old_template_loaders
if failed_tests and not standalone:
msg = "Template tests %s failed." % failed_tests