import json import pytest from frozendict import frozendict 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): return frozendict( { "REL_IMAGE_SIZE": json.dumps({label: {"min": 0.1, "max": 0.2}}), "IMAGE_FORMAT": json.dumps({label: {"min": 0.5, "max": 0.4}}), "CONFIDENCE": json.dumps({label: {"min": 0.8}}), } ) def test_read_environment_vars_for_thresholds(page_quotient_threshold_map, label): assert get_class_specific_min_image_to_page_quotient(label, table=page_quotient_threshold_map) == 0.1 assert get_class_specific_max_image_to_page_quotient(label, table=page_quotient_threshold_map) == 0.2 assert get_class_specific_min_image_width_to_height_quotient(label, table=page_quotient_threshold_map) == 0.5 assert get_class_specific_max_image_width_to_height_quotient(label, table=page_quotient_threshold_map) == 0.4 assert get_class_specific_min_classification_confidence(label, table=page_quotient_threshold_map) == 0.8