Debian Codegraph @

tests/test_regression.py

raw
1 import pytest
2
3 from jinja2 import DictLoader
4 from jinja2 import Environment
5 from jinja2 import PrefixLoader
6 from jinja2 import Template
7 from jinja2 import TemplateAssertionError
8 from jinja2 import TemplateNotFound
9 from jinja2 import TemplateSyntaxError
10 from jinja2.utils import pass_context
11
12
13 class TestCorner:
14 def test_assigned_scoping(self, env):
15 t = env.from_string(
16 """
17 {%- for item in (1, 2, 3, 4) -%}
18 [{{ item }}]
19 {%- endfor %}
20 {{- item -}}
21 """
22 )
23 assert t.render(item=42) == "[1][2][3][4]42"
24
25 t = env.from_string(
26 """
27 {%- for item in (1, 2, 3, 4) -%}
28 [{{ item }}]
29 {%- endfor %}
30 {%- set item = 42 %}
31 {{- item -}}
32 """
33 )
34 assert t.render() == "[1][2][3][4]42"
35
36 t = env.from_string(
37 """
38 {%- set item = 42 %}
39 {%- for item in (1, 2, 3, 4) -%}
40 [{{ item }}]
41 {%- endfor %}
42 {{- item -}}
43 """
44 )
45 assert t.render() == "[1][2][3][4]42"
46
47 def test_closure_scoping(self, env):
48 t = env.from_string(
49 """
50 {%- set wrapper = "<FOO>" %}
51 {%- for item in (1, 2, 3, 4) %}
52 {%- macro wrapper() %}[{{ item }}]{% endmacro %}
53 {{- wrapper() }}
54 {%- endfor %}
55 {{- wrapper -}}
56 """
57 )
58 assert t.render() == "[1][2][3][4]<FOO>"
59
60 t = env.from_string(
61 """
62 {%- for item in (1, 2, 3, 4) %}
63 {%- macro wrapper() %}[{{ item }}]{% endmacro %}
64 {{- wrapper() }}
65 {%- endfor %}
66 {%- set wrapper = "<FOO>" %}
67 {{- wrapper -}}
68 """
69 )
70 assert t.render() == "[1][2][3][4]<FOO>"
71
72 t = env.from_string(
73 """
74 {%- for item in (1, 2, 3, 4) %}
75 {%- macro wrapper() %}[{{ item }}]{% endmacro %}
76 {{- wrapper() }}
77 {%- endfor %}
78 {{- wrapper -}}
79 """
80 )
81 assert t.render(wrapper=23) == "[1][2][3][4]23"
82
83
84 class TestBug:
85 def test_keyword_folding(self, env):
86 env = Environment()
87 env.filters["testing"] = lambda value, some: value + some
88 assert (
89 env.from_string("{{ 'test'|testing(some='stuff') }}").render()
90 == "teststuff"
91 )
92
93 def test_extends_output_bugs(self, env):
94 env = Environment(
95 loader=DictLoader({"parent.html": "(({% block title %}{% endblock %}))"})
96 )
97
98 t = env.from_string(
99 '{% if expr %}{% extends "parent.html" %}{% endif %}'
100 "[[{% block title %}title{% endblock %}]]"
101 "{% for item in [1, 2, 3] %}({{ item }}){% endfor %}"
102 )
103 assert t.render(expr=False) == "[[title]](1)(2)(3)"
104 assert t.render(expr=True) == "((title))"
105
106 def test_urlize_filter_escaping(self, env):
107 tmpl = env.from_string('{{ "http://www.example.org/<foo"|urlize }}')
108 assert (
109 tmpl.render() == '<a href="http://www.example.org/&lt;foo" rel="noopener">'
110 "http://www.example.org/&lt;foo</a>"
111 )
112
113 def test_urlize_filter_closing_punctuation(self, env):
114 tmpl = env.from_string(
115 '{{ "(see http://www.example.org/?page=subj_<desc.h>)"|urlize }}'
116 )
117 assert tmpl.render() == (
118 '(see <a href="http://www.example.org/?page=subj_&lt;desc.h&gt;" '
119 'rel="noopener">http://www.example.org/?page=subj_&lt;desc.h&gt;</a>)'
120 )
121
122 def test_loop_call_loop(self, env):
123 tmpl = env.from_string(
124 """
125
126 {% macro test() %}
127 {{ caller() }}
128 {% endmacro %}
129
130 {% for num1 in range(5) %}
131 {% call test() %}
132 {% for num2 in range(10) %}
133 {{ loop.index }}
134 {% endfor %}
135 {% endcall %}
136 {% endfor %}
137
138 """
139 )
140
141 assert tmpl.render().split() == [str(x) for x in range(1, 11)] * 5
142
143 def test_weird_inline_comment(self, env):
144 env = Environment(line_statement_prefix="%")
145 pytest.raises(
146 TemplateSyntaxError,
147 env.from_string,
148 "% for item in seq {# missing #}\n...% endfor",
149 )
150
151 def test_old_macro_loop_scoping_bug(self, env):
152 tmpl = env.from_string(
153 "{% for i in (1, 2) %}{{ i }}{% endfor %}"
154 "{% macro i() %}3{% endmacro %}{{ i() }}"
155 )
156 assert tmpl.render() == "123"
157
158 def test_partial_conditional_assignments(self, env):
159 tmpl = env.from_string("{% if b %}{% set a = 42 %}{% endif %}{{ a }}")
160 assert tmpl.render(a=23) == "23"
161 assert tmpl.render(b=True) == "42"
162
163 def test_stacked_locals_scoping_bug(self, env):
164 env = Environment(line_statement_prefix="#")
165 t = env.from_string(
166 """\
167 # for j in [1, 2]:
168 # set x = 1
169 # for i in [1, 2]:
170 # print x
171 # if i % 2 == 0:
172 # set x = x + 1
173 # endif
174 # endfor
175 # endfor
176 # if a
177 # print 'A'
178 # elif b
179 # print 'B'
180 # elif c == d
181 # print 'C'
182 # else
183 # print 'D'
184 # endif
185 """
186 )
187 assert t.render(a=0, b=False, c=42, d=42.0) == "1111C"
188
189 def test_stacked_locals_scoping_bug_twoframe(self, env):
190 t = Template(
191 """
192 {% set x = 1 %}
193 {% for item in foo %}
194 {% if item == 1 %}
195 {% set x = 2 %}
196 {% endif %}
197 {% endfor %}
198 {{ x }}
199 """
200 )
201 rv = t.render(foo=[1]).strip()
202 assert rv == "1"
203
204 def test_call_with_args(self, env):
205 t = Template(
206 """{% macro dump_users(users) -%}
207 <ul>
208 {%- for user in users -%}
209 <li><p>{{ user.username|e }}</p>{{ caller(user) }}</li>
210 {%- endfor -%}
211 </ul>
212 {%- endmacro -%}
213
214 {% call(user) dump_users(list_of_user) -%}
215 <dl>
216 <dl>Realname</dl>
217 <dd>{{ user.realname|e }}</dd>
218 <dl>Description</dl>
219 <dd>{{ user.description }}</dd>
220 </dl>
221 {% endcall %}"""
222 )
223
224 assert [
225 x.strip()
226 for x in t.render(
227 list_of_user=[
228 {
229 "username": "apo",
230 "realname": "something else",
231 "description": "test",
232 }
233 ]
234 ).splitlines()
235 ] == [
236 "<ul><li><p>apo</p><dl>",
237 "<dl>Realname</dl>",
238 "<dd>something else</dd>",
239 "<dl>Description</dl>",
240 "<dd>test</dd>",
241 "</dl>",
242 "</li></ul>",
243 ]
244
245 def test_empty_if_condition_fails(self, env):
246 pytest.raises(TemplateSyntaxError, Template, "{% if %}....{% endif %}")
247 pytest.raises(
248 TemplateSyntaxError, Template, "{% if foo %}...{% elif %}...{% endif %}"
249 )
250 pytest.raises(TemplateSyntaxError, Template, "{% for x in %}..{% endfor %}")
251
252 def test_recursive_loop_compile(self, env):
253 Template(
254 """
255 {% for p in foo recursive%}
256 {{p.bar}}
257 {% for f in p.fields recursive%}
258 {{f.baz}}
259 {{p.bar}}
260 {% if f.rec %}
261 {{ loop(f.sub) }}
262 {% endif %}
263 {% endfor %}
264 {% endfor %}
265 """
266 )
267 Template(
268 """
269 {% for p in foo%}
270 {{p.bar}}
271 {% for f in p.fields recursive%}
272 {{f.baz}}
273 {{p.bar}}
274 {% if f.rec %}
275 {{ loop(f.sub) }}
276 {% endif %}
277 {% endfor %}
278 {% endfor %}
279 """
280 )
281
282 def test_else_loop_bug(self, env):
283 t = Template(
284 """
285 {% for x in y %}
286 {{ loop.index0 }}
287 {% else %}
288 {% for i in range(3) %}{{ i }}{% endfor %}
289 {% endfor %}
290 """
291 )
292 assert t.render(y=[]).strip() == "012"
293
294 def test_correct_prefix_loader_name(self, env):
295 env = Environment(loader=PrefixLoader({"foo": DictLoader({})}))
296 with pytest.raises(TemplateNotFound) as e:
297 env.get_template("foo/bar.html")
298
299 assert e.value.name == "foo/bar.html"
300
301 def test_pass_context_callable_class(self, env):
302 class CallableClass:
303 @pass_context
304 def __call__(self, ctx):
305 return ctx.resolve("hello")
306
307 tpl = Template("""{{ callableclass() }}""")
308 output = tpl.render(callableclass=CallableClass(), hello="TEST")
309 expected = "TEST"
310
311 assert output == expected
312
313 def test_block_set_with_extends(self):
314 env = Environment(
315 loader=DictLoader({"main": "{% block body %}[{{ x }}]{% endblock %}"})
316 )
317 t = env.from_string('{% extends "main" %}{% set x %}42{% endset %}')
318 assert t.render() == "[42]"
319
320 def test_nested_for_else(self, env):
321 tmpl = env.from_string(
322 "{% for x in y %}{{ loop.index0 }}{% else %}"
323 "{% for i in range(3) %}{{ i }}{% endfor %}"
324 "{% endfor %}"
325 )
326 assert tmpl.render() == "012"
327
328 def test_macro_var_bug(self, env):
329 tmpl = env.from_string(
330 """
331 {% set i = 1 %}
332 {% macro test() %}
333 {% for i in range(0, 10) %}{{ i }}{% endfor %}
334 {% endmacro %}{{ test() }}
335 """
336 )
337 assert tmpl.render().strip() == "0123456789"
338
339 def test_macro_var_bug_advanced(self, env):
340 tmpl = env.from_string(
341 """
342 {% macro outer() %}
343 {% set i = 1 %}
344 {% macro test() %}
345 {% for i in range(0, 10) %}{{ i }}{% endfor %}
346 {% endmacro %}{{ test() }}
347 {% endmacro %}{{ outer() }}
348 """
349 )
350 assert tmpl.render().strip() == "0123456789"
351
352 def test_callable_defaults(self):
353 env = Environment()
354 env.globals["get_int"] = lambda: 42
355 t = env.from_string(
356 """
357 {% macro test(a, b, c=get_int()) -%}
358 {{ a + b + c }}
359 {%- endmacro %}
360 {{ test(1, 2) }}|{{ test(1, 2, 3) }}
361 """
362 )
363 assert t.render().strip() == "45|6"
364
365 def test_macro_escaping(self):
366 env = Environment(autoescape=lambda x: False)
367 template = "{% macro m() %}<html>{% endmacro %}"
368 template += "{% autoescape true %}{{ m() }}{% endautoescape %}"
369 assert env.from_string(template).render()
370
371 def test_macro_scoping(self, env):
372 tmpl = env.from_string(
373 """
374 {% set n=[1,2,3,4,5] %}
375 {% for n in [[1,2,3], [3,4,5], [5,6,7]] %}
376
377 {% macro x(l) %}
378 {{ l.pop() }}
379 {% if l %}{{ x(l) }}{% endif %}
380 {% endmacro %}
381
382 {{ x(n) }}
383
384 {% endfor %}
385 """
386 )
387 assert list(map(int, tmpl.render().split())) == [3, 2, 1, 5, 4, 3, 7, 6, 5]
388
389 def test_scopes_and_blocks(self):
390 env = Environment(
391 loader=DictLoader(
392 {
393 "a.html": """
394 {%- set foo = 'bar' -%}
395 {% include 'x.html' -%}
396 """,
397 "b.html": """
398 {%- set foo = 'bar' -%}
399 {% block test %}{% include 'x.html' %}{% endblock -%}
400 """,
401 "c.html": """
402 {%- set foo = 'bar' -%}
403 {% block test %}{% set foo = foo
404 %}{% include 'x.html' %}{% endblock -%}
405 """,
406 "x.html": """{{ foo }}|{{ test }}""",
407 }
408 )
409 )
410
411 a = env.get_template("a.html")
412 b = env.get_template("b.html")
413 c = env.get_template("c.html")
414
415 assert a.render(test="x").strip() == "bar|x"
416 assert b.render(test="x").strip() == "bar|x"
417 assert c.render(test="x").strip() == "bar|x"
418
419 def test_scopes_and_include(self):
420 env = Environment(
421 loader=DictLoader(
422 {
423 "include.html": "{{ var }}",
424 "base.html": '{% include "include.html" %}',
425 "child.html": '{% extends "base.html" %}{% set var = 42 %}',
426 }
427 )
428 )
429 t = env.get_template("child.html")
430 assert t.render() == "42"
431
432 def test_caller_scoping(self, env):
433 t = env.from_string(
434 """
435 {% macro detail(icon, value) -%}
436 {% if value -%}
437 <p><span class="fa fa-fw fa-{{ icon }}"></span>
438 {%- if caller is undefined -%}
439 {{ value }}
440 {%- else -%}
441 {{ caller(value, *varargs) }}
442 {%- endif -%}</p>
443 {%- endif %}
444 {%- endmacro %}
445
446
447 {% macro link_detail(icon, value, href) -%}
448 {% call(value, href) detail(icon, value, href) -%}
449 <a href="{{ href }}">{{ value }}</a>
450 {%- endcall %}
451 {%- endmacro %}
452 """
453 )
454
455 assert t.module.link_detail("circle", "Index", "/") == (
456 '<p><span class="fa fa-fw fa-circle"></span><a href="/">Index</a></p>'
457 )
458
459 def test_variable_reuse(self, env):
460 t = env.from_string("{% for x in x.y %}{{ x }}{% endfor %}")
461 assert t.render(x={"y": [0, 1, 2]}) == "012"
462
463 t = env.from_string("{% for x in x.y %}{{ loop.index0 }}|{{ x }}{% endfor %}")
464 assert t.render(x={"y": [0, 1, 2]}) == "0|01|12|2"
465
466 t = env.from_string("{% for x in x.y recursive %}{{ x }}{% endfor %}")
467 assert t.render(x={"y": [0, 1, 2]}) == "012"
468
469 def test_double_caller(self, env):
470 t = env.from_string(
471 "{% macro x(caller=none) %}[{% if caller %}"
472 "{{ caller() }}{% endif %}]{% endmacro %}"
473 "{{ x() }}{% call x() %}aha!{% endcall %}"
474 )
475 assert t.render() == "[][aha!]"
476
477 def test_double_caller_no_default(self, env):
478 with pytest.raises(TemplateAssertionError) as exc_info:
479 env.from_string(
480 "{% macro x(caller) %}[{% if caller %}"
481 "{{ caller() }}{% endif %}]{% endmacro %}"
482 )
483 assert exc_info.match(
484 r'"caller" argument must be omitted or ' r"be given a default"
485 )
486
487 t = env.from_string(
488 "{% macro x(caller=none) %}[{% if caller %}"
489 "{{ caller() }}{% endif %}]{% endmacro %}"
490 )
491 with pytest.raises(TypeError) as exc_info:
492 t.module.x(None, caller=lambda: 42)
493 assert exc_info.match(
494 r"\'x\' was invoked with two values for the " r"special caller argument"
495 )
496
497 def test_macro_blocks(self, env):
498 t = env.from_string(
499 "{% macro x() %}{% block foo %}x{% endblock %}{% endmacro %}{{ x() }}"
500 )
501 assert t.render() == "x"
502
503 def test_scoped_block(self, env):
504 t = env.from_string(
505 "{% set x = 1 %}{% with x = 2 %}{% block y scoped %}"
506 "{{ x }}{% endblock %}{% endwith %}"
507 )
508 assert t.render() == "2"
509
510 def test_recursive_loop_filter(self, env):
511 t = env.from_string(
512 """
513 <?xml version="1.0" encoding="UTF-8"?>
514 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
515 {%- for page in [site.root] if page.url != this recursive %}
516 <url><loc>{{ page.url }}</loc></url>
517 {{- loop(page.children) }}
518 {%- endfor %}
519 </urlset>
520 """
521 )
522 sm = t.render(
523 this="/foo",
524 site={"root": {"url": "/", "children": [{"url": "/foo"}, {"url": "/bar"}]}},
525 )
526 lines = [x.strip() for x in sm.splitlines() if x.strip()]
527 assert lines == [
528 '<?xml version="1.0" encoding="UTF-8"?>',
529 '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
530 "<url><loc>/</loc></url>",
531 "<url><loc>/bar</loc></url>",
532 "</urlset>",
533 ]
534
535 def test_empty_if(self, env):
536 t = env.from_string("{% if foo %}{% else %}42{% endif %}")
537 assert t.render(foo=False) == "42"
538
539 def test_subproperty_if(self, env):
540 t = env.from_string(
541 "{% if object1.subproperty1 is eq object2.subproperty2 %}42{% endif %}"
542 )
543 assert (
544 t.render(
545 object1={"subproperty1": "value"}, object2={"subproperty2": "value"}
546 )
547 == "42"
548 )
549
550 def test_set_and_include(self):
551 env = Environment(
552 loader=DictLoader(
553 {
554 "inc": "bar",
555 "main": '{% set foo = "foo" %}{{ foo }}{% include "inc" %}',
556 }
557 )
558 )
559 assert env.get_template("main").render() == "foobar"
560
561 def test_loop_include(self):
562 env = Environment(
563 loader=DictLoader(
564 {
565 "inc": "{{ i }}",
566 "main": '{% for i in [1, 2, 3] %}{% include "inc" %}{% endfor %}',
567 }
568 )
569 )
570 assert env.get_template("main").render() == "123"
571
572 def test_grouper_repr(self):
573 from jinja2.filters import _GroupTuple
574
575 t = _GroupTuple("foo", [1, 2])
576 assert t.grouper == "foo"
577 assert t.list == [1, 2]
578 assert repr(t) == "('foo', [1, 2])"
579 assert str(t) == "('foo', [1, 2])"
580
581 def test_custom_context(self, env):
582 from jinja2.runtime import Context
583
584 class MyContext(Context):
585 pass
586
587 class MyEnvironment(Environment):
588 context_class = MyContext
589
590 loader = DictLoader({"base": "{{ foobar }}", "test": '{% extends "base" %}'})
591 env = MyEnvironment(loader=loader)
592 assert env.get_template("test").render(foobar="test") == "test"
593
594 def test_recursive_loop_bug(self, env):
595 tmpl = env.from_string(
596 "{%- for value in values recursive %}1{% else %}0{% endfor -%}"
597 )
598 assert tmpl.render(values=[]) == "0"
599
600 def test_markup_and_chainable_undefined(self):
601 from markupsafe import Markup
602
603 from jinja2.runtime import ChainableUndefined
604
605 assert str(Markup(ChainableUndefined())) == ""
606
607 def test_scoped_block_loop_vars(self, env):
608 tmpl = env.from_string(
609 """\
610 Start
611 {% for i in ["foo", "bar"] -%}
612 {% block body scoped -%}
613 {{ loop.index }}) {{ i }}{% if loop.last %} last{% endif -%}
614 {%- endblock %}
615 {% endfor -%}
616 End"""
617 )
618 assert tmpl.render() == "Start\n1) foo\n2) bar last\nEnd"
619
620 def test_pass_context_loop_vars(self, env):
621 @pass_context
622 def test(ctx):
623 return f"{ctx['i']}{ctx['j']}"
624
625 tmpl = env.from_string(
626 """\
627 {% set i = 42 %}
628 {%- for idx in range(2) -%}
629 {{ i }}{{ j }}
630 {% set i = idx -%}
631 {%- set j = loop.index -%}
632 {{ test() }}
633 {{ i }}{{ j }}
634 {% endfor -%}
635 {{ i }}{{ j }}"""
636 )
637 tmpl.globals["test"] = test
638 assert tmpl.render() == "42\n01\n01\n42\n12\n12\n42"
639
640 def test_pass_context_scoped_loop_vars(self, env):
641 @pass_context
642 def test(ctx):
643 return f"{ctx['i']}"
644
645 tmpl = env.from_string(
646 """\
647 {% set i = 42 %}
648 {%- for idx in range(2) -%}
649 {{ i }}
650 {%- set i = loop.index0 -%}
651 {% block body scoped %}
652 {{ test() }}
653 {% endblock -%}
654 {% endfor -%}
655 {{ i }}"""
656 )
657 tmpl.globals["test"] = test
658 assert tmpl.render() == "42\n0\n42\n1\n42"
659
660 def test_pass_context_in_blocks(self, env):
661 @pass_context
662 def test(ctx):
663 return f"{ctx['i']}"
664
665 tmpl = env.from_string(
666 """\
667 {%- set i = 42 -%}
668 {{ i }}
669 {% block body -%}
670 {% set i = 24 -%}
671 {{ test() }}
672 {% endblock -%}
673 {{ i }}"""
674 )
675 tmpl.globals["test"] = test
676 assert tmpl.render() == "42\n24\n42"
677
678 def test_pass_context_block_and_loop(self, env):
679 @pass_context
680 def test(ctx):
681 return f"{ctx['i']}"
682
683 tmpl = env.from_string(
684 """\
685 {%- set i = 42 -%}
686 {% for idx in range(2) -%}
687 {{ test() }}
688 {%- set i = idx -%}
689 {% block body scoped %}
690 {{ test() }}
691 {% set i = 24 -%}
692 {{ test() }}
693 {% endblock -%}
694 {{ test() }}
695 {% endfor -%}
696 {{ test() }}"""
697 )
698 tmpl.globals["test"] = test
699
700 # values set within a block or loop should not
701 # show up outside of it
702 assert tmpl.render() == "42\n0\n24\n0\n42\n1\n24\n1\n42"
703
704 @pytest.mark.parametrize("op", ["extends", "include"])
705 def test_cached_extends(self, op):
706 env = Environment(
707 loader=DictLoader(
708 {"base": "{{ x }} {{ y }}", "main": f"{{% {op} 'base' %}}"}
709 )
710 )
711 env.globals["x"] = "x"
712 env.globals["y"] = "y"
713
714 # template globals overlay env globals
715 tmpl = env.get_template("main", globals={"x": "bar"})
716 assert tmpl.render() == "bar y"
717
718 # base was loaded indirectly, it just has env globals
719 tmpl = env.get_template("base")
720 assert tmpl.render() == "x y"
721
722 # set template globals for base, no longer uses env globals
723 tmpl = env.get_template("base", globals={"x": 42})
724 assert tmpl.render() == "42 y"
725
726 # templates are cached, they keep template globals set earlier
727 tmpl = env.get_template("main")
728 assert tmpl.render() == "bar y"
729
730 tmpl = env.get_template("base")
731 assert tmpl.render() == "42 y"
732
733 def test_nested_loop_scoping(self, env):
734 tmpl = env.from_string(
735 "{% set output %}{% for x in [1,2,3] %}hello{% endfor %}"
736 "{% endset %}{{ output }}"
737 )
738 assert tmpl.render() == "hellohellohello"
739
740 def test_pass_context_with_select(self, env):
741 @pass_context
742 def is_foo(ctx, s):
743 assert ctx is not None
744 return s == "foo"
745
746 env.tests["foo"] = is_foo
747 tmpl = env.from_string(
748 "{% for x in ['one', 'foo'] | select('foo') %}{{ x }}{% endfor %}"
749 )
750 assert tmpl.render() == "foo"
751
752
753 def test_load_parameter_when_set_in_all_if_branches(env):
754 tmpl = env.from_string(
755 "{% if True %}{{ a.b }}{% set a = 1 %}"
756 "{% elif False %}{% set a = 2 %}"
757 "{% else %}{% set a = 3 %}{% endif %}"
758 "{{ a }}"
759 )
760 assert tmpl.render(a={"b": 0}) == "01"
761
762
763 @pytest.mark.parametrize("unicode_char", ["\N{FORM FEED}", "\x85"])
764 def test_unicode_whitespace(env, unicode_char):
765 content = "Lorem ipsum\n" + unicode_char + "\nMore text"
766 tmpl = env.from_string(content)
767 assert tmpl.render() == content