MCPcopy Index your code
hub / github.com/microsoft/playwright-python / assert_to_be_golden

Function assert_to_be_golden

tests/conftest.py:201–227  ·  view source on GitHub ↗
(browser_name: str)

Source from the content-addressed store, hash-verified

199
200@pytest.fixture(scope="session")
201def assert_to_be_golden(browser_name: str) -> Callable[[bytes, str], None]:
202 def compare(received_raw: bytes, golden_name: str) -> None:
203 golden_file_path = _dirname / f"golden-{browser_name}" / golden_name
204 try:
205 golden_file = golden_file_path.read_bytes()
206 received_image = Image.open(io.BytesIO(received_raw))
207 golden_image = Image.open(io.BytesIO(golden_file))
208
209 if golden_image.size != received_image.size:
210 pytest.fail("Image size differs to golden image")
211 return
212 diff_pixels = pixelmatch(
213 from_PIL_to_raw_data(received_image),
214 from_PIL_to_raw_data(golden_image),
215 golden_image.size[0],
216 golden_image.size[1],
217 threshold=0.2,
218 )
219 assert diff_pixels == 0
220 except Exception:
221 if os.getenv("PW_WRITE_SCREENSHOT"):
222 golden_file_path.parent.mkdir(parents=True, exist_ok=True)
223 golden_file_path.write_bytes(received_raw)
224 print(f"Wrote {golden_file_path}")
225 raise
226
227 return compare
228
229
230class RemoteServer:

Calls

no outgoing calls

Tested by

no test coverage detected