tests: notebook: more tests

This commit is contained in:
Casper da Costa-Luis 2021-03-08 23:53:50 +00:00
parent 5eb36df4f0
commit 06698c5e97
No known key found for this signature in database
GPG Key ID: F5126E5FBD2512AD
2 changed files with 204 additions and 2 deletions

View File

@ -122,6 +122,9 @@ markers=
python_files=tests_*.py tests_*.ipynb
testpaths=tests
addopts=-v --tb=short -rxs -W=error --durations=0 --durations-min=0.1
[regex1]
regex: (?<= )[\s\d.]+(it/s|s/it)
replace: ??.??it/s
[coverage:run]
branch=True

View File

@ -1,12 +1,29 @@
{
"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 tqdm.notebook import tqdm"
"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)"
]
},
{
@ -36,7 +53,189 @@
}
],
"source": [
"help(tqdm.display)"
"help(tqdm_notebook.display)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# basic use"
]
},
{
"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/10 [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",
"9\n"
]
}
],
"source": [
"for i in tqdm_notebook(range(10)):\n",
" sleep(0.01)\n",
" print(i)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# repr"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 0%| | 0/9 [00:00<?, ?it/s]\n",
" 0%| | 0/9 [00:00<?, ?it/s]\n",
"1\n",
" 0%| | 0/9 [00:00<?, ?it/s]\n",
" 0%| | 0/9 [00:00<?, ?it/s]\n"
]
}
],
"source": [
"with trange(1, 10) as pbar:\n",
" print(pbar)\n",
" print(pbar.container)\n",
" it = iter(pbar)\n",
" print(next(it))\n",
" print(pbar)\n",
" print(pbar.container)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# display"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"t = trange(10)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 0%| | 0/10 [00:00<?, ?it/s]\n",
" 0%| | 0/10 [00:00<?, ?it/s]\n"
]
}
],
"source": [
"print(t)\n",
"print(t.container)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"for i in t:\n",
" pass"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"100%|██████████| 10/10 [00:00<00:00, 169.05it/s]\n",
"100%|##########| 10/10 [00:00<00:00, 168.12it/s]\n"
]
}
],
"source": [
"print(t)\n",
"print(t.container)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# no total"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"no total: 0it [00:00, ?it/s]\n",
"no total: 1it [00:00, 33.56it/s]\n"
]
}
],
"source": [
"with tqdm(desc=\"no total\") as t:\n",
" print(t)\n",
" t.update()\n",
" print(t)"
]
}
],