X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=scripts%2Fjinja2%2Ftests.py;h=50510b0d353791c5dd3c3fd213cfc1545a9576cc;hb=31d36dd3e8a2b7b513958f005cc555e01b9c3d5b;hp=6873b5a8f5fc0de9a59c004a4096b6abaaac9231;hpb=279822e9e2a4f26deaf67b5fe8423b27837a75d7;p=libfirm diff --git a/scripts/jinja2/tests.py b/scripts/jinja2/tests.py index 6873b5a8f..50510b0d3 100644 --- a/scripts/jinja2/tests.py +++ b/scripts/jinja2/tests.py @@ -5,17 +5,33 @@ Jinja test functions. Used with the "is" operator. - :copyright: 2007 by Armin Ronacher. + :copyright: (c) 2010 by the Jinja Team. :license: BSD, see LICENSE for more details. """ import re from jinja2.runtime import Undefined +try: + from collections import Mapping as MappingType +except ImportError: + import UserDict + MappingType = (UserDict.UserDict, UserDict.DictMixin, dict) + +# nose, nothing here to test +__test__ = False + number_re = re.compile(r'^-?\d+(\.\d+)?$') regex_type = type(number_re) +try: + test_callable = callable +except NameError: + def test_callable(x): + return hasattr(x, '__call__') + + def test_odd(value): """Return true if the variable is odd.""" return value % 2 == 1 @@ -73,6 +89,14 @@ def test_string(value): return isinstance(value, basestring) +def test_mapping(value): + """Return true if the object is a mapping (dict etc.). + + .. versionadded:: 2.6 + """ + return isinstance(value, MappingType) + + def test_number(value): """Return true if the variable is a number.""" return isinstance(value, (int, long, float, complex)) @@ -127,10 +151,11 @@ TESTS = { 'lower': test_lower, 'upper': test_upper, 'string': test_string, + 'mapping': test_mapping, 'number': test_number, 'sequence': test_sequence, 'iterable': test_iterable, - 'callable': callable, + 'callable': test_callable, 'sameas': test_sameas, 'escaped': test_escaped }