Skip to content

Commit 5ab1f68

Browse files
test: Add tests for Sequence-Like datasets
Sequence-Like means it has a __len__ and a __getitem__ method Ref: #67
1 parent ca758d4 commit 5ab1f68

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

tests/test_dataframe_compatibility.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,94 @@ def get(*_):
218218
_get_value=get,
219219
)
220220
assert process._retrieve_value == get
221+
222+
223+
# >>>>>>>> Sequence Like <<<<<<<< #
224+
def test_SO_init() -> None:
225+
ParallelProcessing(
226+
function=lambda x: x,
227+
dataset=DummySequenceLike(10, list(range(10))),
228+
)
229+
230+
231+
def test_SO_init_list() -> None:
232+
ParallelProcessing(
233+
function=lambda x: x,
234+
dataset=[1, 2, 3],
235+
)
236+
237+
238+
def test_SO_init_tuple() -> None:
239+
ParallelProcessing(
240+
function=lambda x: x,
241+
dataset=(1, 2, 3),
242+
)
243+
244+
245+
def test_SO_init_set() -> None:
246+
with pytest.raises(TypeError):
247+
ParallelProcessing(
248+
function=lambda x: x,
249+
dataset=set([1, 2, 3]), # type: ignore
250+
)
251+
252+
253+
def test_SO_init_dict() -> None:
254+
ParallelProcessing(
255+
function=lambda x: x,
256+
dataset={1: 1, 2: 2, 3: 3}, # type: ignore
257+
)
258+
259+
260+
def test_SO_init_str() -> None:
261+
ParallelProcessing(
262+
function=lambda x: x,
263+
dataset='123',
264+
)
265+
266+
267+
def test_SO_init_withLength() -> None:
268+
ParallelProcessing(
269+
function=lambda x: x,
270+
dataset=DummySequenceLike(10, list(range(10))),
271+
_length=10,
272+
)
273+
274+
275+
def test_SO_init_withGet() -> None:
276+
ParallelProcessing(
277+
function=lambda x: x,
278+
dataset=DummySequenceLike(10, list(range(10))),
279+
_get_value=lambda *_: _,
280+
)
281+
282+
283+
def test_SO_init_withLengthAndGet() -> None:
284+
ParallelProcessing(
285+
function=lambda x: x,
286+
dataset=DummySequenceLike(10, list(range(10))),
287+
_length=10,
288+
_get_value=lambda *_: _,
289+
)
290+
291+
292+
def test_SO_len() -> None:
293+
process = ParallelProcessing(
294+
function=lambda x: x,
295+
dataset=DummySequenceLike(10, list(range(10))),
296+
)
297+
assert process._length == 10
298+
299+
300+
def test_SO_enforceTypes() -> None:
301+
def validate(x, i):
302+
assert isinstance(x, DummySequenceLike)
303+
assert isinstance(i, int)
304+
305+
process = ParallelProcessing(
306+
function=lambda x: x,
307+
dataset=DummySequenceLike(10, list(range(10))),
308+
_get_value=validate,
309+
)
310+
process.start()
311+
process.join()

0 commit comments

Comments
 (0)