Skip to content

Commit 1754125

Browse files
authored
Merge pull request #8618 from radarhere/px
2 parents a254b8c + f4db366 commit 1754125

15 files changed

+49
-11
lines changed

Tests/test_file_dds.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,13 @@ def test_dxt5_colorblock_alpha_issue_4142() -> None:
331331

332332
with Image.open("Tests/images/dxt5-colorblock-alpha-issue-4142.dds") as im:
333333
px = im.getpixel((0, 0))
334+
assert isinstance(px, tuple)
334335
assert px[0] != 0
335336
assert px[1] != 0
336337
assert px[2] != 0
337338

338339
px = im.getpixel((1, 0))
340+
assert isinstance(px, tuple)
339341
assert px[0] != 0
340342
assert px[1] != 0
341343
assert px[2] != 0

Tests/test_file_eps.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,14 @@ def test_sanity(filename: str, size: tuple[int, int], scale: int) -> None:
9595
@pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available")
9696
def test_load() -> None:
9797
with Image.open(FILE1) as im:
98-
assert im.load()[0, 0] == (255, 255, 255)
98+
px = im.load()
99+
assert px is not None
100+
assert px[0, 0] == (255, 255, 255)
99101

100102
# Test again now that it has already been loaded once
101-
assert im.load()[0, 0] == (255, 255, 255)
103+
px = im.load()
104+
assert px is not None
105+
assert px[0, 0] == (255, 255, 255)
102106

103107

104108
def test_binary() -> None:

Tests/test_file_gbr.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ def test_gbr_file() -> None:
1414

1515
def test_load() -> None:
1616
with Image.open("Tests/images/gbr.gbr") as im:
17+
px = im.load()
18+
assert px is not None
1719
assert im.load()[0, 0] == (0, 0, 0, 0)
1820

1921
# Test again now that it has already been loaded once
20-
assert im.load()[0, 0] == (0, 0, 0, 0)
22+
px = im.load()
23+
assert px is not None
24+
assert px[0, 0] == (0, 0, 0, 0)
2125

2226

2327
def test_multiple_load_operations() -> None:

Tests/test_file_gif.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ def test_roundtrip_save_all_1(tmp_path: Path) -> None:
307307
def test_loading_multiple_palettes(path: str, mode: str) -> None:
308308
with Image.open(path) as im:
309309
assert im.mode == "P"
310+
assert im.palette is not None
310311
first_frame_colors = im.palette.colors.keys()
311312
original_color = im.convert("RGB").getpixel((0, 0))
312313

@@ -525,6 +526,7 @@ def test_dispose_background_transparency() -> None:
525526
with Image.open("Tests/images/dispose_bgnd_transparency.gif") as img:
526527
img.seek(2)
527528
px = img.load()
529+
assert px is not None
528530
assert px[35, 30][3] == 0
529531

530532

@@ -1323,6 +1325,7 @@ def test_palette_save_all_P(tmp_path: Path) -> None:
13231325
with Image.open(out) as im:
13241326
# Assert that the frames are correct, and each frame has the same palette
13251327
assert_image_equal(im.convert("RGB"), frames[0].convert("RGB"))
1328+
assert im.palette is not None
13261329
assert im.palette.palette == im.global_palette.palette
13271330

13281331
im.seek(1)

Tests/test_file_icns.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@ def test_sanity() -> None:
3232

3333
def test_load() -> None:
3434
with Image.open(TEST_FILE) as im:
35-
assert im.load()[0, 0] == (0, 0, 0, 0)
35+
px = im.load()
36+
assert px is not None
37+
assert px[0, 0] == (0, 0, 0, 0)
3638

3739
# Test again now that it has already been loaded once
38-
assert im.load()[0, 0] == (0, 0, 0, 0)
40+
px = im.load()
41+
assert px is not None
42+
assert px[0, 0] == (0, 0, 0, 0)
3943

4044

4145
def test_save(tmp_path: Path) -> None:

Tests/test_file_ico.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ def test_sanity() -> None:
2424

2525
def test_load() -> None:
2626
with Image.open(TEST_ICO_FILE) as im:
27-
assert im.load()[0, 0] == (1, 1, 9, 255)
27+
px = im.load()
28+
assert px is not None
29+
assert px[0, 0] == (1, 1, 9, 255)
2830

2931

3032
def test_mask() -> None:

Tests/test_file_jpeg2k.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def test_sanity() -> None:
6363

6464
with Image.open("Tests/images/test-card-lossless.jp2") as im:
6565
px = im.load()
66+
assert px is not None
6667
assert px[0, 0] == (0, 0, 0)
6768
assert im.mode == "RGB"
6869
assert im.size == (640, 480)
@@ -421,13 +422,15 @@ def test_subsampling_decode(name: str) -> None:
421422
def test_pclr() -> None:
422423
with Image.open(f"{EXTRA_DIR}/issue104_jpxstream.jp2") as im:
423424
assert im.mode == "P"
425+
assert im.palette is not None
424426
assert len(im.palette.colors) == 256
425427
assert im.palette.colors[(255, 255, 255)] == 0
426428

427429
with Image.open(
428430
f"{EXTRA_DIR}/147af3f1083de4393666b7d99b01b58b_signal_sigsegv_130c531_6155_5136.jp2"
429431
) as im:
430432
assert im.mode == "P"
433+
assert im.palette is not None
431434
assert len(im.palette.colors) == 139
432435
assert im.palette.colors[(0, 0, 0, 0)] == 0
433436

Tests/test_file_ppm.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def test_arbitrary_maxval(
7979
assert im.mode == mode
8080

8181
px = im.load()
82+
assert px is not None
8283
assert tuple(px[x, 0] for x in range(3)) == pixels
8384

8485

Tests/test_file_tga.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def test_palette_depth_8(tmp_path: Path) -> None:
7272

7373
def test_palette_depth_16(tmp_path: Path) -> None:
7474
with Image.open("Tests/images/p_16.tga") as im:
75+
assert im.palette is not None
7576
assert im.palette.mode == "RGBA"
7677
assert_image_equal_tofile(im.convert("RGBA"), "Tests/images/p_16.png")
7778

@@ -213,10 +214,14 @@ def test_save_orientation(tmp_path: Path) -> None:
213214
def test_horizontal_orientations() -> None:
214215
# These images have been manually hexedited to have the relevant orientations
215216
with Image.open("Tests/images/rgb32rle_top_right.tga") as im:
216-
assert im.load()[90, 90][:3] == (0, 0, 0)
217+
px = im.load()
218+
assert px is not None
219+
assert px[90, 90][:3] == (0, 0, 0)
217220

218221
with Image.open("Tests/images/rgb32rle_bottom_right.tga") as im:
219-
assert im.load()[90, 90][:3] == (0, 255, 0)
222+
px = im.load()
223+
assert px is not None
224+
assert px[90, 90][:3] == (0, 255, 0)
220225

221226

222227
def test_save_rle(tmp_path: Path) -> None:

Tests/test_file_wal.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ def test_open() -> None:
2121

2222
def test_load() -> None:
2323
with WalImageFile.open(TEST_FILE) as im:
24-
assert im.load()[0, 0] == 122
24+
px = im.load()
25+
assert px is not None
26+
assert px[0, 0] == 122
2527

2628
# Test again now that it has already been loaded once
27-
assert im.load()[0, 0] == 122
29+
px = im.load()
30+
assert px is not None
31+
assert px[0, 0] == 122

0 commit comments

Comments
 (0)