Skip to content

Commit 3b0c73e

Browse files
committed
frozen data class
1 parent 9c8a700 commit 3b0c73e

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

tests/test_a11y.py

+21-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Using Axe-core, scan the Kitchen Sink pages for accessibility violations."""
22

33
import time
4+
from dataclasses import dataclass
45
from http.client import HTTPConnection
56
from pathlib import Path
67
from subprocess import PIPE, Popen
@@ -70,20 +71,30 @@ def url_base():
7071
process.wait()
7172

7273

73-
def fingerprint_violations(accessibility_page_scan_violations):
74+
@dataclass(frozen=True)
75+
class AxeViolationFingerprint:
76+
"""Fingerprint for single Axe violation."""
77+
78+
id: str
79+
help: str
80+
helpUrl: str
81+
targets: tuple
82+
83+
84+
def fingerprint(accessibility_page_scan_violations):
7485
"""Create a fingerprint of the Axe violations array.
7586
7687
https://playwright.dev/docs/accessibility-testing#using-snapshots-to-allow-specific-known-issues
7788
"""
78-
return [
79-
{
80-
"id": violation["id"],
81-
"help": violation["help"],
82-
"helpUrl": violation["helpUrl"],
83-
"targets": [node["target"] for node in violation["nodes"]],
84-
}
89+
return tuple(
90+
AxeViolationFingerprint(
91+
violation["id"],
92+
violation["help"],
93+
violation["helpUrl"],
94+
tuple(node["target"] for node in violation["nodes"]),
95+
)
8596
for violation in accessibility_page_scan_violations
86-
]
97+
)
8798

8899

89100
@pytest.mark.a11y
@@ -171,7 +182,7 @@ def test_axe_core(
171182
results = page.evaluate("axe.run()" if selector == "" else f"axe.run('{selector}')")
172183

173184
# Check found violations against known violations that we do not plan to fix
174-
data_regression.check(fingerprint_violations(results["violations"]))
185+
data_regression.check(fingerprint(results["violations"]))
175186

176187

177188
def test_version_switcher_highlighting(page: Page, url_base: str) -> None:

0 commit comments

Comments
 (0)