项目文件夹

文件
Saurav Panda ffadfe6c51 fix: declare pillow dependency and use TemporaryDirectory in tests
Bot review caught two issues:

1. capture_screenshot's max_dim path imports PIL but Pillow wasn't in
   pyproject.toml dependencies, so a clean install would ImportError as
   soon as the option was used.

2. NamedTemporaryFile + writing to f.name while the handle is open is
   not portable on Windows (file lock). Switched the screenshot tests to
   tempfile.TemporaryDirectory and folded the three near-identical bodies
   into a small _run() helper.
2026-04-27 12:08:40 -07:00

36 行
916 B
Python

import base64
import io
import os
import tempfile
from unittest.mock import patch
from PIL import Image
import helpers
def _fake_png(width, height):
buf = io.BytesIO()
Image.new("RGB", (width, height), "white").save(buf, format="PNG")
return base64.b64encode(buf.getvalue()).decode()
def _run(width, height, **kwargs):
fake = lambda method, **_: {"data": _fake_png(width, height)}
with patch("helpers.cdp", side_effect=fake), tempfile.TemporaryDirectory() as d:
path = os.path.join(d, "shot.png")
helpers.capture_screenshot(path, **kwargs)
return Image.open(path).size
def test_max_dim_downsizes_oversized_image():
assert max(_run(4592, 2286, max_dim=1800)) == 1800
def test_max_dim_skips_when_image_already_small():
assert _run(800, 400, max_dim=1800) == (800, 400)
def test_max_dim_default_is_no_resize():
assert _run(4592, 2286) == (4592, 2286)