Skip to content

Commit 2ce9922

Browse files
test: Add tests for datasets with only __len__
1 parent 818ec36 commit 2ce9922

1 file changed

Lines changed: 86 additions & 0 deletions

File tree

tests/test_dataframe_compatibility.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import typing
2+
import pytest
23
from src.thread import ParallelProcessing
34

45

@@ -39,3 +40,88 @@ class DummyUnlikeSequence2:
3940
def __init__(self) -> None: ...
4041
def __str__(self) -> str:
4142
return 'invalid'
43+
44+
45+
# >>>>>>>>>> Length Only <<<<<<<<<< #
46+
def test_LO_init() -> None:
47+
ParallelProcessing(
48+
function=lambda x: x,
49+
dataset=DummyLengthOnly(10),
50+
_get_value=lambda *_: _,
51+
)
52+
53+
54+
def test_LO_init_missingGetValueError_nothing() -> None:
55+
with pytest.raises(AssertionError):
56+
ParallelProcessing(
57+
function=lambda x: x,
58+
dataset=DummyLengthOnly(10), # type: ignore
59+
)
60+
61+
62+
def test_LO_init_missingGetValueError_lengthNum() -> None:
63+
with pytest.raises(AssertionError):
64+
ParallelProcessing(
65+
function=lambda x: x,
66+
dataset=DummyLengthOnly(10), # type: ignore
67+
_length=1,
68+
)
69+
70+
71+
def test_LO_init_missingGetValueError_lengthFunc() -> None:
72+
with pytest.raises(AssertionError):
73+
ParallelProcessing(
74+
function=lambda x: x,
75+
dataset=DummyLengthOnly(10), # type: ignore
76+
_length=lambda _: 1,
77+
)
78+
79+
80+
def test_LO_init_invalidLengthValueError() -> None:
81+
with pytest.raises(ValueError):
82+
ParallelProcessing(
83+
function=lambda x: x,
84+
dataset=DummyLengthOnly(-10),
85+
_get_value=lambda *_: _,
86+
)
87+
88+
89+
def test_LO_init_nonIntLengthError_numLike() -> None:
90+
with pytest.raises(TypeError):
91+
ParallelProcessing(
92+
function=lambda x: x,
93+
dataset=DummyLengthOnly(10.5),
94+
_get_value=lambda *_: _,
95+
)
96+
97+
98+
def test_LO_init_nonIntLengthError() -> None:
99+
with pytest.raises(TypeError):
100+
ParallelProcessing(
101+
function=lambda x: x,
102+
dataset=DummyLengthOnly('10'),
103+
_get_value=lambda *_: _,
104+
)
105+
106+
107+
def test_LO_enforceTypes() -> None:
108+
def validate(x, i):
109+
assert isinstance(x, DummyLengthOnly)
110+
assert isinstance(i, int)
111+
112+
process = ParallelProcessing(
113+
function=lambda x: x,
114+
dataset=DummyLengthOnly(10),
115+
_get_value=validate,
116+
)
117+
process.start()
118+
process.join()
119+
120+
121+
def test_LO_len() -> None:
122+
process = ParallelProcessing(
123+
function=lambda x: x,
124+
dataset=DummyLengthOnly(10),
125+
_get_value=lambda *_: _,
126+
)
127+
assert process._length == 10

0 commit comments

Comments
 (0)