MCPcopy
hub / github.com/pallets/jinja / test_required_with_scope

Method test_required_with_scope

tests/test_inheritance.py:319–341  ·  view source on GitHub ↗
(self, env)

Source from the content-addressed store, hash-verified

317 t.render(t="if")
318
319 def test_required_with_scope(self, env):
320 env = Environment(
321 loader=DictLoader(
322 {
323 "default1": "{% for item in seq %}[{% block item scoped required %}"
324 "{% endblock %}]{% endfor %}",
325 "child1": "{% extends 'default1' %}{% block item %}"
326 "{{ item }}{% endblock %}",
327 "default2": "{% for item in seq %}[{% block item required scoped %}"
328 "{% endblock %}]{% endfor %}",
329 "child2": "{% extends 'default2' %}{% block item %}"
330 "{{ item }}{% endblock %}",
331 }
332 )
333 )
334 t1 = env.get_template("child1")
335 t2 = env.get_template("child2")
336
337 assert t1.render(seq=list(range(3))) == "[0][1][2]"
338
339 # scoped must come before required
340 with pytest.raises(TemplateSyntaxError):
341 t2.render(seq=list(range(3)))
342
343 def test_duplicate_required_or_scoped(self, env):
344 env = Environment(

Callers

nothing calls this directly

Calls 4

get_templateMethod · 0.95
EnvironmentClass · 0.90
DictLoaderClass · 0.90
renderMethod · 0.45

Tested by

no test coverage detected