Skip to content

Commit 5b901d8

Browse files
committed
test: assert contrast payloads directly
1 parent e626e67 commit 5b901d8

2 files changed

Lines changed: 30 additions & 18 deletions

File tree

tests/test_cli.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -839,12 +839,16 @@ def test_should_emit_worst_tile_contrast_json_for_busy_background(self):
839839
}
840840
finding = payload["diagnostics"][0]
841841
assert finding["code"] == "low-contrast"
842-
assert finding["measured"]["contrast"] < finding["measured"]["threshold"]
843-
assert finding["measured"]["method"] == "worst-tile"
844-
assert finding["measured"]["tile_size"] == 32
845-
assert finding["measured"]["tile_count"] > 1
846-
assert finding["measured"]["tile_bbox"]["x"] >= 116
847-
assert finding["measured"]["background_rgb"][0] > 240
842+
assert finding["measured"] == {
843+
"contrast": 1.0,
844+
"threshold": 2.0,
845+
"method": "worst-tile",
846+
"tile_bbox": {"x": 116, "y": 30, "width": 32, "height": 26},
847+
"tile_count": 6,
848+
"tile_size": 32,
849+
"foreground_rgb": [255.0, 255.0, 255.0],
850+
"background_rgb": [255.0, 255.0, 255.0],
851+
}
848852

849853
def test_should_exit_1_for_invalid_lint_format(self, spec_file):
850854
"""lint exits 1 when --format is neither text nor json"""

tests/test_diagnostics.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -480,14 +480,16 @@ def test_should_include_structured_values_for_low_contrast_text(self):
480480
assert finding.bbox.width > 0
481481
assert finding.bbox.height > 0
482482
assert finding.related_layers == ["layer:1"]
483-
assert finding.measured["contrast"] < finding.measured["threshold"]
484-
assert finding.measured["method"] == "worst-tile"
485-
assert finding.measured["tile_count"] >= 1
486-
assert finding.measured["tile_size"] == 32
487-
assert finding.measured["tile_bbox"]["width"] > 0
488-
assert finding.measured["tile_bbox"]["height"] > 0
489-
assert len(finding.measured["foreground_rgb"]) == 3
490-
assert len(finding.measured["background_rgb"]) == 3
483+
assert finding.measured == {
484+
"contrast": 1.0620159366897584,
485+
"threshold": 2.0,
486+
"method": "worst-tile",
487+
"tile_bbox": {"x": 10, "y": 10, "width": 32, "height": 32},
488+
"tile_count": 12,
489+
"tile_size": 32,
490+
"foreground_rgb": (248.0, 248.0, 248.0),
491+
"background_rgb": (255.0, 255.0, 255.0),
492+
}
491493
assert finding.suggestion == "increase foreground/background contrast to at least 2.0:1"
492494

493495
def test_should_warn_for_worst_tile_contrast_on_busy_background(self):
@@ -511,10 +513,16 @@ def paint_split_background(image: Image.Image) -> None:
511513
# then
512514
assert [d.code for d in diagnostics] == ["low-contrast"]
513515
finding = diagnostics[0]
514-
assert finding.measured["method"] == "worst-tile"
515-
assert finding.measured["contrast"] < finding.measured["threshold"]
516-
assert finding.measured["tile_bbox"]["x"] >= 116
517-
assert finding.measured["background_rgb"][0] > 240
516+
assert finding.measured == {
517+
"contrast": 1.0,
518+
"threshold": 2.0,
519+
"method": "worst-tile",
520+
"tile_bbox": {"x": 116, "y": 30, "width": 32, "height": 26},
521+
"tile_count": 6,
522+
"tile_size": 32,
523+
"foreground_rgb": (255.0, 255.0, 255.0),
524+
"background_rgb": (255.0, 255.0, 255.0),
525+
}
518526

519527
def test_should_ignore_low_contrast_tiles_without_text_pixels(self):
520528
"""Whitespace inside the text bbox does not drive low-contrast findings"""

0 commit comments

Comments
 (0)