mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixed #18269 -- Applied unicode_literals for Python 3 compatibility.
Thanks Vinay Sajip for the support of his django3 branch and Jannis Leidel for the review.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
"""
|
||||
Testing some internals of the template processing. These are *not* examples to be copied in user code.
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.template import (TokenParser, FilterExpression, Parser, Variable,
|
||||
TemplateSyntaxError)
|
||||
from django.utils.unittest import TestCase
|
||||
@@ -33,23 +35,23 @@ class ParserTests(TestCase):
|
||||
self.assertFalse(p.more())
|
||||
|
||||
def test_filter_parsing(self):
|
||||
c = {"article": {"section": u"News"}}
|
||||
c = {"article": {"section": "News"}}
|
||||
p = Parser("")
|
||||
|
||||
def fe_test(s, val):
|
||||
self.assertEqual(FilterExpression(s, p).resolve(c), val)
|
||||
|
||||
fe_test("article.section", u"News")
|
||||
fe_test("article.section|upper", u"NEWS")
|
||||
fe_test(u'"News"', u"News")
|
||||
fe_test(u"'News'", u"News")
|
||||
fe_test(ur'"Some \"Good\" News"', u'Some "Good" News')
|
||||
fe_test(ur'"Some \"Good\" News"', u'Some "Good" News')
|
||||
fe_test(ur"'Some \'Bad\' News'", u"Some 'Bad' News")
|
||||
fe_test("article.section", "News")
|
||||
fe_test("article.section|upper", "NEWS")
|
||||
fe_test('"News"', "News")
|
||||
fe_test("'News'", "News")
|
||||
fe_test(r'"Some \"Good\" News"', 'Some "Good" News')
|
||||
fe_test(r'"Some \"Good\" News"', 'Some "Good" News')
|
||||
fe_test(r"'Some \'Bad\' News'", "Some 'Bad' News")
|
||||
|
||||
fe = FilterExpression(ur'"Some \"Good\" News"', p)
|
||||
fe = FilterExpression(r'"Some \"Good\" News"', p)
|
||||
self.assertEqual(fe.filters, [])
|
||||
self.assertEqual(fe.var, u'Some "Good" News')
|
||||
self.assertEqual(fe.var, 'Some "Good" News')
|
||||
|
||||
# Filtered variables should reject access of attributes beginning with
|
||||
# underscores.
|
||||
@@ -58,10 +60,10 @@ class ParserTests(TestCase):
|
||||
)
|
||||
|
||||
def test_variable_parsing(self):
|
||||
c = {"article": {"section": u"News"}}
|
||||
c = {"article": {"section": "News"}}
|
||||
self.assertEqual(Variable("article.section").resolve(c), "News")
|
||||
self.assertEqual(Variable(u'"News"').resolve(c), "News")
|
||||
self.assertEqual(Variable(u"'News'").resolve(c), "News")
|
||||
self.assertEqual(Variable('"News"').resolve(c), "News")
|
||||
self.assertEqual(Variable("'News'").resolve(c), "News")
|
||||
|
||||
# Translated strings are handled correctly.
|
||||
self.assertEqual(Variable("_(article.section)").resolve(c), "News")
|
||||
@@ -70,10 +72,10 @@ class ParserTests(TestCase):
|
||||
|
||||
# Escaped quotes work correctly as well.
|
||||
self.assertEqual(
|
||||
Variable(ur'"Some \"Good\" News"').resolve(c), 'Some "Good" News'
|
||||
Variable(r'"Some \"Good\" News"').resolve(c), 'Some "Good" News'
|
||||
)
|
||||
self.assertEqual(
|
||||
Variable(ur"'Some \'Better\' News'").resolve(c), "Some 'Better' News"
|
||||
Variable(r"'Some \'Better\' News'").resolve(c), "Some 'Better' News"
|
||||
)
|
||||
|
||||
# Variables should reject access of attributes beginning with
|
||||
|
||||
Reference in New Issue
Block a user