Download ocr-tech/tests/test_admit_page_reading_order_profile_application.py from prosperious/ocr-projects-archive: direct link, hf CLI and curl.
- Browser
- Download file 6.96 kB
-
https://huggingface.co/prosperious/ocr-projects-archive/resolve/main/ocr-tech/tests/test_admit_page_reading_order_profile_application.py
- Command line
-
hf download hf://prosperious/ocr-projects-archive/ocr-tech/tests/test_admit_page_reading_order_profile_application.py
-
curl -L -o test_admit_page_reading_order_profile_application.py https://huggingface.co/prosperious/ocr-projects-archive/resolve/main/ocr-tech/tests/test_admit_page_reading_order_profile_application.py
6.96 kB
| from __future__ import annotations | |
| import importlib.util | |
| import json | |
| import sys | |
| from argparse import Namespace | |
| from pathlib import Path | |
| def _load_tool(): | |
| path = Path(__file__).resolve().parents[1] / "tools" / "admit_page_reading_order_profile_application.py" | |
| spec = importlib.util.spec_from_file_location("admit_page_reading_order_profile_application", path) | |
| assert spec is not None | |
| assert spec.loader is not None | |
| module = importlib.util.module_from_spec(spec) | |
| sys.modules[spec.name] = module | |
| spec.loader.exec_module(module) | |
| return module | |
| def _write_json(path: Path, payload: dict) -> None: | |
| path.parent.mkdir(parents=True, exist_ok=True) | |
| path.write_text(json.dumps(payload, ensure_ascii=False, indent=2) + "\n", encoding="utf-8") | |
| def test_admit_page_reading_order_profile_application_accepts_safe_evidence(tmp_path: Path) -> None: | |
| tool = _load_tool() | |
| score_dir = tmp_path / "score" | |
| metrics = score_dir / "metrics.json" | |
| _write_json(metrics, {"text_cer_codepoint_micro": 0.1}) | |
| metrics_sha = tool.sha256_file(metrics) | |
| profile_audit = tmp_path / "profile-audit.json" | |
| profile_application = tmp_path / "profile-application.json" | |
| effect_audit = tmp_path / "effect-audit.json" | |
| _write_json( | |
| profile_audit, | |
| { | |
| "audit_passed": True, | |
| "operational_profile_safe": True, | |
| "profile_claim_safe": True, | |
| "profile_sha256": "profile-sha", | |
| }, | |
| ) | |
| _write_json( | |
| profile_application, | |
| { | |
| "profile_sha256": "profile-sha", | |
| "profile_claim_safe": True, | |
| "assignment_count": 10, | |
| }, | |
| ) | |
| _write_json( | |
| effect_audit, | |
| { | |
| "book_ocr_objective_safe": True, | |
| "issues": [], | |
| "candidate_score_dir": str(score_dir), | |
| "candidate_metrics_sha256": metrics_sha, | |
| }, | |
| ) | |
| report = tool.admit_application( | |
| Namespace( | |
| profile_audit=profile_audit, | |
| profile_map_audit=None, | |
| profile_application_report=profile_application, | |
| effect_audit=effect_audit, | |
| out=tmp_path / "admission", | |
| ) | |
| ) | |
| assert report["admitted_operational"] is True | |
| assert report["issues"] == [] | |
| def test_admit_page_reading_order_profile_application_rejects_pending_profile(tmp_path: Path) -> None: | |
| tool = _load_tool() | |
| profile_audit = tmp_path / "profile-audit.json" | |
| profile_application = tmp_path / "profile-application.json" | |
| effect_audit = tmp_path / "effect-audit.json" | |
| _write_json( | |
| profile_audit, | |
| { | |
| "audit_passed": True, | |
| "operational_profile_safe": False, | |
| "profile_claim_safe": False, | |
| "profile_sha256": "profile-sha", | |
| }, | |
| ) | |
| _write_json( | |
| profile_application, | |
| { | |
| "profile_sha256": "profile-sha", | |
| "profile_claim_safe": False, | |
| "assignment_count": 10, | |
| }, | |
| ) | |
| _write_json(effect_audit, {"book_ocr_objective_safe": True, "issues": []}) | |
| report = tool.admit_application( | |
| Namespace( | |
| profile_audit=profile_audit, | |
| profile_map_audit=None, | |
| profile_application_report=profile_application, | |
| effect_audit=effect_audit, | |
| out=tmp_path / "admission", | |
| ) | |
| ) | |
| assert report["admitted_operational"] is False | |
| assert any("profile audit does not mark operational_profile_safe=true" in issue for issue in report["issues"]) | |
| assert "profile application usage row 1 was not run with a claim-safe profile" in report["issues"] | |
| def test_admit_page_reading_order_profile_application_accepts_multiple_profile_audits(tmp_path: Path) -> None: | |
| tool = _load_tool() | |
| score_dir = tmp_path / "score" | |
| metrics = score_dir / "metrics.json" | |
| _write_json(metrics, {"text_cer_codepoint_micro": 0.1}) | |
| metrics_sha = tool.sha256_file(metrics) | |
| first_audit = tmp_path / "first-profile-audit.json" | |
| second_audit = tmp_path / "second-profile-audit.json" | |
| profile_application = tmp_path / "profile-application.json" | |
| effect_audit = tmp_path / "effect-audit.json" | |
| _write_json( | |
| first_audit, | |
| { | |
| "audit_passed": True, | |
| "operational_profile_safe": True, | |
| "profile_claim_safe": True, | |
| "profile_sha256": "first-sha", | |
| }, | |
| ) | |
| _write_json( | |
| second_audit, | |
| { | |
| "audit_passed": True, | |
| "operational_profile_safe": True, | |
| "profile_claim_safe": True, | |
| "profile_sha256": "second-sha", | |
| }, | |
| ) | |
| _write_json( | |
| profile_application, | |
| { | |
| "profile_usage": [ | |
| {"profile_sha256": "first-sha", "profile_claim_safe": True, "sample_ids": ["a"]}, | |
| {"profile_sha256": "second-sha", "profile_claim_safe": True, "sample_ids": ["b"]}, | |
| ], | |
| "assignment_count": 20, | |
| }, | |
| ) | |
| _write_json( | |
| effect_audit, | |
| { | |
| "book_ocr_objective_safe": True, | |
| "issues": [], | |
| "candidate_score_dir": str(score_dir), | |
| "candidate_metrics_sha256": metrics_sha, | |
| }, | |
| ) | |
| report = tool.admit_application( | |
| Namespace( | |
| profile_audit=[first_audit, second_audit], | |
| profile_map_audit=None, | |
| profile_application_report=profile_application, | |
| effect_audit=effect_audit, | |
| out=tmp_path / "admission", | |
| ) | |
| ) | |
| assert report["admitted_operational"] is True | |
| assert len(report["profile_audits"]) == 2 | |
| def test_admit_page_reading_order_profile_application_requires_profile_map_audit(tmp_path: Path) -> None: | |
| tool = _load_tool() | |
| profile_audit = tmp_path / "profile-audit.json" | |
| profile_application = tmp_path / "profile-application.json" | |
| effect_audit = tmp_path / "effect-audit.json" | |
| _write_json( | |
| profile_audit, | |
| { | |
| "audit_passed": True, | |
| "operational_profile_safe": True, | |
| "profile_claim_safe": True, | |
| "profile_sha256": "profile-sha", | |
| }, | |
| ) | |
| _write_json( | |
| profile_application, | |
| { | |
| "profile_map_sha256": "map-sha", | |
| "profile_usage": [{"profile_sha256": "profile-sha", "profile_claim_safe": True}], | |
| "assignment_count": 10, | |
| }, | |
| ) | |
| _write_json(effect_audit, {"book_ocr_objective_safe": True, "issues": []}) | |
| report = tool.admit_application( | |
| Namespace( | |
| profile_audit=[profile_audit], | |
| profile_map_audit=None, | |
| profile_application_report=profile_application, | |
| effect_audit=effect_audit, | |
| out=tmp_path / "admission", | |
| ) | |
| ) | |
| assert report["admitted_operational"] is False | |
| assert "profile application used a profile map but no --profile-map-audit was supplied" in report["issues"] | |