return '%d Bytes' % bytes
else:
for i, prefix in enumerate(prefixes):
- unit = base ** (i + 1)
- if bytes <= unit:
- return '%.1f %s' % ((bytes / unit), prefix)
- return '%.1f %s' % ((bytes / unit), prefix)
+ unit = base ** (i + 2)
+ if bytes < unit:
+ return '%.1f %s' % ((base * bytes / unit), prefix)
+ return '%.1f %s' % ((base * bytes / unit), prefix)
def do_pprint(value, verbose=False):
out = tmpl.render()
self.assert_equal(out, (
'100 Bytes|1.0 kB|1.0 MB|1.0 GB|1.0 TB|100 Bytes|'
- '1000 Bytes|1.0 MiB|0.9 GiB|0.9 TiB'
+ '1000 Bytes|976.6 KiB|953.7 MiB|931.3 GiB'
))
+ def test_filesizeformat_issue59(self):
+ tmpl = env.from_string(
+ '{{ 300|filesizeformat }}|'
+ '{{ 3000|filesizeformat }}|'
+ '{{ 3000000|filesizeformat }}|'
+ '{{ 3000000000|filesizeformat }}|'
+ '{{ 3000000000000|filesizeformat }}|'
+ '{{ 300|filesizeformat(true) }}|'
+ '{{ 3000|filesizeformat(true) }}|'
+ '{{ 3000000|filesizeformat(true) }}'
+ )
+ out = tmpl.render()
+ self.assert_equal(out, (
+ '300 Bytes|3.0 kB|3.0 MB|3.0 GB|3.0 TB|300 Bytes|'
+ '2.9 KiB|2.9 MiB'
+ ))
+
+
def test_first(self):
tmpl = env.from_string('{{ foo|first }}')
out = tmpl.render(foo=range(10))