From ce003b0931c98ddf766e1439b1d933a6ab6cb981 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ianar=C3=A9=20S=C3=A9vi?= Date: Fri, 3 Oct 2025 18:04:52 +0200 Subject: [PATCH] :sparkles: allow comparing v2 field confidence --- .github/workflows/_test-integrations.yml | 2 +- .github/workflows/_test-regressions.yml | 2 +- .github/workflows/_test-units.yml | 2 +- mindee/parsing/v2/field/field_confidence.py | 26 +++++++++++++++++++++ pyproject.toml | 2 +- tests/v2/test_inference_response.py | 9 ++++++- 6 files changed, 38 insertions(+), 5 deletions(-) diff --git a/.github/workflows/_test-integrations.yml b/.github/workflows/_test-integrations.yml index d1bdcb8b..d5d6d210 100644 --- a/.github/workflows/_test-integrations.yml +++ b/.github/workflows/_test-integrations.yml @@ -51,7 +51,7 @@ jobs: MINDEE_V2_FINDOC_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID }} MINDEE_V2_SE_TESTS_BLANK_PDF_URL: ${{ secrets.MINDEE_V2_SE_TESTS_BLANK_PDF_URL }} run: | - pytest -m integration + pytest --cov mindee -m integration - name: Notify Slack Action on Failure diff --git a/.github/workflows/_test-regressions.yml b/.github/workflows/_test-regressions.yml index e45a0f74..246d8ff0 100644 --- a/.github/workflows/_test-regressions.yml +++ b/.github/workflows/_test-regressions.yml @@ -47,7 +47,7 @@ jobs: env: MINDEE_API_KEY: ${{ secrets.MINDEE_API_KEY_SE_TESTS }} run: | - pytest -m regression + pytest --cov mindee -m regression - name: Notify Slack Action on Failure uses: ravsamhq/notify-slack-action@2.3.0 diff --git a/.github/workflows/_test-units.yml b/.github/workflows/_test-units.yml index d0915aeb..0ff41b05 100644 --- a/.github/workflows/_test-units.yml +++ b/.github/workflows/_test-units.yml @@ -50,4 +50,4 @@ jobs: env: MINDEE_API_KEY: ${{ secrets.MINDEE_API_KEY_SE_TESTS }} run: | - pytest --cov-fail-under 87 + pytest --cov mindee --cov-fail-under 87 diff --git a/mindee/parsing/v2/field/field_confidence.py b/mindee/parsing/v2/field/field_confidence.py index 0c3bb1b6..4e3ccb84 100644 --- a/mindee/parsing/v2/field/field_confidence.py +++ b/mindee/parsing/v2/field/field_confidence.py @@ -8,3 +8,29 @@ class FieldConfidence(str, Enum): HIGH = "High" MEDIUM = "Medium" LOW = "Low" + + def __int__(self) -> int: + return {"Certain": 4, "High": 3, "Medium": 2, "Low": 1}[self.value] + + def __str__(self) -> str: + return self.value + + def __lt__(self, other) -> bool: + if isinstance(other, FieldConfidence): + return int(self) < int(other) + raise TypeError(f"Cannot compare FieldConfidence with {type(other)}") + + def __le__(self, other) -> bool: + if isinstance(other, FieldConfidence): + return int(self) <= int(other) + raise TypeError(f"Cannot compare FieldConfidence with {type(other)}") + + def __gt__(self, other) -> bool: + if isinstance(other, FieldConfidence): + return int(self) > int(other) + raise TypeError(f"Cannot compare FieldConfidence with {type(other)}") + + def __ge__(self, other) -> bool: + if isinstance(other, FieldConfidence): + return int(self) >= int(other) + raise TypeError(f"Cannot compare FieldConfidence with {type(other)}") diff --git a/pyproject.toml b/pyproject.toml index 009323a1..159b0072 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -120,7 +120,7 @@ safe_licenses = [ [tool.pytest.ini_options] -addopts = "--pyargs --cov mindee --cov-report term:skip-covered --cov-report term-missing -m 'not regression and not integration'" +addopts = "--pyargs --cov-report term:skip-covered --cov-report term-missing -m 'not regression and not integration'" python_files = "test*.py" junit_family = "xunit2" markers = [ diff --git a/tests/v2/test_inference_response.py b/tests/v2/test_inference_response.py index c5829dec..e305d9e6 100644 --- a/tests/v2/test_inference_response.py +++ b/tests/v2/test_inference_response.py @@ -268,5 +268,12 @@ def test_field_locations_and_confidence() -> None: assert polygon[3][0] == 0.948849 assert polygon[3][1] == 0.244565 + assert str(date_field.confidence) == "Medium" + assert int(date_field.confidence) == 2 assert date_field.confidence == FieldConfidence.MEDIUM - assert str(date_field.confidence.value) == "Medium" + assert date_field.confidence >= FieldConfidence.MEDIUM + assert date_field.confidence <= FieldConfidence.MEDIUM + assert date_field.confidence >= FieldConfidence.LOW + assert date_field.confidence > FieldConfidence.LOW + assert date_field.confidence <= FieldConfidence.HIGH + assert date_field.confidence < FieldConfidence.HIGH