From 0f6e87b8a6784c1e165b54f9e7d6b6a45e4293eb Mon Sep 17 00:00:00 2001 From: Matthias Bisping Date: Wed, 15 Feb 2023 10:42:01 +0100 Subject: [PATCH] Refactoring Move DVC fixture into data fixture module --- cv_analysis/locations.py | 5 +++-- synthesis/segment/plot.py | 5 +++-- test/.gitignore | 1 + test/conftest.py | 1 + test/data.dvc | 5 +++++ test/fixtures/data.py | 13 +++++++++++++ test/fixtures/table_parsing.py | 10 ---------- 7 files changed, 26 insertions(+), 14 deletions(-) create mode 100644 test/data.dvc create mode 100644 test/fixtures/data.py diff --git a/cv_analysis/locations.py b/cv_analysis/locations.py index 27dc749..34d36c2 100644 --- a/cv_analysis/locations.py +++ b/cv_analysis/locations.py @@ -7,6 +7,7 @@ PACKAGE_ROOT_PATH = MODULE_PATH.parents[0] REPO_ROOT_PATH = PACKAGE_ROOT_PATH TEST_DIR_PATH = REPO_ROOT_PATH / "test" -TEST_DATA_DVC = TEST_DIR_PATH / "test_data.dvc" # TODO: remove once new tests are in place TEST_DATA_DIR = TEST_DIR_PATH / "data" -TEST_PAGE_TEXTURES_DIR = TEST_DATA_DIR / "paper" +TEST_DATA_DIR_DVC = TEST_DIR_PATH / "data.dvc" +TEST_DATA_SYNTHESIS_DIR = TEST_DATA_DIR / "synthesis" +TEST_PAGE_TEXTURES_DIR = TEST_DATA_SYNTHESIS_DIR / "paper" diff --git a/synthesis/segment/plot.py b/synthesis/segment/plot.py index 314b877..3cb4570 100644 --- a/synthesis/segment/plot.py +++ b/synthesis/segment/plot.py @@ -130,9 +130,10 @@ class RandomPlot(RandomContentRectangle): def generate_random_heat_map(self, rectangle: Rectangle): n = random.randint(3, 7) - x = np.random.uniform(size=(n, n)) + m = random.randint(3, 7) + x = np.random.uniform(size=(n, m)) heat_map_fn = lambda x, y: plt.imshow(x, interpolation="nearest") - ax, fig = self.__generate_random_plot( + self.__generate_random_plot( heat_map_fn, rectangle, x, diff --git a/test/.gitignore b/test/.gitignore index 81a860e..9100bb4 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -1 +1,2 @@ /test_data +/data diff --git a/test/conftest.py b/test/conftest.py index aaf9432..a068821 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -5,6 +5,7 @@ warnings.filterwarnings("ignore", category=DeprecationWarning) pytest_plugins = [ "test.fixtures.table_parsing", "test.fixtures.figure_detection", + "test.fixtures.data", "test.fixtures.page_generation.page", ] diff --git a/test/data.dvc b/test/data.dvc new file mode 100644 index 0000000..9d4436f --- /dev/null +++ b/test/data.dvc @@ -0,0 +1,5 @@ +outs: +- md5: 4e22cc1a7655987683215d4a4677d645.dir + size: 25117769 + nfiles: 6 + path: data diff --git a/test/fixtures/data.py b/test/fixtures/data.py new file mode 100644 index 0000000..597f1b3 --- /dev/null +++ b/test/fixtures/data.py @@ -0,0 +1,13 @@ +import pytest +from dvc.repo import Repo +from loguru import logger + +from cv_analysis.locations import REPO_ROOT_PATH, TEST_DATA_DIR_DVC + + +@pytest.fixture(scope="session") +def dvc_test_data(): + # noinspection PyCallingNonCallable + logger.info("Pulling data with DVC...") + Repo(REPO_ROOT_PATH).pull(targets=[str(TEST_DATA_DIR_DVC)]) + logger.info("Finished pulling data.") diff --git a/test/fixtures/table_parsing.py b/test/fixtures/table_parsing.py index d9e8ada..5563a74 100644 --- a/test/fixtures/table_parsing.py +++ b/test/fixtures/table_parsing.py @@ -3,12 +3,10 @@ from os.path import join import cv2 import pytest -from dvc.repo import Repo from funcy import first from loguru import logger from cv_analysis.config import get_config -from cv_analysis.locations import REPO_ROOT_PATH, TEST_DATA_DVC from cv_analysis.utils.drawing import draw_rectangles from cv_analysis.utils.input import open_analysis_input_file from test.fixtures.figure_detection import paste_text @@ -22,14 +20,6 @@ def client_page_with_table(test_file_index, dvc_test_data): return first(open_analysis_input_file(img_path)) -@pytest.fixture(scope="session") -def dvc_test_data(): - # noinspection PyCallingNonCallable - logger.info("Pulling data with DVC...") - Repo(REPO_ROOT_PATH).pull(targets=[str(TEST_DATA_DVC)]) - logger.info("Finished pulling data.") - - @pytest.fixture def expected_table_annotation(test_file_index): json_path = join(CV_CONFIG.test_data_dir, f"test{test_file_index}.json")