From 128b325c0df1dbb1a836e43dcab462117553ab7e Mon Sep 17 00:00:00 2001 From: Matthias Bisping Date: Thu, 14 Apr 2022 18:26:25 +0200 Subject: [PATCH] refactoring: splitting conftest logic into submodules --- test/conftest.py | 34 ++-------------------------------- test/fixtures/image.py | 36 ++++++++++++++++++++++++++++++++++++ test/fixtures/parameters.py | 0 3 files changed, 38 insertions(+), 32 deletions(-) create mode 100644 test/fixtures/parameters.py diff --git a/test/conftest.py b/test/conftest.py index 582a3db..af16f30 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -21,12 +21,13 @@ from image_prediction.label_mapper.mappers.probability import ProbabilityMapper, from image_prediction.locations import TEST_DATA_DIR from image_prediction.pipeline import load_pipeline from image_prediction.utils import get_logger -from test.utils.generation.image import array_to_image from test.utils.generation.pdf import add_image, pdf_stream pytest_plugins = [ 'test.fixtures.model', 'test.fixtures.model_store', + 'test.fixtures.image', + 'test.fixtures.input', ] @@ -77,11 +78,6 @@ def expected_predictions(label_format, batch_of_expected_numeric_labels, batch_o raise UnknownLabelFormat(f"No label mapper for label format {label_format} was specified.") -@pytest.fixture -def images(input_batch): - return list(map(array_to_image, input_batch)) - - @pytest.fixture def input_batch(batch_size, input_size): return np.random.random_sample(size=(batch_size, *input_size)) @@ -92,22 +88,6 @@ def batch_size(request): return request.param -@pytest.fixture -def input_size(alpha, __input_size): - w, h, d = __input_size - return w, h, d + alpha - - -@pytest.fixture(params=[False]) -def alpha(request): - return request.param - - -@pytest.fixture(params=[{"width": 10, "height": 15, "depth": 3}, {"width": 150, "height": 100, "depth": 3}]) -def __input_size(request): - return itemgetter("width", "height", "depth")(request.param) - - @pytest.fixture def batch_of_expected_string_labels(batch_of_expected_numeric_labels, classes): return map_labels(batch_of_expected_numeric_labels, classes) @@ -263,16 +243,6 @@ def base_patch_metadata(width, height, page_width, page_height): return metadata -@pytest.fixture(params=[33, 100]) -def height(request): - return request.param - - -@pytest.fixture(params=[10, 31]) -def width(request): - return request.param - - @pytest.fixture(params=[220, 30]) def page_height(request): return request.param diff --git a/test/fixtures/image.py b/test/fixtures/image.py index e69de29..e066657 100644 --- a/test/fixtures/image.py +++ b/test/fixtures/image.py @@ -0,0 +1,36 @@ +from operator import itemgetter + +import pytest + +from test.utils.generation.image import array_to_image + + +@pytest.fixture +def images(input_batch): + return list(map(array_to_image, input_batch)) + + +@pytest.fixture +def input_size(alpha, __input_size): + w, h, d = __input_size + return w, h, d + alpha + + +@pytest.fixture(params=[False]) +def alpha(request): + return request.param + + +@pytest.fixture(params=[{"width": 10, "height": 15, "depth": 3}, {"width": 150, "height": 100, "depth": 3}]) +def __input_size(request): + return itemgetter("width", "height", "depth")(request.param) + + +@pytest.fixture(params=[33, 100]) +def height(request): + return request.param + + +@pytest.fixture(params=[10, 31]) +def width(request): + return request.param \ No newline at end of file diff --git a/test/fixtures/parameters.py b/test/fixtures/parameters.py new file mode 100644 index 0000000..e69de29