|
1 | 1 | import typing |
| 2 | +import pytest |
2 | 3 | from src.thread import ParallelProcessing |
3 | 4 |
|
4 | 5 |
|
@@ -39,3 +40,88 @@ class DummyUnlikeSequence2: |
39 | 40 | def __init__(self) -> None: ... |
40 | 41 | def __str__(self) -> str: |
41 | 42 | 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