@@ -16,7 +16,10 @@ def render_page_to_image(pdf_path: Path, page_num: int, dpi: int) -> Image.Image
1616
1717
1818def compare_images (
19- ref_img : Image .Image , actual_img : Image .Image , threshold : float , output_path : Path
19+ ref_img : Image .Image ,
20+ actual_img : Image .Image ,
21+ threshold : float ,
22+ output_path : Path | None ,
2023) -> bool :
2124 mismatch_count = pixelmatch (
2225 ref_img , actual_img , diff_path = output_path , threshold = threshold
@@ -29,11 +32,12 @@ def compare_images(
2932
3033
3134def check_visual_content (
32- ref : Path , actual : Path , threshold : float , dpi : int , output_dir : Path , logger
35+ ref : Path , actual : Path , threshold : float , dpi : int , output_dir : Path | None , logger
3336) -> None :
3437 logger .info ("[4/4] Checking visual content..." )
3538
36- output_dir .mkdir (parents = True , exist_ok = True )
39+ if output_dir is not None :
40+ output_dir .mkdir (parents = True , exist_ok = True )
3741
3842 ref_doc = fitz .open (ref )
3943 page_count = len (ref_doc )
@@ -45,11 +49,13 @@ def check_visual_content(
4549 ref_img = render_page_to_image (ref , page_num , dpi )
4650 actual_img = render_page_to_image (actual , page_num , dpi )
4751
48- ref_name = ref .stem
49- actual_name = actual .stem
50- output_path = (
51- output_dir / f"{ ref_name } _vs_{ actual_name } _page{ page_num + 1 } _diff.png"
52- )
52+ output_path = None
53+ if output_dir is not None :
54+ ref_name = ref .stem
55+ actual_name = actual .stem
56+ output_path = (
57+ output_dir / f"{ ref_name } _vs_{ actual_name } _page{ page_num + 1 } _diff.png"
58+ )
5359
5460 passed = compare_images (ref_img , actual_img , threshold , output_path )
5561
0 commit comments