mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Refs #24121 -- Added __repr__() to AdminForm, BlockContext, BlockTranslateNode, and IncludeNode.
This commit is contained in:
parent
cb6c19749d
commit
66ed03e7c9
7 changed files with 80 additions and 1 deletions
|
@ -5,6 +5,8 @@ from functools import partial, wraps
|
|||
from asgiref.local import Local
|
||||
|
||||
from django.template import Context, Template, TemplateSyntaxError
|
||||
from django.template.base import Token, TokenType
|
||||
from django.templatetags.i18n import BlockTranslateNode
|
||||
from django.test import SimpleTestCase, override_settings
|
||||
from django.utils import translation
|
||||
from django.utils.safestring import mark_safe
|
||||
|
@ -584,3 +586,17 @@ class MiscTests(SimpleTestCase):
|
|||
|
||||
class MiscBlockTranslationTests(MiscTests):
|
||||
tag_name = 'blocktrans'
|
||||
|
||||
|
||||
class BlockTranslateNodeTests(SimpleTestCase):
|
||||
def test_repr(self):
|
||||
block_translate_node = BlockTranslateNode(extra_context={}, singular=[
|
||||
Token(TokenType.TEXT, 'content'),
|
||||
Token(TokenType.VAR, 'variable'),
|
||||
])
|
||||
self.assertEqual(
|
||||
repr(block_translate_node),
|
||||
'<BlockTranslateNode: extra_context={} '
|
||||
'singular=[<Text token: "content...">, <Var token: "variable...">] '
|
||||
'plural=None>',
|
||||
)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from django.template.base import TemplateSyntaxError
|
||||
from django.template.context import Context
|
||||
from django.template.loader_tags import BlockContext, BlockNode
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
from ..utils import SilentAttrClass, SilentGetItemClass, SomeClass, setup
|
||||
|
@ -333,3 +334,14 @@ class BasicSyntaxTests(SimpleTestCase):
|
|||
self.assertEqual(output, '%%')
|
||||
output = self.engine.render_to_string('tpl-weird-percent')
|
||||
self.assertEqual(output, '% %s')
|
||||
|
||||
|
||||
class BlockContextTests(SimpleTestCase):
|
||||
def test_repr(self):
|
||||
block_context = BlockContext()
|
||||
block_context.add_blocks({'content': BlockNode('content', [])})
|
||||
self.assertEqual(
|
||||
repr(block_context),
|
||||
"<BlockContext: blocks=defaultdict(<class 'list'>, "
|
||||
"{'content': [<Block Node: content. Contents: []>]})>",
|
||||
)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from django.template import (
|
||||
Context, Engine, TemplateDoesNotExist, TemplateSyntaxError, loader,
|
||||
)
|
||||
from django.template.loader_tags import IncludeNode
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
from ..utils import setup
|
||||
|
@ -314,3 +315,12 @@ class IncludeTests(SimpleTestCase):
|
|||
], libraries={'custom': 'template_tests.templatetags.custom'})
|
||||
output = engine.render_to_string('template', {'vars': range(9)})
|
||||
self.assertEqual(output, '012345678')
|
||||
|
||||
|
||||
class IncludeNodeTests(SimpleTestCase):
|
||||
def test_repr(self):
|
||||
include_node = IncludeNode('app/template.html')
|
||||
self.assertEqual(
|
||||
repr(include_node),
|
||||
"<IncludeNode: template='app/template.html'>",
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue