2021-03-08 22:26:04 +00:00
{
"cells": [
2021-03-08 23:53:50 +00:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This file is part of the [test suite](./tests) and will be moved there when [nbval#116](https://github.com/computationalmodelling/nbval/issues/116#issuecomment-793148404) is fixed.\n",
"\n",
"See [DEMO.ipynb](DEMO.ipynb) instead for notebook examples."
]
},
2021-03-08 22:26:04 +00:00
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
2021-03-08 23:53:50 +00:00
"from functools import partial\n",
2021-04-05 15:52:03 +00:00
"from time import sleep\n",
2021-03-08 23:53:50 +00:00
"\n",
"from tqdm.notebook import tqdm_notebook\n",
"from tqdm.notebook import tnrange\n",
"\n",
"# avoid displaying widgets by default (pollutes output cells)\n",
"tqdm = partial(tqdm_notebook, display=False)\n",
"trange = partial(tnrange, display=False)"
2021-03-08 22:26:04 +00:00
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Help on function display in module tqdm.notebook:\n",
"\n",
2021-04-05 15:52:03 +00:00
"display(self, msg=None, pos=None, close=False, bar_style=None, check_delay=True)\n",
2021-03-08 22:26:04 +00:00
" Use `self.sp` to display `msg` in the specified `pos`.\n",
" \n",
" Consider overloading this function when inheriting to use e.g.:\n",
" `self.some_frontend(**self.format_dict)` instead of `self.sp`.\n",
" \n",
" Parameters\n",
" ----------\n",
" msg : str, optional. What to display (default: `repr(self)`).\n",
" pos : int, optional. Position to `moveto`\n",
" (default: `abs(self.pos)`).\n",
"\n"
]
}
],
"source": [
2021-03-08 23:53:50 +00:00
"help(tqdm_notebook.display)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "7c18c038bf964b55941e228503292506",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
2021-03-09 15:10:25 +00:00
" 0%| | 0/9 [00:00<?, ?it/s]"
2021-03-08 23:53:50 +00:00
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"0\n",
"1\n",
"2\n",
"3\n",
"4\n",
"5\n",
"6\n",
"7\n",
2021-03-09 15:10:25 +00:00
"8\n"
2021-03-08 23:53:50 +00:00
]
2021-03-09 00:53:19 +00:00
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "e29668be41ca4e40b16fb98572b333a5",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
2021-03-09 15:10:25 +00:00
" 0%| | 0/9 [00:00<?, ?it/s]"
2021-03-09 00:53:19 +00:00
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
2021-03-08 23:53:50 +00:00
}
],
"source": [
2021-03-09 15:10:25 +00:00
"# NBVAL_TEST_NAME: basic use\n",
"with tqdm_notebook(range(9)) as t:\n",
2021-03-09 00:53:19 +00:00
" for i in t:\n",
" print(i)\n",
2021-03-09 15:10:25 +00:00
"assert t.container.children[1].bar_style == 'success'\n",
2021-03-09 00:53:19 +00:00
"\n",
2021-03-09 15:10:25 +00:00
"t = tqdm_notebook(total=9)\n",
2021-03-09 00:53:19 +00:00
"t.update()\n",
"t.refresh()"
]
},
2021-03-08 23:53:50 +00:00
{
"cell_type": "code",
2021-03-09 00:53:19 +00:00
"execution_count": 4,
2021-03-08 23:53:50 +00:00
"metadata": {},
2021-03-09 00:53:19 +00:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2021-03-09 15:10:25 +00:00
" 11%|█ | 1/9 [00:00<00:00, 17.73it/s]\n",
" 20%|██ | 1/5 [00:00<00:00, 341.50it/s]\n"
2021-03-09 00:53:19 +00:00
]
}
],
"source": [
2021-03-09 15:10:25 +00:00
"# NBVAL_TEST_NAME: reset\n",
2021-03-09 00:53:19 +00:00
"print(t)\n",
"t.reset(total=5)\n",
"t.update(1)\n",
"print(t)"
]
2021-03-08 23:53:50 +00:00
},
{
2021-03-09 15:10:25 +00:00
"cell_type": "code",
"execution_count": 5,
2021-03-08 23:53:50 +00:00
"metadata": {},
2021-03-09 15:10:25 +00:00
"outputs": [],
2021-03-08 23:53:50 +00:00
"source": [
2021-03-09 15:10:25 +00:00
"# NBVAL_TEST_NAME: bar_style\n",
"assert t.container.children[1].bar_style != 'danger'\n",
"t.close()\n",
"assert t.container.children[1].bar_style == 'danger'"
2021-03-08 23:53:50 +00:00
]
},
{
"cell_type": "code",
2021-03-09 15:10:25 +00:00
"execution_count": 6,
2021-03-08 23:53:50 +00:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2021-03-09 15:10:25 +00:00
" 0%| | 0/8 [00:00<?, ?it/s]\n",
" 0%| | 0/8 [00:00<?, ?it/s]\n",
2021-03-08 23:53:50 +00:00
"1\n",
2021-03-09 15:10:25 +00:00
" 0%| | 0/8 [00:00<?, ?it/s]\n",
" 0%| | 0/8 [00:00<?, ?it/s]\n"
2021-03-08 23:53:50 +00:00
]
}
],
"source": [
2021-03-09 15:10:25 +00:00
"# NBVAL_TEST_NAME: repr\n",
"with trange(1, 9) as t:\n",
" print(t)\n",
" print(t.container)\n",
" it = iter(t)\n",
2021-03-08 23:53:50 +00:00
" print(next(it))\n",
2021-03-09 15:10:25 +00:00
" print(t)\n",
" print(t.container)"
2021-03-08 23:53:50 +00:00
]
},
{
"cell_type": "code",
2021-03-09 15:10:25 +00:00
"execution_count": 7,
2021-03-08 23:53:50 +00:00
"metadata": {},
"outputs": [],
"source": [
2021-03-09 15:10:25 +00:00
"t = trange(9)"
2021-03-08 23:53:50 +00:00
]
},
{
"cell_type": "code",
2021-03-09 15:10:25 +00:00
"execution_count": 8,
2021-03-08 23:53:50 +00:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2021-03-09 15:10:25 +00:00
" 0%| | 0/9 [00:00<?, ?it/s]\n",
" 0%| | 0/9 [00:00<?, ?it/s]\n"
2021-03-08 23:53:50 +00:00
]
}
],
"source": [
2021-03-09 15:10:25 +00:00
"# NBVAL_TEST_NAME: display pre\n",
2021-03-08 23:53:50 +00:00
"print(t)\n",
"print(t.container)"
]
},
{
"cell_type": "code",
2021-03-09 15:10:25 +00:00
"execution_count": 9,
2021-03-08 23:53:50 +00:00
"metadata": {},
"outputs": [],
"source": [
"for i in t:\n",
" pass"
]
},
{
"cell_type": "code",
2021-03-09 15:10:25 +00:00
"execution_count": 10,
2021-03-08 23:53:50 +00:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2021-03-09 15:10:25 +00:00
"100%|██████████| 9/9 [00:00<00:00, 132.23it/s]\n",
"100%|##########| 9/9 [00:00<00:00, 131.02it/s]\n"
2021-03-08 23:53:50 +00:00
]
}
],
"source": [
2021-03-09 15:10:25 +00:00
"# NBVAL_TEST_NAME: display post\n",
2021-03-08 23:53:50 +00:00
"print(t)\n",
"print(t.container)"
]
},
{
2021-03-09 15:10:25 +00:00
"cell_type": "code",
"execution_count": 11,
2021-03-08 23:53:50 +00:00
"metadata": {},
2021-03-09 15:10:25 +00:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"no total: 0it [00:00, ?it/s]\n",
"no total: 1it [00:00, 47.83it/s]\n"
]
}
],
2021-03-08 23:53:50 +00:00
"source": [
2021-03-09 15:10:25 +00:00
"# NBVAL_TEST_NAME: no total\n",
"with tqdm(desc=\"no total\") as t:\n",
" print(t)\n",
" t.update()\n",
" print(t)"
2021-03-08 23:53:50 +00:00
]
},
{
"cell_type": "code",
2021-03-09 15:10:25 +00:00
"execution_count": 12,
2021-03-08 23:53:50 +00:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2021-03-09 15:10:25 +00:00
" 0%| | 0/9 [00:00<?, ?it/s]\n",
" 11%|███▍ | 1/9 [00:00<00:00, 45.06it/s]\n"
2021-03-08 23:53:50 +00:00
]
}
],
"source": [
2021-03-09 15:10:25 +00:00
"# NBVAL_TEST_NAME: ncols\n",
"with trange(9, ncols=66) as t:\n",
" print(t)\n",
" for i in t:\n",
" if i == 1:\n",
" break\n",
" print(t)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 0%| | 0/1 [00:00<?, ?it/s]\n",
"100%|██████████| 1/1 [00:00<00:00, 54.60it/s]\n",
" 0%| | 0/9 [00:00<?, ?it/s]\n",
" 11%|█ | 1/9 [00:00<00:00, 57.43it/s]\n"
]
}
],
"source": [
"# NBVAL_TEST_NAME: leave\n",
2022-09-03 09:09:37 +00:00
"def is_hidden(widget):\n",
" return ('hidden', False, None) == (\n",
" getattr(getattr(widget, \"layout\", None), \"visibility\", 'visible'), # ipyw>=8\n",
" getattr(widget, \"visible\", False), getattr(widget, \"_ipython_display_\", None)) # ipyw<8\n",
"\n",
"assert not is_hidden(t.container)\n",
2021-03-09 15:10:25 +00:00
"for total in (1, 9):\n",
" with tqdm(total=total, leave=False) as t:\n",
" print(t)\n",
" t.update()\n",
" print(t)\n",
2022-09-03 09:09:37 +00:00
" assert total != 1 or is_hidden(t.container)"
2021-03-09 15:10:25 +00:00
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0it [00:00, ?it/s]\n",
"1it [00:00, 47.87it/s]\n"
]
}
],
"source": [
"# NBVAL_TEST_NAME: no total\n",
"with tqdm() as t:\n",
2021-03-08 23:53:50 +00:00
" print(t)\n",
" t.update()\n",
" print(t)"
2021-03-08 22:26:04 +00:00
]
2021-03-09 00:53:19 +00:00
},
{
2021-03-09 15:10:25 +00:00
"cell_type": "code",
"execution_count": 15,
2021-03-09 00:53:19 +00:00
"metadata": {},
2021-03-09 15:10:25 +00:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"disable: None\n",
" 0%| | 0/1 [00:00<?, ?it/s]\n",
"100%|██████████| 1/1 [00:00<00:00, 53.24it/s]\n",
" 0%| | 0/9 [00:00<?, ?it/s]\n",
2021-03-09 16:13:27 +00:00
" 11%|█ | 1/9 [00:00<00:00, 1752.01it/s]\n",
"0it [00:00, ?it/s]\n",
"1it [00:00, 35.88it/s]\n",
2021-03-09 15:10:25 +00:00
" 0%| | 0/1 [00:00<?, ?it/s]\n",
"100%|██████████| 1/1 [00:00<00:00, 1880.85it/s]\n",
"disable: True\n",
" 0%| | 0/1 [00:00<?, ?it/s]\n",
" 0%| | 0/1 [00:00<?, ?it/s]\n",
" 0%| | 0/9 [00:00<?, ?it/s]\n",
" 0%| | 0/9 [00:00<?, ?it/s]\n",
2021-03-09 16:13:27 +00:00
"0it [00:00, ?it/s]\n",
"0it [00:00, ?it/s]\n",
2021-03-09 15:10:25 +00:00
" 0%| | 0/1 [00:00<?, ?it/s]\n",
" 0%| | 0/1 [00:00<?, ?it/s]\n"
]
}
],
2021-03-09 00:53:19 +00:00
"source": [
2021-03-09 15:10:25 +00:00
"# NBVAL_TEST_NAME: reset and disable\n",
"for disable in (None, True):\n",
" print(\"disable:\", disable)\n",
" with tqdm(total=1, disable=disable) as t:\n",
" print(t)\n",
" t.update()\n",
" print(t)\n",
"\n",
" t.reset(total=9)\n",
" print(t)\n",
" t.update()\n",
" print(t)\n",
2021-03-09 16:13:27 +00:00
" with tqdm(disable=disable) as t:\n",
2021-03-09 15:10:25 +00:00
" print(t)\n",
" t.update()\n",
" print(t)\n",
"\n",
" t.reset(total=1)\n",
" print(t)\n",
" t.update()\n",
" print(t)"
2021-03-09 00:53:19 +00:00
]
},
{
"cell_type": "code",
2021-03-09 15:10:25 +00:00
"execution_count": 16,
2021-03-09 00:53:19 +00:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2021-03-09 15:10:25 +00:00
" 0%|| 0/1 [00:00<?, ?it/s]\n",
"100%|| 1/1 [00:00<00:00, 32.57it/s]\n",
" 0%| \n",
"100%|██████████\n"
2021-03-09 00:53:19 +00:00
]
}
],
"source": [
2021-03-09 15:10:25 +00:00
"# NBVAL_TEST_NAME: bar_format\n",
"with tqdm(total=1, bar_format='{l_bar}{r_bar}') as t:\n",
2021-03-09 00:53:19 +00:00
" print(t)\n",
2021-03-09 15:10:25 +00:00
" t.update()\n",
" print(t)\n",
"\n",
"with tqdm(total=1, bar_format='{l_bar}{bar}') as t:\n",
" print(t)\n",
" t.update()\n",
2021-03-09 00:53:19 +00:00
" print(t)"
]
2021-03-09 15:10:25 +00:00
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 0%|\u001b[33m \u001b[0m| 0/1 [00:00<?, ?it/s]\n",
"100%|\u001b[33m██████████\u001b[0m| 1/1 [00:00<00:00, 47.14it/s]\n"
]
}
],
"source": [
"# NBVAL_TEST_NAME: colour\n",
"assert t.colour != 'yellow'\n",
"with tqdm(total=1, colour='yellow') as t:\n",
" print(t)\n",
" t.update()\n",
" print(t)\n",
" assert t.colour == 'yellow'"
]
2021-04-05 15:52:03 +00:00
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"# NBVAL_TEST_NAME: delay no trigger\n",
"with tqdm_notebook(total=1, delay=10) as t:\n",
" t.update()"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "fe102eedbb4f437783fbd0cff32f6613",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"100%|##########| 1/1 [00:00<00:00, 7.68it/s]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# NBVAL_TEST_NAME: delay trigger\n",
"with tqdm_notebook(total=1, delay=0.1) as t:\n",
" sleep(0.1)\n",
" t.update()"
]
2021-03-08 22:26:04 +00:00
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:tqdm]",
"language": "python",
"name": "conda-env-tqdm-py"
},
"language_info": {
"codemirror_mode": {
"name": "ipython"
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}