1- from django .template import Template , Context , TemplateSyntaxError
1+ from django .template import Context , Template , TemplateSyntaxError
22from django .test import SimpleTestCase
33
44
55def _render (template ):
66 context = Context ({})
7- return Template (' {% load capture_tags %}' + template ).render (context )
7+ return Template (" {% load capture_tags %}" + template ).render (context )
88
99
1010class CaptureTagTests (SimpleTestCase ):
@@ -14,32 +14,45 @@ class CaptureTagTests(SimpleTestCase):
1414
1515 def test_capture (self ):
1616 """- check: {% capture %}"""
17- self .assertEqual (_render (' {% capture %}foo{% endcapture %}!{{ capture }}' ), ' foo!foo' )
17+ self .assertEqual (_render (" {% capture %}foo{% endcapture %}!{{ capture }}" ), " foo!foo" )
1818
1919 def test_capture_block (self ):
2020 """- check: {% block x %}{% capture %}{% endblock"""
2121 # Can't access outer context inside block yet.
2222 # This won't be possible, as the block could also be overwritten.
23- self .assertEqual (_render ('{% block x %}{% capture %}foo{% endcapture %}{% endblock %}!{{ capture }}' ), 'foo!' )
23+ self .assertEqual (
24+ _render ("{% block x %}{% capture %}foo{% endcapture %}{% endblock %}!{{ capture }}" ),
25+ "foo!" ,
26+ )
2427
2528 def test_capture_as_var (self ):
2629 """- check: {% capture as var %}"""
27- self .assertEqual (_render (' {% capture as var %}foo{% endcapture %}!{{ var }}' ), ' foo!foo' )
30+ self .assertEqual (_render (" {% capture as var %}foo{% endcapture %}!{{ var }}" ), " foo!foo" )
2831
2932 def test_capture_silent (self ):
3033 """- check: {% capture silent %}"""
31- self .assertEqual (_render (' {% capture silent %}foo{% endcapture %}!{{ capture }}' ), ' !foo' )
34+ self .assertEqual (_render (" {% capture silent %}foo{% endcapture %}!{{ capture }}" ), " !foo" )
3235
3336 def test_capture_as_var_silent (self ):
3437 """- check: {% capture as var silent %}"""
35- self .assertEqual (_render ('{% capture as var silent %}foo{% endcapture %}!{{ var }}' ), '!foo' )
38+ self .assertEqual (
39+ _render ("{% capture as var silent %}foo{% endcapture %}!{{ var }}" ), "!foo"
40+ )
3641
3742 def test_capture_as_silent (self ):
3843 """- check: {% capture as silent %}"""
39- self .assertEqual (_render ('{% capture as silent %}foo{% endcapture %}!{{ silent }}' ), 'foo!foo' )
44+ self .assertEqual (
45+ _render ("{% capture as silent %}foo{% endcapture %}!{{ silent }}" ), "foo!foo"
46+ )
4047
4148 def test_syntax_errors (self ):
42- self .assertRaises (TemplateSyntaxError , _render , '{% capture %}foo' )
43- self .assertRaises (TemplateSyntaxError , _render , '{% capture AS bar silent %}foo{% endcapture %}' )
44- self .assertRaises (TemplateSyntaxError , _render , '{% capture as bar SILENT %}foo{% endcapture %}' )
45- self .assertRaises (TemplateSyntaxError , _render , '{% capture as bar silent foo %}foo{% endcapture %}' )
49+ self .assertRaises (TemplateSyntaxError , _render , "{% capture %}foo" )
50+ self .assertRaises (
51+ TemplateSyntaxError , _render , "{% capture AS bar silent %}foo{% endcapture %}"
52+ )
53+ self .assertRaises (
54+ TemplateSyntaxError , _render , "{% capture as bar SILENT %}foo{% endcapture %}"
55+ )
56+ self .assertRaises (
57+ TemplateSyntaxError , _render , "{% capture as bar silent foo %}foo{% endcapture %}"
58+ )
0 commit comments