From 7d21b0a5855201369427abf0ab4b3c954ceaa98d Mon Sep 17 00:00:00 2001 From: Matthias Bisping Date: Sat, 26 Mar 2022 19:54:18 +0100 Subject: [PATCH] refactoring --- test/unit_tests/preprocessor_test.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/test/unit_tests/preprocessor_test.py b/test/unit_tests/preprocessor_test.py index 562e7e6..3432819 100644 --- a/test/unit_tests/preprocessor_test.py +++ b/test/unit_tests/preprocessor_test.py @@ -5,22 +5,25 @@ from image_prediction.estimator.preprocessor.preprocessors.tensor_conversion imp from image_prediction.estimator.preprocessor.utils import image_to_normalized_tensor, images_to_batch_tensor +def image_conversion_is_correct(image): + tensor = image_to_normalized_tensor(image) + image_re = Image.fromarray(np.uint8(tensor * 255), mode="RGB") + return image == image_re and tensor.ndim == 3 + + +def images_conversion_is_correct(images, tensor): + return all([isinstance(tensor, np.ndarray), tensor.ndim == 4, tensor.shape[0] == len(images)]) + + def test_image_to_tensor(images): - - def inner(image): - tensor = image_to_normalized_tensor(image) - image_re = Image.fromarray(np.uint8(tensor * 255), mode="RGB") - return image == image_re and tensor.ndim == 3 - - assert all(map(inner, images)) + assert all(map(image_conversion_is_correct, images)) def test_images_to_batch_tensor(images): tensor = images_to_batch_tensor(images) - assert isinstance(tensor, np.ndarray) - assert tensor.ndim == 4 + assert images_conversion_is_correct(images, tensor) def test_basic_preprocessor(images): - tensor = BasicPreprocessor().preprocess(images) - assert tensor.ndim == 4 + tensor = BasicPreprocessor()(images) + assert images_conversion_is_correct(images, tensor)