From f5c3537ff7e1d1d6e72a2a6ee2d99fbfc6bf8f63 Mon Sep 17 00:00:00 2001 From: Yonghye Kwon Date: Fri, 4 Sep 2026 10:12:19 +0700 Subject: [PATCH] fix(ci): parse scientific AE metrics Signed-off-by: Yonghye Kwon --- scripts/check_visual_pr.py | 7 +++++-- scripts/tests/test_check_visual_pr.py | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/scripts/check_visual_pr.py b/scripts/check_visual_pr.py index 5a49d96d..5a14f9b0 100644 --- a/scripts/check_visual_pr.py +++ b/scripts/check_visual_pr.py @@ -534,11 +534,14 @@ def decoded_pixel_delta(before: Path, after: Path) -> int: text=True, ) metric_output = result.stderr.strip() or result.stdout.strip() - metric_match = re.search(r"(?:^|\s)(\d+)(?:\s|$)", metric_output) + metric_match = re.search( + r"(?:^|\s)(\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)(?:\s|$)", + metric_output, + ) if result.returncode not in {0, 1} or not metric_match: detail = metric_output or f"exit status {result.returncode}" raise RuntimeError(f"ImageMagick could not compare the evidence: {detail}") - return int(metric_match.group(1)) + return int(float(metric_match.group(1))) def validate_reference_exporter_differences( diff --git a/scripts/tests/test_check_visual_pr.py b/scripts/tests/test_check_visual_pr.py index 0f55a86e..70c7ce29 100644 --- a/scripts/tests/test_check_visual_pr.py +++ b/scripts/tests/test_check_visual_pr.py @@ -11,6 +11,7 @@ from scripts.check_visual_pr import ( AUDIT_ROWS, INSPECTION_ITEMS, + decoded_pixel_delta, read_jpeg_info, validate_evidence, validate_layout_audit, @@ -466,6 +467,19 @@ def test_native_evidence_cannot_be_added_without_a_difference_report(self): class ReferenceExporterDifferenceTests(unittest.TestCase): + def test_decoded_pixel_delta_accepts_scientific_notation(self): + with ( + patch("scripts.check_visual_pr.shutil.which", return_value="/usr/bin/magick"), + patch("scripts.check_visual_pr.subprocess.run") as run, + ): + run.return_value.returncode = 1 + run.return_value.stderr = "6.83993e+06 (0.759992)" + run.return_value.stdout = "" + + delta = decoded_pixel_delta(Path("gt.jpg"), Path("native.jpg")) + + self.assertEqual(delta, 6_839_930) + def prepare_evidence(self, root: Path) -> tuple[str, dict[str, object]]: issue_dir = root / "assets/bugfixes/issue-186" issue_dir.mkdir(parents=True)