fixing a test
This commit is contained in:
1 parent
4b5cb5197a
commit
934774f15e
2 files changed
+39
-13
No files matched your search
+38
-13
@@ -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():
|
||||
argv = [sys.executable, "-c",
|
||||
"import os,sys;sys.stdout.write(os.environ['WAYLAND_DISPLAY']+':'+"
|
||||
"('PATH' in os.environ and 'haspath' or 'nopath'))"]
|
||||
argv = [
|
||||
sys.executable,
|
||||
"-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"})
|
||||
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():
|
||||
@@ -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():
|
||||
code = ("import sys;"
|
||||
"sys.stdout.buffer.write(b'EMPTY' if not sys.stdin.read() else b'DATA')")
|
||||
code = (
|
||||
"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"
|
||||
|
||||
|
||||
@@ -102,15 +110,32 @@ def test_image_size_reads_png_headers(width, height):
|
||||
|
||||
|
||||
def test_image_size_reads_a_jpeg_sof_header():
|
||||
jpeg = (b"\xff\xd8"
|
||||
+ b"\xff\xe0" + (16).to_bytes(2, "big") + 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)
|
||||
jpeg = (
|
||||
b"\xff\xd8"
|
||||
+ b"\xff\xe0"
|
||||
+ (16).to_bytes(2, "big")
|
||||
+ 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)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("data", [b"", b"not an image", b"\x89PNG\r\n\x1a\n",
|
||||
b"\xff\xd8", b"\xff\xd8\xff\xc0\x00\x11"])
|
||||
@pytest.mark.parametrize(
|
||||
"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):
|
||||
assert image_size(data) is None
|
||||
Reference in new issue
Block a user