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
Provenance
- Commit
ee352ec- Tree
640c911- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
067879e
3 files changed+25 added−2 removed
modified:jinja2/testsuite/tests.py+8 added-2 removed
46 unmodified lines47 {{ [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 ]62 63 def test_sequence(self):64 tmpl = env.from_string(29 unmodified linesmodified:jinja2/tests.py+15 added
9 unmodified lines10 """11 import re12 from jinja2.runtime import Undefined13 14+try:15+ from collections import Mapping as MappingType16+except ImportError:17+ import UserDict18+ MappingType = (UserDict.UserDict, UserDict.DictMixin, dict)19+20 # nose, nothing here to test21 __test__ = False22 23 64 unmodified lines88 """Return true if the object is a string."""89 return isinstance(value, basestring)90 91 92+def test_mapping(value):93+ """Return true if the object is a mapping (dict etc.).94+95+ .. versionadded:: 2.696+ """97+ return isinstance(value, MappingType)98+99+100 def test_number(value):101 """Return true if the variable is a number."""102 return isinstance(value, (int, long, float, complex))103 46 unmodified lines150 '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 linesmodified:CHANGES+2 added
30 unmodified lines31 - 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.37 38 Version 2.5.539 -------------40 (re-release of 2.5.4 with built documentation removed for filesize.229 unmodified lines