Skip to content
Myr

Merge pull request #406 from ThiefMaster/number-test-fix

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

Fix `long_integer is number` check in Python 2

authored by Markus Unterwaditzer · committed by Markus Unterwaditzer · parents d09edda, 1e73c09 · Browse files · 4 files+11 added−4 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+11 added−4 removed

  • other:+11 added−4 removed

4 files+11 added−4 removed

modified:jinja2/testsuite/tests.py+6 added-2 removed
49 unmodified lines
50 {{ range(5) is iterable }}51 {{ {} is mapping }}52 {{ mydict is mapping }}53 {{ [] is mapping }}54 {{ 10 is number }}55 {{ (10 ** 100) is number }}56 {{ 3.14159 is number }}57 {{ complex is number }}58 ''')59 class MyDict(dict):60 pass57 assert tmpl.render(mydict=MyDict()).split() == [61 assert tmpl.render(mydict=MyDict(), complex=complex(1, 2)).split() == [62 'False', 'True', 'False', 'True', 'True', 'False',63 'True', 'True', 'True', 'True', 'False', 'True',60 'True', 'True', 'False'64 'True', 'True', 'False', 'True', 'True', 'True', 'True'65 ]6667 def test_sequence(self):68 tmpl = env.from_string(
40 unmodified lines
modified:jinja2/_compat.py+2 added
20 unmodified lines
21 unichr = chr22 range_type = range23 text_type = str24 string_types = (str,)25 integer_types = (int,)2627 iterkeys = lambda d: iter(d.keys())28 itervalues = lambda d: iter(d.values())29 iteritems = lambda d: iter(d.items())
21 unmodified lines
51 unichr = unichr52 text_type = unicode53 range_type = xrange54 string_types = (str, unicode)55 integer_types = (int, long)5657 iterkeys = lambda d: d.iterkeys()58 itervalues = lambda d: d.itervalues()59 iteritems = lambda d: d.iteritems()
52 unmodified lines
modified:jinja2/tests.py+2 added-2 removed
9 unmodified lines
10"""11import re12from collections import Mapping13from jinja2.runtime import Undefined14from jinja2._compat import text_type, string_types14from jinja2._compat import text_type, string_types, integer_types151617number_re = re.compile(r'^-?\d+(\.\d+)?$')18regex_type = type(number_re)
68 unmodified lines
878889def test_number(value):90 """Return true if the variable is a number."""91 return isinstance(value, (int, float, complex))91 return isinstance(value, integer_types + (float, complex))929394def test_sequence(value):95 """Return true if the variable is a sequence. Sequences are variables
76 unmodified lines
modified:CHANGES+1 added
18 unmodified lines
19- If unmarshalling of cached data fails the template will be20 reloaded now.21- Implemented a block ``set`` tag.22- Default cache size was incrased to 400 from a low 50.23- Fixed ``is number`` test to accept long integers in all Python versions.2425Version 2.7.326-------------27(bugfix release, released on June 6th 2014)
328 unmodified lines