Skip to content
Myr

Merged in ronny's fixes for round filter

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 · parents 10c34da, b299acb · Browse files · 2 files+11 added−8 removed
This commit

State

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

Diff stats

2 files+11 added−8 removed

  • other:+11 added−8 removed

2 files+11 added−8 removed

modified:jinja2/testsuite/filters.py+10 added-4 removed
204 unmodified lines
205 assert tmpl.render() == '21'206207 def test_abs(self):208 tmpl = env.from_string('''{{ -1|abs }}|{{ 1|abs }}''')209 return tmpl.render() == '1|1'209 assert tmpl.render() == '1|1', tmpl.render()210211 def test_round(self):211 def test_round_positive(self):212 tmpl = env.from_string('{{ 2.7|round }}|{{ 2.1|round }}|'213 "{{ 2.1234|round(2, 'floor') }}|"213 "{{ 2.1234|round(3, 'floor') }}|"214 "{{ 2.1|round(0, 'ceil') }}")215 return tmpl.render() == '3.0|2.0|2.1|3.0'215 assert tmpl.render() == '3.0|2.0|2.123|3.0', tmpl.render()216217 def test_round_negative(self):218 tmpl = env.from_string('{{ 21.3|round(-1)}}|'219 "{{ 21.3|round(-1, 'ceil')}}|"220 "{{ 21.3|round(-1, 'floor')}}")221 assert tmpl.render() == '20.0|30.0|20.0',tmpl.render()222223 def test_xmlattr(self):224 tmpl = env.from_string("{{ {'foo': 42, 'bar': 23, 'fish': none, "225 "'spam': missing, 'blub:blub': '<?>'}|xmlattr }}")226 out = tmpl.render().split()
65 unmodified lines
modified:jinja2/filters.py+1 added-4 removed
553 unmodified lines
554 -> 43555 """556 if not method in ('common', 'ceil', 'floor'):557 raise FilterArgumentError('method must be common, ceil or floor')558 if precision < 0:559 raise FilterArgumentError('precision must be a postive integer '560 'or zero.')558 if method == 'common':559 return round(value, precision)560 func = getattr(math, method)561 if precision:565 return func(value * 10 * precision) / (10 * precision)562 return func(value * (10 ** precision)) / (10 ** precision)563 else:564 return func(value)565566
156 unmodified lines