import json import os import pytest from image_prediction.transformer.transformers.response import ( get_class_specific_min_image_to_page_quotient, get_class_specific_max_image_to_page_quotient, get_class_specific_max_image_width_to_height_quotient, get_class_specific_min_image_width_to_height_quotient, get_class_specific_min_classification_confidence, ) @pytest.fixture def label(): return "signature" @pytest.fixture def page_quotient_threshold_map(label): # TODO: suboptimal, as actual environment is used os.environ["REL_IMAGE_SIZE_MAP"] = json.dumps({label: {"min": 0.1, "max": 0.2}}) os.environ["IMAGE_FORMAT_MAP"] = json.dumps({label: {"min": 0.5, "max": 0.4}}) os.environ["CONFIDENCE"] = json.dumps({label: {"min": 0.8}}) yield for env_var in ("REL_IMAGE_SIZE_MAP", "IMAGE_FORMAT_MAP", "CONFIDENCE"): os.environ.pop(env_var) # FIXME: Runs correctly in isolation, but fails when other tests are run before def test_read_environment_vars_for_thresholds(page_quotient_threshold_map, label): assert get_class_specific_min_image_to_page_quotient(label) == 0.1 assert get_class_specific_max_image_to_page_quotient(label) == 0.2 assert get_class_specific_min_image_width_to_height_quotient(label) == 0.5 assert get_class_specific_max_image_width_to_height_quotient(label) == 0.4 assert get_class_specific_min_classification_confidence(label) == 0.8