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), '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): def test_template_loader(template_name, template_dirs=None):
"A custom template loader that loads the unit-test templates."
try: try:
return TEMPLATE_TESTS[template_name][0] return TEMPLATE_TESTS[template_name][0]
except KeyError: except KeyError:
raise template.TemplateDoesNotExist, template_name raise template.TemplateDoesNotExist, template_name
def run_tests(verbosity=0, standalone=False): 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 = [] failed_tests = []
tests = TEMPLATE_TESTS.items() tests = TEMPLATE_TESTS.items()
tests.sort() tests.sort()
@ -248,7 +251,7 @@ def run_tests(verbosity=0, standalone=False):
if verbosity: if verbosity:
print "Template test: %s -- FAILED. Expected %r, got %r" % (name, vals[2], output) print "Template test: %s -- FAILED. Expected %r, got %r" % (name, vals[2], output)
failed_tests.append(name) failed_tests.append(name)
loader.load_template_source = old_template_loader loader.template_source_loaders = old_template_loaders
if failed_tests and not standalone: if failed_tests and not standalone:
msg = "Template tests %s failed." % failed_tests msg = "Template tests %s failed." % failed_tests