| 18 | |
| 19 | @pytest.mark.parametrize("path", paths) |
| 20 | def test_screenshot(path: str): |
| 21 | driver = webdriver.Chrome(options=options) |
| 22 | m = importlib.import_module(f"tests.snapshots.modules.{path}").m |
| 23 | img_data = m._to_png(3, driver=driver, size=(800, 800)) |
| 24 | img_a = Image.open(io.BytesIO(img_data)) |
| 25 | img_a.save(f"/tmp/screenshot_new_{path}.png") |
| 26 | |
| 27 | if os.path.exists(f"tests/snapshots/screenshots/screenshot_{path}.png"): |
| 28 | img_b = Image.open(f"tests/snapshots/screenshots/screenshot_{path}.png") |
| 29 | |
| 30 | img_diff = Image.new("RGBA", img_a.size) |
| 31 | # note how there is no need to specify dimensions |
| 32 | mismatch = pixelmatch(img_a, img_b, img_diff, threshold=0.2, includeAA=False) |
| 33 | |
| 34 | img_diff.save(f"/tmp/screenshot_diff_{path}.png") |
| 35 | m.save(f"/tmp/folium_map_{path}.html") |
| 36 | assert mismatch < 200 |
| 37 | |
| 38 | else: # pragma: no cover |
| 39 | shutil.copy( |
| 40 | f"/tmp/screenshot_new_{path}.png", |
| 41 | f"tests/snapshots/screenshots/screenshot_{path}.png", |
| 42 | ) |
| 43 | raise Exception("no screenshot available, generating new") |