Add dvc-data-pull fixture

This allows the tests that depend on input files to run without the need
to manuallt dvc-pull them beforehand.
This commit is contained in:
Matthias Bisping 2023-01-03 10:01:00 +01:00
parent fcb2786697
commit 04f100386d
4 changed files with 57 additions and 2 deletions

9
cv_analysis/locations.py Normal file
View File

@ -0,0 +1,9 @@
"""Defines constant paths relative to a root path."""
from pathlib import Path
MODULE_PATH = Path(__file__).resolve().parents[0]
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"

36
poetry.lock generated
View File

@ -1114,6 +1114,21 @@ sqs = ["boto3 (>=1.9.12)", "pycurl (>=7.44.1,<7.45.0)", "urllib3 (>=1.26.7)"]
yaml = ["PyYAML (>=3.10)"]
zookeeper = ["kazoo (>=1.3.1)"]
[[package]]
name = "loguru"
version = "0.6.0"
description = "Python logging made (stupidly) simple"
category = "main"
optional = false
python-versions = ">=3.5"
[package.dependencies]
colorama = {version = ">=0.3.4", markers = "sys_platform == \"win32\""}
win32-setctime = {version = ">=1.0.0", markers = "sys_platform == \"win32\""}
[package.extras]
dev = ["Sphinx (>=4.1.1)", "black (>=19.10b0)", "colorama (>=0.3.4)", "docutils (==0.16)", "flake8 (>=3.7.7)", "isort (>=5.1.1)", "pytest (>=4.6.2)", "pytest-cov (>=2.7.1)", "sphinx-autobuild (>=0.7.1)", "sphinx-rtd-theme (>=0.4.3)", "tox (>=3.9.0)"]
[[package]]
name = "lorem-text"
version = "2.1"
@ -1971,6 +1986,17 @@ MarkupSafe = ">=2.1.1"
[package.extras]
watchdog = ["watchdog"]
[[package]]
name = "win32-setctime"
version = "1.1.0"
description = "A small Python utility to set file creation time on Windows"
category = "main"
optional = false
python-versions = ">=3.5"
[package.extras]
dev = ["black (>=19.3b0)", "pytest (>=4.6.2)"]
[[package]]
name = "wrapt"
version = "1.14.1"
@ -2020,7 +2046,7 @@ testing = ["flake8 (<5)", "func-timeout", "jaraco.functools", "jaraco.itertools"
[metadata]
lock-version = "1.1"
python-versions = "~3.8"
content-hash = "0aaec0b423f117c8a01eba279d75becf88983f0a8f93bf8d2f2b4eaa6646c68b"
content-hash = "9899b1f28ed2409e7be40e1a161be917cb7a862a553f4de42697affb3d1ce4dc"
[metadata.files]
aiohttp = [
@ -2860,6 +2886,10 @@ kombu = [
{file = "kombu-5.2.4-py3-none-any.whl", hash = "sha256:8b213b24293d3417bcf0d2f5537b7f756079e3ea232a8386dcc89a59fd2361a4"},
{file = "kombu-5.2.4.tar.gz", hash = "sha256:37cee3ee725f94ea8bb173eaab7c1760203ea53bbebae226328600f9d2799610"},
]
loguru = [
{file = "loguru-0.6.0-py3-none-any.whl", hash = "sha256:4e2414d534a2ab57573365b3e6d0234dfb1d84b68b7f3b948e6fb743860a77c3"},
{file = "loguru-0.6.0.tar.gz", hash = "sha256:066bd06758d0a513e9836fd9c6b5a75bfb3fd36841f4b996bc60b547a309d41c"},
]
lorem-text = [
{file = "lorem_text-2.1-py2.py3-none-any.whl", hash = "sha256:b512779addd08dcc221460ce428f7911b198f66c5763410f3de6d788eb62ceb3"},
{file = "lorem_text-2.1.tar.gz", hash = "sha256:b984b5570295084012f5a9385672bab3470965c943b73d8d71a6efcd7a62b5c3"},
@ -3522,6 +3552,10 @@ werkzeug = [
{file = "Werkzeug-2.2.2-py3-none-any.whl", hash = "sha256:f979ab81f58d7318e064e99c4506445d60135ac5cd2e177a2de0089bfd4c9bd5"},
{file = "Werkzeug-2.2.2.tar.gz", hash = "sha256:7ea2d48322cc7c0f8b3a215ed73eabd7b5d75d0b50e31ab006286ccff9e00b8f"},
]
win32-setctime = [
{file = "win32_setctime-1.1.0-py3-none-any.whl", hash = "sha256:231db239e959c2fe7eb1d7dc129f11172354f98361c4fa2d6d2d7e278baa8aad"},
{file = "win32_setctime-1.1.0.tar.gz", hash = "sha256:15cf5750465118d6929ae4de4eb46e8edae9a5634350c01ba582df868e932cb2"},
]
wrapt = [
{file = "wrapt-1.14.1-cp27-cp27m-macosx_10_9_x86_64.whl", hash = "sha256:1b376b3f4896e7930f1f772ac4b064ac12598d1c38d04907e696cc4d794b43d3"},
{file = "wrapt-1.14.1-cp27-cp27m-manylinux1_i686.whl", hash = "sha256:903500616422a40a98a5a3c4ff4ed9d0066f3b4c951fa286018ecdf0750194ef"},

View File

@ -30,6 +30,7 @@ PyMuPDF = "^1.19.6"
pdf2img = {git = "ssh://git@git.iqser.com:2222/rr/pdf2image.git", branch = "master"}
pyinfra = {git = "ssh://git@git.iqser.com:2222/rr/pyinfra.git", branch = "master"}
loguru = "^0.6.0"
[tool.poetry.group.build.dependencies]
pytest = "^7.0.1"

View File

@ -3,9 +3,12 @@ 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.draw import draw_rectangles
from cv_analysis.utils.open_pdf import open_pdf
from test.fixtures.figure_detection import paste_text
@ -14,11 +17,19 @@ CV_CONFIG = get_config()
@pytest.fixture
def client_page_with_table(test_file_index):
def client_page_with_table(test_file_index, dvc_test_data):
img_path = join(CV_CONFIG.test_data_dir, f"test{test_file_index}.png")
return first(open_pdf(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")