From 6343229c1e682acad43a5f0bf81b35c1c4f79a09 Mon Sep 17 00:00:00 2001 From: Matthias Bisping Date: Sat, 26 Mar 2022 20:24:59 +0100 Subject: [PATCH] added chunk_iterable tests --- test/unit_tests/predictor_test.py | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 test/unit_tests/predictor_test.py diff --git a/test/unit_tests/predictor_test.py b/test/unit_tests/predictor_test.py new file mode 100644 index 0000000..cdf78cd --- /dev/null +++ b/test/unit_tests/predictor_test.py @@ -0,0 +1,35 @@ +import pytest + +from image_prediction.utils import chunk_iterable + + +# @pytest.mark.parametrize("estimator_type", ["mock", "keras"], scope="session") +# @pytest.mark.parametrize("batch_size", [0, 1, 2, 16, 32, 64], scope="session") +# def test_predict(predictor, images, expected_predictions): +# predictions = list(predictor.predict_images(images)) +# assert predictions == expected_predictions + + +def test_chunk_iterable_exact_split(): + a, b = chunk_iterable(range(10), chunk_size=5) + assert a == tuple(range(5)) + assert b == tuple(range(5, 10)) + + +def test_chunk_iterable_no_split(): + a = next(chunk_iterable(range(10), chunk_size=10)) + assert a == tuple(range(10)) + + +def test_chunk_iterable_last_partial(): + a, b, c, d = chunk_iterable(range(10), chunk_size=3) + assert d == (9, ) + + +def test_chunk_iterable_empty(): + with pytest.raises(StopIteration): + next(chunk_iterable(range(0), chunk_size=3)) + + +def test_chunk_iterable_less_than_chunk_size_elements(): + assert next(chunk_iterable(range(2), chunk_size=5)) == (0, 1)