Skip to content

Commit bd1a594

Browse files
committed
Commit uncommitted test file
1 parent 3ce69ac commit bd1a594

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/test_work.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from contextlib import aclosing
2+
import pytest
3+
4+
from shrinkray.work import WorkContext, parallel_map
5+
6+
7+
async def identity(x: int) -> int:
8+
return x
9+
10+
11+
@pytest.mark.parametrize("p", [1, 2, 3, 4])
12+
async def test_parallel_map(p: int) -> None:
13+
input = [1, 2, 3]
14+
async with parallel_map(input, identity, parallelism=p) as mapped:
15+
values = [x async for x in mapped]
16+
assert values == input
17+
18+
19+
@pytest.mark.parametrize("p", [1, 2, 3, 4])
20+
async def test_worker_map(p: int) -> None:
21+
work = WorkContext(parallelism=p)
22+
23+
input = range(1000)
24+
25+
i = 0
26+
async with aclosing(work.map(input, identity)) as mapped:
27+
async for x in mapped:
28+
assert input[i] == x
29+
i += 1

0 commit comments

Comments
 (0)