|
| 1 | +import json |
| 2 | +import os.path |
| 3 | +import re |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
| 7 | +from ..cli_line_dirs import process |
| 8 | +from .util import working_directory |
| 9 | + |
| 10 | +data_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data") |
| 11 | + |
| 12 | + |
| 13 | +@pytest.mark.integration |
| 14 | +def test_cli_line_dirs_basic(tmp_path): |
| 15 | + """Test that the cli/process() produces a good report""" |
| 16 | + |
| 17 | + with working_directory(tmp_path): |
| 18 | + gt_dir = os.path.join(data_dir, "line_dirs/basic/gt") |
| 19 | + ocr_dir = os.path.join(data_dir, "line_dirs/basic/ocr") |
| 20 | + process(gt_dir, ocr_dir, "report") |
| 21 | + with open("report.json", "r") as jsonf: |
| 22 | + print(jsonf.read()) |
| 23 | + with open("report.json", "r") as jsonf: |
| 24 | + j = json.load(jsonf) |
| 25 | + assert j["cer"] == pytest.approx(0.1071429) |
| 26 | + assert j["wer"] == pytest.approx(0.5) |
| 27 | + |
| 28 | + |
| 29 | +@pytest.mark.integration |
| 30 | +def test_cli_line_dirs_basic_report_diff(tmp_path): |
| 31 | + """Test that the cli/process() produces a report wiff char+word diff""" |
| 32 | + |
| 33 | + with working_directory(tmp_path): |
| 34 | + gt_dir = os.path.join(data_dir, "line_dirs/basic/gt") |
| 35 | + ocr_dir = os.path.join(data_dir, "line_dirs/basic/ocr") |
| 36 | + process(gt_dir, ocr_dir, "report") |
| 37 | + |
| 38 | + with open("report.html", "r") as htmlf: |
| 39 | + html_report = htmlf.read() |
| 40 | + |
| 41 | + # Counting GT lines in the diff |
| 42 | + assert len(re.findall(r"gt.*l\d+-cdiff", html_report)) == 2 |
| 43 | + assert len(re.findall(r"gt.*l\d+-wdiff", html_report)) == 2 |
| 44 | + |
| 45 | + |
| 46 | +@pytest.mark.integration |
| 47 | +def test_cli_line_dirs_merged(tmp_path): |
| 48 | + """Test that the cli/process() produces a good report""" |
| 49 | + |
| 50 | + with working_directory(tmp_path): |
| 51 | + gt_dir = os.path.join(data_dir, "line_dirs/merged") |
| 52 | + ocr_dir = os.path.join(data_dir, "line_dirs/merged") |
| 53 | + process( |
| 54 | + gt_dir, ocr_dir, "report", gt_suffix=".gt.txt", ocr_suffix=".some-ocr.txt" |
| 55 | + ) |
| 56 | + with open("report.json", "r") as jsonf: |
| 57 | + print(jsonf.read()) |
| 58 | + with open("report.json", "r") as jsonf: |
| 59 | + j = json.load(jsonf) |
| 60 | + assert j["cer"] == pytest.approx(0.1071429) |
| 61 | + assert j["wer"] == pytest.approx(0.5) |
0 commit comments