Fix typing and minor issues
This commit is contained in:
parent
2db2253578
commit
72ab627a34
54 changed files with 635 additions and 589 deletions
|
|
@ -1,11 +1,13 @@
|
|||
import pytest
|
||||
from typing import Any, Iterable
|
||||
|
||||
import pytest
|
||||
from great_ai.utilities import WorkerException, parallel_map
|
||||
from typing_extensions import Never
|
||||
|
||||
COUNT = int(1e5) + 3
|
||||
|
||||
|
||||
def test_simple_case_with_progress_bar() -> None:
|
||||
def test_simple_case() -> None:
|
||||
assert list(parallel_map(lambda v: v**2, range(COUNT), concurrency=4)) == [
|
||||
v**2 for v in range(COUNT)
|
||||
]
|
||||
|
|
@ -14,7 +16,7 @@ def test_simple_case_with_progress_bar() -> None:
|
|||
def test_with_iterable() -> None:
|
||||
from time import sleep
|
||||
|
||||
def my_generator():
|
||||
def my_generator() -> Iterable[int]:
|
||||
for i in range(10):
|
||||
yield i
|
||||
sleep(0.1)
|
||||
|
|
@ -26,12 +28,6 @@ def test_with_iterable() -> None:
|
|||
)
|
||||
|
||||
|
||||
def test_simple_case_without_progress_bar() -> None:
|
||||
assert list(parallel_map(lambda v: v**2, range(COUNT), concurrency=2)) == [
|
||||
v**2 for v in range(COUNT)
|
||||
]
|
||||
|
||||
|
||||
def test_simple_case_invalid_values() -> None:
|
||||
with pytest.raises(AssertionError):
|
||||
list(parallel_map(lambda v: v**2, range(COUNT), concurrency=0))
|
||||
|
|
@ -41,7 +37,7 @@ def test_simple_case_invalid_values() -> None:
|
|||
|
||||
|
||||
def test_this_process_exception() -> None:
|
||||
def my_generator():
|
||||
def my_generator() -> Iterable[int]:
|
||||
yield 1
|
||||
yield 2
|
||||
yield 3
|
||||
|
|
@ -59,7 +55,7 @@ def test_this_process_exception() -> None:
|
|||
|
||||
|
||||
def test_ignore_this_process_exception() -> None:
|
||||
def my_generator():
|
||||
def my_generator() -> Iterable[float]:
|
||||
yield 1
|
||||
yield 2
|
||||
yield 3
|
||||
|
|
@ -74,19 +70,10 @@ def test_ignore_this_process_exception() -> None:
|
|||
ignore_exceptions=True,
|
||||
)
|
||||
) == [1, 4]
|
||||
assert list(
|
||||
parallel_map(
|
||||
lambda v: v**2,
|
||||
my_generator(),
|
||||
concurrency=1,
|
||||
chunk_size=2,
|
||||
ignore_exceptions=True,
|
||||
)
|
||||
) == [1, 4, 9]
|
||||
|
||||
|
||||
def test_worker_process_exception() -> None:
|
||||
def oh_no(_):
|
||||
def oh_no(_: Any) -> Never:
|
||||
raise ValueError("hi")
|
||||
|
||||
with pytest.raises(WorkerException):
|
||||
|
|
@ -97,7 +84,7 @@ def test_worker_process_exception() -> None:
|
|||
|
||||
|
||||
def test_ignore_worker_process_exception() -> None:
|
||||
def oh_no(_):
|
||||
def oh_no(_: Any) -> Never:
|
||||
raise ValueError("hi")
|
||||
|
||||
assert (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue