Adding upstream version 4.64.1.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
ee08d9327c
commit
2da88b2fbc
89 changed files with 16770 additions and 0 deletions
515
tests_notebook.ipynb
Normal file
515
tests_notebook.ipynb
Normal file
|
@ -0,0 +1,515 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"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."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from functools import partial\n",
|
||||
"from time import sleep\n",
|
||||
"\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)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Help on function display in module tqdm.notebook:\n",
|
||||
"\n",
|
||||
"display(self, msg=None, pos=None, close=False, bar_style=None, check_delay=True)\n",
|
||||
" 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": [
|
||||
"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": [
|
||||
" 0%| | 0/9 [00:00<?, ?it/s]"
|
||||
]
|
||||
},
|
||||
"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",
|
||||
"8\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"application/vnd.jupyter.widget-view+json": {
|
||||
"model_id": "e29668be41ca4e40b16fb98572b333a5",
|
||||
"version_major": 2,
|
||||
"version_minor": 0
|
||||
},
|
||||
"text/plain": [
|
||||
" 0%| | 0/9 [00:00<?, ?it/s]"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"True"
|
||||
]
|
||||
},
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# NBVAL_TEST_NAME: basic use\n",
|
||||
"with tqdm_notebook(range(9)) as t:\n",
|
||||
" for i in t:\n",
|
||||
" print(i)\n",
|
||||
"assert t.container.children[1].bar_style == 'success'\n",
|
||||
"\n",
|
||||
"t = tqdm_notebook(total=9)\n",
|
||||
"t.update()\n",
|
||||
"t.refresh()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
" 11%|█ | 1/9 [00:00<00:00, 17.73it/s]\n",
|
||||
" 20%|██ | 1/5 [00:00<00:00, 341.50it/s]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# NBVAL_TEST_NAME: reset\n",
|
||||
"print(t)\n",
|
||||
"t.reset(total=5)\n",
|
||||
"t.update(1)\n",
|
||||
"print(t)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# 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'"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
" 0%| | 0/8 [00:00<?, ?it/s]\n",
|
||||
" 0%| | 0/8 [00:00<?, ?it/s]\n",
|
||||
"1\n",
|
||||
" 0%| | 0/8 [00:00<?, ?it/s]\n",
|
||||
" 0%| | 0/8 [00:00<?, ?it/s]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# NBVAL_TEST_NAME: repr\n",
|
||||
"with trange(1, 9) as t:\n",
|
||||
" print(t)\n",
|
||||
" print(t.container)\n",
|
||||
" it = iter(t)\n",
|
||||
" print(next(it))\n",
|
||||
" print(t)\n",
|
||||
" print(t.container)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"t = trange(9)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
" 0%| | 0/9 [00:00<?, ?it/s]\n",
|
||||
" 0%| | 0/9 [00:00<?, ?it/s]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# NBVAL_TEST_NAME: display pre\n",
|
||||
"print(t)\n",
|
||||
"print(t.container)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"for i in t:\n",
|
||||
" pass"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"100%|██████████| 9/9 [00:00<00:00, 132.23it/s]\n",
|
||||
"100%|##########| 9/9 [00:00<00:00, 131.02it/s]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# NBVAL_TEST_NAME: display post\n",
|
||||
"print(t)\n",
|
||||
"print(t.container)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 11,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"no total: 0it [00:00, ?it/s]\n",
|
||||
"no total: 1it [00:00, 47.83it/s]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# NBVAL_TEST_NAME: no total\n",
|
||||
"with tqdm(desc=\"no total\") as t:\n",
|
||||
" print(t)\n",
|
||||
" t.update()\n",
|
||||
" print(t)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 12,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
" 0%| | 0/9 [00:00<?, ?it/s]\n",
|
||||
" 11%|███▍ | 1/9 [00:00<00:00, 45.06it/s]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# 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",
|
||||
"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",
|
||||
"for total in (1, 9):\n",
|
||||
" with tqdm(total=total, leave=False) as t:\n",
|
||||
" print(t)\n",
|
||||
" t.update()\n",
|
||||
" print(t)\n",
|
||||
" assert total != 1 or is_hidden(t.container)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"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",
|
||||
" print(t)\n",
|
||||
" t.update()\n",
|
||||
" print(t)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 15,
|
||||
"metadata": {},
|
||||
"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",
|
||||
" 11%|█ | 1/9 [00:00<00:00, 1752.01it/s]\n",
|
||||
"0it [00:00, ?it/s]\n",
|
||||
"1it [00:00, 35.88it/s]\n",
|
||||
" 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",
|
||||
"0it [00:00, ?it/s]\n",
|
||||
"0it [00:00, ?it/s]\n",
|
||||
" 0%| | 0/1 [00:00<?, ?it/s]\n",
|
||||
" 0%| | 0/1 [00:00<?, ?it/s]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# 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",
|
||||
" with tqdm(disable=disable) as t:\n",
|
||||
" print(t)\n",
|
||||
" t.update()\n",
|
||||
" print(t)\n",
|
||||
"\n",
|
||||
" t.reset(total=1)\n",
|
||||
" print(t)\n",
|
||||
" t.update()\n",
|
||||
" print(t)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 16,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
" 0%|| 0/1 [00:00<?, ?it/s]\n",
|
||||
"100%|| 1/1 [00:00<00:00, 32.57it/s]\n",
|
||||
" 0%| \n",
|
||||
"100%|██████████\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# NBVAL_TEST_NAME: bar_format\n",
|
||||
"with tqdm(total=1, bar_format='{l_bar}{r_bar}') as t:\n",
|
||||
" print(t)\n",
|
||||
" 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",
|
||||
" print(t)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"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'"
|
||||
]
|
||||
},
|
||||
{
|
||||
"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()"
|
||||
]
|
||||
}
|
||||
],
|
||||
"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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue