Download asyncgui/modified_testcases/test_TaskCounter.py from Dorothydu/gitrepo_top_sample_50: direct link, hf CLI and curl.
- Browser
- Download file 1.77 kB
-
https://huggingface.co/datasets/Dorothydu/gitrepo_top_sample_50/resolve/main/asyncgui/modified_testcases/test_TaskCounter.py
- Command line
-
hf download hf://datasets/Dorothydu/gitrepo_top_sample_50/asyncgui/modified_testcases/test_TaskCounter.py
-
curl -L -o test_TaskCounter.py https://huggingface.co/datasets/Dorothydu/gitrepo_top_sample_50/resolve/main/asyncgui/modified_testcases/test_TaskCounter.py
1.77 kB
| import pytest | |
| def test_wait(): | |
| import asyncgui as ag | |
| tc = ag.TaskCounter() | |
| task = ag.start(tc.to_be_zero()) | |
| assert task.finished | |
| def test_decr_decr(): | |
| import asyncgui as ag | |
| tc = ag.TaskCounter() | |
| with pytest.raises(AssertionError): | |
| tc.decrease() | |
| with pytest.raises(AssertionError): | |
| tc.decrease() | |
| assert tc._n_children == 0 | |
| def test_incr_wait_decr(): | |
| import asyncgui as ag | |
| tc = ag.TaskCounter() | |
| tc.increase() | |
| task = ag.start(tc.to_be_zero()) | |
| assert not task.finished | |
| tc.decrease() | |
| assert task.finished | |
| def test_incr_decr_wait(): | |
| import asyncgui as ag | |
| tc = ag.TaskCounter() | |
| tc.increase() | |
| tc.decrease() | |
| task = ag.start(tc.to_be_zero()) | |
| assert task.finished | |
| def test_incr_decr_incr_wait_decr(): | |
| import asyncgui as ag | |
| tc = ag.TaskCounter() | |
| tc.increase() | |
| tc.decrease() | |
| tc.increase() | |
| task = ag.start(tc.to_be_zero()) | |
| assert not task.finished | |
| tc.decrease() | |
| assert task.finished | |
| def test_boolean(): | |
| import asyncgui as ag | |
| tc = ag.TaskCounter() | |
| assert not tc | |
| tc.increase() | |
| assert tc | |
| tc.decrease() | |
| assert not tc | |
| def test_cancel(): | |
| import asyncgui as ag | |
| TS = ag.TaskState | |
| async def async_fn(ctx, tc): | |
| async with ag.open_cancel_scope() as scope: | |
| ctx['scope'] = scope | |
| await tc.to_be_zero() | |
| pytest.fail() | |
| await ag.sleep_forever() | |
| ctx = {} | |
| tc = ag.TaskCounter() | |
| tc.increase() | |
| task = ag.start(async_fn(ctx, tc)) | |
| assert task.state is TS.STARTED | |
| ctx['scope'].cancel() | |
| assert task.state is TS.STARTED | |
| tc.decrease() | |
| assert task.state is TS.STARTED | |
| task._step() | |
| assert task.state is TS.FINISHED | |