Skip to content
Myr

[svn] added sameas test function

Before adoption: this commit came in with the history the project adopted, so no landing records it.

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent e39a5d2 · Browse files · 4 files+28 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+28 added−1 removed

  • tests:+6 added−0 removed
  • other:+22 added−1 removed

4 files+28 added−1 removed

modified:jinja/filters.py+2 added
870 unmodified lines
871872 As you can see the item we're grouping by is stored in the `grouper`873 attribute and the `list` contains all the objects that have this grouper874 in common.875876 *New in Jinja 1.2*877 """878 def wrapped(env, context, value):879 expr = lambda x: env.get_attribute(x, attribute)880 return [{
55 unmodified lines
modified:jinja/tests.py+18 added-1 removed
109 unmodified lines
110 return regex.search(value) is not None111 return wrapped112113114def test_sameas(other):115 """116 Check if an object points to the same memory address than another117 object:118119 .. sourcecode:: jinja120121 {% if foo.attribute is sameas(false) %}122 the foo attribute really is the `False` singleton123 {% endif %}124125 *New in Jinja 1.2*126 """127 return lambda e, c, v: v is other128129130TESTS = {131 'odd': test_odd,132 'even': test_even,133 'defined': test_defined,134 'lower': test_lower,135 'upper': test_upper,136 'numeric': test_numeric,137 'sequence': test_sequence,122 'matching': test_matching138 'matching': test_matching,139 'sameas': test_sameas140}
modified:tests/test_tests.py+6 added
17 unmodified lines
18SEQUENCE = '''{{ [1, 2, 3] is sequence }}|\19{{ "foo" is sequence }}|\20{{ 42 is sequence }}'''21UPPER = '''{{ "FOO" is upper }}|{{ "foo" is upper }}'''22SAMEAS = '''{{ foo is sameas(false) }}|{{ 0 is sameas(false) }}'''232425def test_defined(env):26 tmpl = env.from_string(DEFINED)
32 unmodified lines
5960def test_upper(env):61 tmpl = env.from_string(UPPER)62 assert tmpl.render() == 'True|False'636465def test_sameas(env):66 tmpl = env.from_string(SAMEAS)67 assert tmpl.render(foo=False) == 'True|False'
modified:CHANGES+2 added
12 unmodified lines
13- once again improved debugger.1415- added `groupby` filter.1617- added `sameas` test function.181920Version 1.121-----------22(codename: sinka, released Jun 1, 2007)23
119 unmodified lines