Skip to content
Myr

Added test for mappings. This fixes #35

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

authored by Armin Ronacher · committed by Armin Ronacher · parent 067879e · Browse files · 3 files+25 added−2 removed
This commit

State

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

Diff stats

3 files+25 added−2 removed

  • other:+25 added−2 removed

3 files+25 added−2 removed

modified:jinja2/testsuite/tests.py+8 added-2 removed
46 unmodified lines
47 {{ [1] is sequence }}48 {{ range is callable }}49 {{ 42 is callable }}50 {{ range(5) is iterable }}51 {{ {} is mapping }}52 {{ mydict is mapping }}53 {{ [] is mapping }}54 ''')55 class MyDict(dict):56 pass52 assert tmpl.render().split() == [57 assert tmpl.render(mydict=MyDict()).split() == [58 'False', 'True', 'False', 'True', 'True', 'False',54 'True', 'True', 'True', 'True', 'False', 'True'59 'True', 'True', 'True', 'True', 'False', 'True',60 'True', 'True', 'False'61 ]6263 def test_sequence(self):64 tmpl = env.from_string(
29 unmodified lines
modified:jinja2/tests.py+15 added
9 unmodified lines
10"""11import re12from jinja2.runtime import Undefined1314try:15 from collections import Mapping as MappingType16except ImportError:17 import UserDict18 MappingType = (UserDict.UserDict, UserDict.DictMixin, dict)1920# nose, nothing here to test21__test__ = False2223
64 unmodified lines
88 """Return true if the object is a string."""89 return isinstance(value, basestring)909192def test_mapping(value):93 """Return true if the object is a mapping (dict etc.).9495 .. versionadded:: 2.696 """97 return isinstance(value, MappingType)9899100def test_number(value):101 """Return true if the variable is a number."""102 return isinstance(value, (int, long, float, complex))103
46 unmodified lines
150 'none': test_none,151 'lower': test_lower,152 'upper': test_upper,153 'string': test_string,154 'mapping': test_mapping,155 'number': test_number,156 'sequence': test_sequence,157 'iterable': test_iterable,158 'callable': test_callable,
3 unmodified lines
modified:CHANGES+2 added
30 unmodified lines
31- like sum, sort now also makes it possible to order items by attribute.32- like sum and sort, join now also is able to join attributes of objects33 as string.34- the internal eval context now has a reference to the environment.35- added a mapping test to see if an object is a dict or an object with36 a similar interface.3738Version 2.5.539-------------40(re-release of 2.5.4 with built documentation removed for filesize.
229 unmodified lines