Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions scripts/check_visual_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 14 additions & 0 deletions scripts/tests/test_check_visual_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
Loading