Compare commits

...
2 changed files with 39 additions and 13 deletions

No files matched your search

+1
View File
@@ -0,0 +1 @@
use flake
+38 -13
View File
@@ -75,12 +75,18 @@ def test_a_failure_after_a_good_frame_keeps_the_known_size():
def test_env_is_overlaid_on_our_own_environment(): def test_env_is_overlaid_on_our_own_environment():
argv = [sys.executable, "-c", argv = [
"import os,sys;sys.stdout.write(os.environ['WAYLAND_DISPLAY']+':'+" sys.executable,
"('PATH' in os.environ and 'haspath' or 'nopath'))"] "-c",
"import os,sys;sys.stdout.write(os.environ['WAYLAND_DISPLAY']+':'+"
+ "('PATH' in os.environ and 'haspath' or 'nopath'))",
]
before = os.environ.get("WAYLAND_DISPLAY")
capture = CommandCapture(argv, env={"WAYLAND_DISPLAY": "wayland-9"}) capture = CommandCapture(argv, env={"WAYLAND_DISPLAY": "wayland-9"})
assert capture.grab() == b"wayland-9:haspath" assert capture.grab() == b"wayland-9:haspath"
assert "WAYLAND_DISPLAY" not in os.environ, "our own environment was mutated" assert os.environ.get("WAYLAND_DISPLAY") == before, (
"our own environment was mutated"
)
def test_empty_argv_and_bad_timeout_are_rejected_up_front(): def test_empty_argv_and_bad_timeout_are_rejected_up_front():
@@ -91,8 +97,10 @@ def test_empty_argv_and_bad_timeout_are_rejected_up_front():
def test_the_helpers_stdin_is_closed_so_it_cannot_steal_ours(): def test_the_helpers_stdin_is_closed_so_it_cannot_steal_ours():
code = ("import sys;" code = (
"sys.stdout.buffer.write(b'EMPTY' if not sys.stdin.read() else b'DATA')") "import sys;"
"sys.stdout.buffer.write(b'EMPTY' if not sys.stdin.read() else b'DATA')"
)
assert CommandCapture([sys.executable, "-c", code]).grab() == b"EMPTY" assert CommandCapture([sys.executable, "-c", code]).grab() == b"EMPTY"
@@ -102,15 +110,32 @@ def test_image_size_reads_png_headers(width, height):
def test_image_size_reads_a_jpeg_sof_header(): def test_image_size_reads_a_jpeg_sof_header():
jpeg = (b"\xff\xd8" jpeg = (
+ b"\xff\xe0" + (16).to_bytes(2, "big") + b"JFIF\x00" + b"\x00" * 9 b"\xff\xd8"
+ b"\xff\xc0" + (17).to_bytes(2, "big") + b"\x08" + b"\xff\xe0"
+ (720).to_bytes(2, "big") + (1280).to_bytes(2, "big") + (16).to_bytes(2, "big")
+ b"\x03" + b"\x00" * 9) + b"JFIF\x00"
+ b"\x00" * 9
+ b"\xff\xc0"
+ (17).to_bytes(2, "big")
+ b"\x08"
+ (720).to_bytes(2, "big")
+ (1280).to_bytes(2, "big")
+ b"\x03"
+ b"\x00" * 9
)
assert image_size(jpeg) == (1280, 720) assert image_size(jpeg) == (1280, 720)
@pytest.mark.parametrize("data", [b"", b"not an image", b"\x89PNG\r\n\x1a\n", @pytest.mark.parametrize(
b"\xff\xd8", b"\xff\xd8\xff\xc0\x00\x11"]) "data",
[
b"",
b"not an image",
b"\x89PNG\r\n\x1a\n",
b"\xff\xd8",
b"\xff\xd8\xff\xc0\x00\x11",
],
)
def test_image_size_returns_none_when_it_cannot_tell(data): def test_image_size_returns_none_when_it_cannot_tell(data):
assert image_size(data) is None assert image_size(data) is None