Moved code outside of context manager

This commit is contained in:
Andrew Murray 2025-03-08 09:54:46 +11:00
parent 5575c1d072
commit baa299a6f4
3 changed files with 9 additions and 9 deletions

View File

@ -317,12 +317,12 @@ def test_grayscale_four_channels() -> None:
with open("Tests/images/rgb_trns_ycbc.jp2", "rb") as fp: with open("Tests/images/rgb_trns_ycbc.jp2", "rb") as fp:
data = fp.read() data = fp.read()
# Change color space to OPJ_CLRSPC_GRAY # Change color space to OPJ_CLRSPC_GRAY
data = data[:76] + b"\x11" + data[77:] data = data[:76] + b"\x11" + data[77:]
with Image.open(BytesIO(data)) as im: with Image.open(BytesIO(data)) as im:
im.load() im.load()
assert im.mode == "RGBA" assert im.mode == "RGBA"
@pytest.mark.skipif( @pytest.mark.skipif(

View File

@ -40,7 +40,7 @@ def test_sanity(tmp_path: Path) -> None:
def test_bad_image_size() -> None: def test_bad_image_size() -> None:
with open("Tests/images/pil184.pcx", "rb") as fp: with open("Tests/images/pil184.pcx", "rb") as fp:
data = fp.read() data = fp.read()
data = data[:4] + b"\xff\xff" + data[6:] data = data[:4] + b"\xff\xff" + data[6:]
b = io.BytesIO(data) b = io.BytesIO(data)
with pytest.raises(SyntaxError, match="bad PCX image size"): with pytest.raises(SyntaxError, match="bad PCX image size"):
@ -51,7 +51,7 @@ def test_bad_image_size() -> None:
def test_unknown_mode() -> None: def test_unknown_mode() -> None:
with open("Tests/images/pil184.pcx", "rb") as fp: with open("Tests/images/pil184.pcx", "rb") as fp:
data = fp.read() data = fp.read()
data = data[:3] + b"\xff" + data[4:] data = data[:3] + b"\xff" + data[4:]
b = io.BytesIO(data) b = io.BytesIO(data)
with pytest.raises(OSError, match="unknown PCX mode"): with pytest.raises(OSError, match="unknown PCX mode"):

View File

@ -20,8 +20,8 @@ def test_sanity() -> None:
def test_zero_width_chars() -> None: def test_zero_width_chars() -> None:
with open(filename, "rb") as fp: with open(filename, "rb") as fp:
data = fp.read() data = fp.read()
data = data[:2650] + b"\x00\x00" + data[2652:] data = data[:2650] + b"\x00\x00" + data[2652:]
BdfFontFile.BdfFontFile(io.BytesIO(data)) BdfFontFile.BdfFontFile(io.BytesIO(data))
def test_invalid_file() -> None: def test_invalid_file() -> None: