Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+38 added−0 removed
tests:+38 added−0 removed
Provenance
Commit
61b5960
Tree
1ada610
Author
Armin Ronacher <armin.ronacher@active-4.com>
Committer
Armin Ronacher <armin.ronacher@active-4.com>
Parent
a1704eb
1 file changed+38 added−0 removed
added:tests/test_meta.py+38 added
1+# -*- coding: utf-8 -*-2+"""3+ unit test for the meta module4+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~5+6+ :copyright: (c) 2009 by the Jinja Team.7+ :license: BSD, see LICENSE for more details.8+"""9+from jinja2 import Environment, meta10+11+12+def test_find_undeclared_variables():13+ env = Environment()14+ ast = env.parse('{% set foo = 42 %}{{ bar + foo }}')15+ x = meta.find_undeclared_variables(ast)16+ assert x == set(['bar'])17+18+ ast = env.parse('{% set foo = 42 %}{{ bar + foo }}'19+ '{% macro meh(x) %}{{ x }}{% endmacro %}'20+ '{% for item in seq %}{{ muh(item) + meh(seq) }}{% endfor %}')21+ x = meta.find_undeclared_variables(ast)22+ assert x == set(['bar', 'seq', 'muh'])23+24+25+def test_find_refererenced_templates():26+ env = Environment()27+ ast = env.parse('{% extends "layout.html" %}{% include helper %}')28+ i = meta.find_referenced_templates(ast)29+ assert i.next() == 'layout.html'30+ assert i.next() is None31+ assert list(i) == []32+33+ ast = env.parse('{% extends "layout.html" %}'34+ '{% from "test.html" import a, b as c %}'35+ '{% import "meh.html" as meh %}'36+ '{% include "muh.html" %}')37+ i = meta.find_referenced_templates(ast)38+ assert list(i) == ['layout.html', 'test.html', 'meh.html', 'muh.html']