Skip to content
Myr

Fixed do_filesizeformat to actually calculate correctly, fixes #59

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

authored by Christopher Grebs · committed by Christopher Grebs · parent 898975d · Browse files · 2 files+23 added−5 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+23 added−5 removed

  • other:+23 added−5 removed

2 files+23 added−5 removed

modified:jinja2/testsuite/filters.py+19 added-1 removed
84 unmodified lines
85 )86 out = tmpl.render()87 self.assert_equal(out, (88 '100 Bytes|1.0 kB|1.0 MB|1.0 GB|1.0 TB|100 Bytes|'89 '1000 Bytes|1.0 MiB|0.9 GiB|0.9 TiB'89 '1000 Bytes|976.6 KiB|953.7 MiB|931.3 GiB'90 ))9192 def test_filesizeformat_issue59(self):93 tmpl = env.from_string(94 '{{ 300|filesizeformat }}|'95 '{{ 3000|filesizeformat }}|'96 '{{ 3000000|filesizeformat }}|'97 '{{ 3000000000|filesizeformat }}|'98 '{{ 3000000000000|filesizeformat }}|'99 '{{ 300|filesizeformat(true) }}|'100 '{{ 3000|filesizeformat(true) }}|'101 '{{ 3000000|filesizeformat(true) }}'102 )103 out = tmpl.render()104 self.assert_equal(out, (105 '300 Bytes|3.0 kB|3.0 MB|3.0 GB|3.0 TB|300 Bytes|'106 '2.9 KiB|2.9 MiB'107 ))108109110 def test_first(self):111 tmpl = env.from_string('{{ foo|first }}')112 out = tmpl.render(foo=range(10))113 assert out == '0'
261 unmodified lines
modified:jinja2/filters.py+4 added-4 removed
359 unmodified lines
360 elif bytes < base:361 return '%d Bytes' % bytes362 else:363 for i, prefix in enumerate(prefixes):364 unit = base ** (i + 1)365 if bytes <= unit:366 return '%.1f %s' % ((bytes / unit), prefix)367 return '%.1f %s' % ((bytes / unit), prefix)364 unit = base ** (i + 2)365 if bytes < unit:366 return '%.1f %s' % ((base * bytes / unit), prefix)367 return '%.1f %s' % ((base * bytes / unit), prefix)368369370def do_pprint(value, verbose=False):371 """Pretty print a variable. Useful for debugging.
430 unmodified lines