mirror of https://github.com/tqdm/tqdm.git
it/s versus s/it: addresses #72
This commit is contained in:
parent
6969610f12
commit
dc8eeedeb1
|
@ -119,10 +119,11 @@ def format_meter(n, total, elapsed, ncols=None, prefix='', ascii=False,
|
|||
# (we allow manual override since predicting time is an arcane art)
|
||||
if rate is None and elapsed:
|
||||
rate = n / elapsed
|
||||
rate_fmt = ((format_sizeof(rate) if unit_scale else
|
||||
'{0:5.2f}'.format(rate)) if elapsed else
|
||||
'?') \
|
||||
+ unit + '/s'
|
||||
inv_rate = 1 / rate if (rate and (rate < 1)) else None
|
||||
rate_fmt = ((format_sizeof(inv_rate if inv_rate else rate) if unit_scale
|
||||
else '{0:5.2f}'.format(inv_rate if inv_rate else rate))
|
||||
if elapsed else '?') \
|
||||
+ ('s' if inv_rate else unit) + '/' + (unit if inv_rate else 's')
|
||||
|
||||
if unit_scale:
|
||||
n_fmt = format_sizeof(n)
|
||||
|
|
|
@ -56,12 +56,12 @@ def test_format_meter():
|
|||
"desc: 0%| | 0/1000 [00:13<?, 0.00it/s]"
|
||||
assert format_meter(231, 1000, 392) == \
|
||||
" 23%|" + unich(0x2588) * 2 + unich(0x258e) + \
|
||||
" | 231/1000 [06:32<21:44, 0.59it/s]"
|
||||
" | 231/1000 [06:32<21:44, 1.70s/it]"
|
||||
assert format_meter(10000, 1000, 13) == \
|
||||
"10000it [00:13, 769.23it/s]"
|
||||
assert format_meter(231, 1000, 392, ncols=56, ascii=True) == \
|
||||
" 23%|" + '#' * 3 + '6' + \
|
||||
" | 231/1000 [06:32<21:44, 0.59it/s]"
|
||||
" | 231/1000 [06:32<21:44, 1.70s/it]"
|
||||
assert format_meter(100000, 1000, 13, unit_scale=True, unit='iB') == \
|
||||
"100KiB [00:13, 7.69KiB/s]"
|
||||
assert format_meter(100, 1000, 12, ncols=0, rate=7.33) == \
|
||||
|
|
Loading…
Reference in New Issue