tests_notebook.ipynb
This file is part of the test suite and will be moved there when nbval#116 is fixed.
See DEMO.ipynb instead for notebook examples.
from functools import partial
from time import sleep
from tqdm.notebook import tqdm_notebook
from tqdm.notebook import tnrange
# avoid displaying widgets by default (pollutes output cells)
tqdm = partial(tqdm_notebook, display=False)
trange = partial(tnrange, display=False)
help(tqdm_notebook.display)
# NBVAL_TEST_NAME: basic use
with tqdm_notebook(range(9)) as t:
for i in t:
print(i)
assert t.container.children[1].bar_style == 'success'
t = tqdm_notebook(total=9)
t.update()
t.refresh()
# NBVAL_TEST_NAME: reset
print(t)
t.reset(total=5)
t.update(1)
print(t)
# NBVAL_TEST_NAME: bar_style
assert t.container.children[1].bar_style != 'danger'
t.close()
assert t.container.children[1].bar_style == 'danger'
# NBVAL_TEST_NAME: repr
with trange(1, 9) as t:
print(t)
print(t.container)
it = iter(t)
print(next(it))
print(t)
print(t.container)
t = trange(9)
# NBVAL_TEST_NAME: display pre
print(t)
print(t.container)
for i in t:
pass
# NBVAL_TEST_NAME: display post
print(t)
print(t.container)
# NBVAL_TEST_NAME: no total
with tqdm(desc="no total") as t:
print(t)
t.update()
print(t)
# NBVAL_TEST_NAME: ncols
with trange(9, ncols=66) as t:
print(t)
for i in t:
if i == 1:
break
print(t)
# NBVAL_TEST_NAME: leave
def is_hidden(widget):
return ('hidden', False, None) == (
getattr(getattr(widget, "layout", None), "visibility", 'visible'), # ipyw>=8
getattr(widget, "visible", False), getattr(widget, "_ipython_display_", None)) # ipyw<8
assert not is_hidden(t.container)
for total in (1, 9):
with tqdm(total=total, leave=False) as t:
print(t)
t.update()
print(t)
assert total != 1 or is_hidden(t.container)
# NBVAL_TEST_NAME: no total
with tqdm() as t:
print(t)
t.update()
print(t)
# NBVAL_TEST_NAME: reset and disable
for disable in (None, True):
print("disable:", disable)
with tqdm(total=1, disable=disable) as t:
print(t)
t.update()
print(t)
t.reset(total=9)
print(t)
t.update()
print(t)
with tqdm(disable=disable) as t:
print(t)
t.update()
print(t)
t.reset(total=1)
print(t)
t.update()
print(t)
# NBVAL_TEST_NAME: bar_format
with tqdm(total=1, bar_format='{l_bar}{r_bar}') as t:
print(t)
t.update()
print(t)
with tqdm(total=1, bar_format='{l_bar}{bar}') as t:
print(t)
t.update()
print(t)
# NBVAL_TEST_NAME: colour
assert t.colour != 'yellow'
with tqdm(total=1, colour='yellow') as t:
print(t)
t.update()
print(t)
assert t.colour == 'yellow'
# NBVAL_TEST_NAME: delay no trigger
with tqdm_notebook(total=1, delay=10) as t:
t.update()
# NBVAL_TEST_NAME: delay trigger
with tqdm_notebook(total=1, delay=0.1) as t:
sleep(0.1)
t.update()