67 lines
1.4 KiB
Python
67 lines
1.4 KiB
Python
import logging
|
|
import os
|
|
|
|
import fpdf
|
|
import numpy as np
|
|
import pytest
|
|
|
|
from image_prediction.info import Info
|
|
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.pdf import add_image, pdf_stream
|
|
|
|
pytest_plugins = [
|
|
"test.fixtures.image",
|
|
"test.fixtures.image_metadata_pair",
|
|
"test.fixtures.input",
|
|
"test.fixtures.label",
|
|
"test.fixtures.metadata",
|
|
"test.fixtures.model",
|
|
"test.fixtures.model_store",
|
|
"test.fixtures.parameters",
|
|
"test.fixtures.pdf",
|
|
"test.fixtures.target",
|
|
]
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def mute_logger():
|
|
logger = get_logger()
|
|
level = logger.level
|
|
logger.setLevel(logging.CRITICAL + 1)
|
|
yield
|
|
logger.setLevel(level)
|
|
|
|
|
|
@pytest.fixture
|
|
def input_batch(batch_size, input_size):
|
|
return np.random.random_sample(size=(batch_size, *input_size))
|
|
|
|
|
|
@pytest.fixture
|
|
def info_label_map():
|
|
return Info
|
|
|
|
|
|
@pytest.fixture
|
|
def pdf(image_metadata_pairs):
|
|
pdf = fpdf.FPDF(unit="pt")
|
|
|
|
for pair in image_metadata_pairs:
|
|
add_image(pdf, pair)
|
|
|
|
return pdf_stream(pdf)
|
|
|
|
|
|
@pytest.fixture
|
|
def real_pdf():
|
|
with open(os.path.join(TEST_DATA_DIR, "f2dc689ca794fccb8cd38b95f2bf6ba9.pdf"), "rb") as f:
|
|
yield f.read()
|
|
|
|
|
|
@pytest.fixture
|
|
def pipeline():
|
|
pipeline = load_pipeline(verbose=False)
|
|
return pipeline
|