summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2005-11-26 22:46:31 +0000
committerAdrian Holovaty <adrian@holovaty.com>2005-11-26 22:46:31 +0000
commit3ede006fc98f7e96ae9fb997872f78635576d5f8 (patch)
tree291765d5f0fb31b7c9bde66d97c859f65f76b17a /tests
parent5676d5b068909a699e798575e8a6a4492ff27af8 (diff)
Fixed #911 -- Made template system scoped to the parser instead of the template module. Also changed the way tags/filters are registered and added support for multiple arguments to {% load %} tag. Thanks, rjwittams. This is a backwards-incompatible change for people who've created custom template tags or filters. See http://code.djangoproject.com/wiki/BackwardsIncompatibleChanges for upgrade instructions.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@1443 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/othertests/defaultfilters.py12
-rw-r--r--tests/othertests/markup.py13
-rw-r--r--tests/othertests/templates.py18
-rw-r--r--tests/testapp/templatetags/testtags.py6
4 files changed, 31 insertions, 18 deletions
diff --git a/tests/othertests/defaultfilters.py b/tests/othertests/defaultfilters.py
index d440e25dd5..539994ba84 100644
--- a/tests/othertests/defaultfilters.py
+++ b/tests/othertests/defaultfilters.py
@@ -1,15 +1,15 @@
"""
->>> floatformat(7.7, None)
+>>> floatformat(7.7)
'7.7'
->>> floatformat(7.0, None)
+>>> floatformat(7.0)
'7'
->>> floatformat(0.7, None)
+>>> floatformat(0.7)
'0.7'
->>> floatformat(0.07, None)
+>>> floatformat(0.07)
'0.1'
->>> floatformat(0.007, None)
+>>> floatformat(0.007)
'0.0'
->>> floatformat(0.0, None)
+>>> floatformat(0.0)
'0'
"""
diff --git a/tests/othertests/markup.py b/tests/othertests/markup.py
index b1ffb99c8a..d2d2203b17 100644
--- a/tests/othertests/markup.py
+++ b/tests/othertests/markup.py
@@ -1,19 +1,20 @@
# Quick tests for the markup templatetags (django.contrib.markup)
-from django.core.template import Template, Context
-import django.contrib.markup.templatetags.markup # this registers the filters
+from django.core.template import Template, Context, add_to_builtins
+
+add_to_builtins('django.contrib.markup.templatetags.markup')
# find out if markup modules are installed and tailor the test appropriately
try:
import textile
except ImportError:
textile = None
-
+
try:
import markdown
except ImportError:
markdown = None
-
+
try:
import docutils
except ImportError:
@@ -36,7 +37,7 @@ if textile:
<p>Paragraph 2 with &#8220;quotes&#8221; and <code>code</code></p>"""
else:
assert rendered == textile_content
-
+
### test markdown
markdown_content = """Paragraph 1
@@ -64,4 +65,4 @@ if docutils:
assert rendered =="""<p>Paragraph 1</p>
<p>Paragraph 2 with a <a class="reference" href="http://www.example.com/">link</a></p>"""
else:
- assert rendered == rest_content \ No newline at end of file
+ assert rendered == rest_content
diff --git a/tests/othertests/templates.py b/tests/othertests/templates.py
index c1dbdde64f..86a67bea67 100644
--- a/tests/othertests/templates.py
+++ b/tests/othertests/templates.py
@@ -1,8 +1,12 @@
-import traceback
+from django.conf import settings
+
+# Turn TEMPLATE_DEBUG off, because tests assume that.
+settings.TEMPLATE_DEBUG = False
from django.core import template
from django.core.template import loader
from django.utils.translation import activate, deactivate, install
+import traceback
# Helper objects for template tests
class SomeClass:
@@ -99,8 +103,14 @@ TEMPLATE_TESTS = {
# Chained filters, with an argument to the first one
'basic-syntax29': ('{{ var|removetags:"b i"|upper|lower }}', {"var": "<b><i>Yes</i></b>"}, "yes"),
- #Escaped string as argument
- 'basic-syntax30': (r"""{{ var|default_if_none:" endquote\" hah" }}""", {"var": None}, ' endquote" hah'),
+ # Escaped string as argument
+ 'basic-syntax30': (r'{{ var|default_if_none:" endquote\" hah" }}', {"var": None}, ' endquote" hah'),
+
+ # Variable as argument
+ 'basic-syntax31': (r'{{ var|default_if_none:var2 }}', {"var": None, "var2": "happy"}, 'happy'),
+
+ # Default argument testing
+ 'basic-syntax32' : (r'{{ var|yesno:"yup,nup,mup" }} {{ var|yesno }}', {"var": True}, 'yup yes'),
### IF TAG ################################################################
'if-tag01': ("{% if foo %}yes{% else %}no{% endif %}", {"foo": True}, "yes"),
@@ -289,7 +299,7 @@ TEMPLATE_TESTS = {
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] , "test:%s" % template_name )
+ return (TEMPLATE_TESTS[template_name][0] , "test:%s" % template_name)
except KeyError:
raise template.TemplateDoesNotExist, template_name
diff --git a/tests/testapp/templatetags/testtags.py b/tests/testapp/templatetags/testtags.py
index 7b755043fa..e9177d8c24 100644
--- a/tests/testapp/templatetags/testtags.py
+++ b/tests/testapp/templatetags/testtags.py
@@ -2,6 +2,8 @@
from django.core import template
+register = template.Library()
+
class EchoNode(template.Node):
def __init__(self, contents):
self.contents = contents
@@ -11,5 +13,5 @@ class EchoNode(template.Node):
def do_echo(parser, token):
return EchoNode(token.contents.split()[1:])
-
-template.register_tag("echo", do_echo) \ No newline at end of file
+
+register.tag("echo", do_echo) \ No newline at end of file