Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --verbose flag to test-e2e.py #45

Merged
merged 1 commit into from
Mar 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions tools/test-e2e.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python

from argparse import ArgumentParser
from argparse import ArgumentParser, BooleanOptionalAction
import re
import os
from subprocess import run
import sys
import textwrap
import time


Expand All @@ -28,7 +29,7 @@ def extract_text(image_path: str) -> str:
IMAGE_PAT = "\\.(jpeg|jpg|png|webp)$"


def run_tests(test_case_dir: str) -> bool:
def run_tests(test_case_dir: str, *, verbose=False) -> bool:
"""
Compare extracted text for image files against expectations.

Expand Down Expand Up @@ -60,9 +61,16 @@ def run_tests(test_case_dir: str) -> bool:
text = text.strip()

if text != expected_text:
print(f"Actual vs expected mismatch for {fname}")
errors += 1

print(f"Actual vs expected mismatch for {fname}")

if verbose:
print("Actual:")
print(textwrap.indent(text, " "))
print("Expected:")
print(textwrap.indent(expected_text, " "))

if errors != 0:
print(f"{errors} tests failed")

Expand All @@ -78,11 +86,14 @@ def run_tests(test_case_dir: str) -> bool:
"""
)
parser.add_argument("dir", help="Directory containing test images and expected outputs")
parser.add_argument(
"-v", "--verbose", action=BooleanOptionalAction, help="Enable verbose logging"
)
args = parser.parse_args()

print("Building ocrs...")
build_ocrs()
passed = run_tests(args.dir)
passed = run_tests(args.dir, verbose=args.verbose)

if not passed:
sys.exit(1)
Loading