Skip to content

Commit 232bddd

Browse files
authored
Merge pull request #7755 from radarhere/type_hints
2 parents f55c9c6 + 7373149 commit 232bddd

25 files changed

+60
-54
lines changed

Tests/test_000_sanity.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from PIL import Image
44

55

6-
def test_sanity():
6+
def test_sanity() -> None:
77
# Make sure we have the binary extension
88
Image.core.new("L", (100, 100))
99

Tests/test_binary.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
from PIL import _binary
44

55

6-
def test_standard():
6+
def test_standard() -> None:
77
assert _binary.i8(b"*") == 42
88
assert _binary.o8(42) == b"*"
99

1010

11-
def test_little_endian():
11+
def test_little_endian() -> None:
1212
assert _binary.i16le(b"\xff\xff\x00\x00") == 65535
1313
assert _binary.i32le(b"\xff\xff\x00\x00") == 65535
1414

1515
assert _binary.o16le(65535) == b"\xff\xff"
1616
assert _binary.o32le(65535) == b"\xff\xff\x00\x00"
1717

1818

19-
def test_big_endian():
19+
def test_big_endian() -> None:
2020
assert _binary.i16be(b"\x00\x00\xff\xff") == 0
2121
assert _binary.i32be(b"\x00\x00\xff\xff") == 65535
2222

Tests/test_file_cur.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
TEST_FILE = "Tests/images/deerstalker.cur"
88

99

10-
def test_sanity():
10+
def test_sanity() -> None:
1111
with Image.open(TEST_FILE) as im:
1212
assert im.size == (32, 32)
1313
assert isinstance(im, CurImagePlugin.CurImageFile)
@@ -17,7 +17,7 @@ def test_sanity():
1717
assert im.getpixel((16, 16)) == (84, 87, 86, 255)
1818

1919

20-
def test_invalid_file():
20+
def test_invalid_file() -> None:
2121
invalid_file = "Tests/images/flower.jpg"
2222

2323
with pytest.raises(SyntaxError):

Tests/test_file_ftex.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
from .helper import assert_image_equal_tofile, assert_image_similar
88

99

10-
def test_load_raw():
10+
def test_load_raw() -> None:
1111
with Image.open("Tests/images/ftex_uncompressed.ftu") as im:
1212
assert_image_equal_tofile(im, "Tests/images/ftex_uncompressed.png")
1313

1414

15-
def test_load_dxt1():
15+
def test_load_dxt1() -> None:
1616
with Image.open("Tests/images/ftex_dxt1.ftc") as im:
1717
with Image.open("Tests/images/ftex_dxt1.png") as target:
1818
assert_image_similar(im, target.convert("RGBA"), 15)
1919

2020

21-
def test_invalid_file():
21+
def test_invalid_file() -> None:
2222
invalid_file = "Tests/images/flower.jpg"
2323

2424
with pytest.raises(SyntaxError):

Tests/test_file_gbr.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,27 @@
77
from .helper import assert_image_equal_tofile
88

99

10-
def test_gbr_file():
10+
def test_gbr_file() -> None:
1111
with Image.open("Tests/images/gbr.gbr") as im:
1212
assert_image_equal_tofile(im, "Tests/images/gbr.png")
1313

1414

15-
def test_load():
15+
def test_load() -> None:
1616
with Image.open("Tests/images/gbr.gbr") as im:
1717
assert im.load()[0, 0] == (0, 0, 0, 0)
1818

1919
# Test again now that it has already been loaded once
2020
assert im.load()[0, 0] == (0, 0, 0, 0)
2121

2222

23-
def test_multiple_load_operations():
23+
def test_multiple_load_operations() -> None:
2424
with Image.open("Tests/images/gbr.gbr") as im:
2525
im.load()
2626
im.load()
2727
assert_image_equal_tofile(im, "Tests/images/gbr.png")
2828

2929

30-
def test_invalid_file():
30+
def test_invalid_file() -> None:
3131
invalid_file = "Tests/images/flower.jpg"
3232

3333
with pytest.raises(SyntaxError):

Tests/test_file_gd.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
TEST_GD_FILE = "Tests/images/hopper.gd"
88

99

10-
def test_sanity():
10+
def test_sanity() -> None:
1111
with GdImageFile.open(TEST_GD_FILE) as im:
1212
assert im.size == (128, 128)
1313
assert im.format == "GD"
1414

1515

16-
def test_bad_mode():
16+
def test_bad_mode() -> None:
1717
with pytest.raises(ValueError):
1818
GdImageFile.open(TEST_GD_FILE, "bad mode")
1919

2020

21-
def test_invalid_file():
21+
def test_invalid_file() -> None:
2222
invalid_file = "Tests/images/flower.jpg"
2323

2424
with pytest.raises(UnidentifiedImageError):

Tests/test_file_gimppalette.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from PIL.GimpPaletteFile import GimpPaletteFile
66

77

8-
def test_sanity():
8+
def test_sanity() -> None:
99
with open("Tests/images/test.gpl", "rb") as fp:
1010
GimpPaletteFile(fp)
1111

@@ -22,7 +22,7 @@ def test_sanity():
2222
GimpPaletteFile(fp)
2323

2424

25-
def test_get_palette():
25+
def test_get_palette() -> None:
2626
# Arrange
2727
with open("Tests/images/custom_gimp_palette.gpl", "rb") as fp:
2828
palette_file = GimpPaletteFile(fp)

Tests/test_file_imt.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
from .helper import assert_image_equal_tofile
1010

1111

12-
def test_sanity():
12+
def test_sanity() -> None:
1313
with Image.open("Tests/images/bw_gradient.imt") as im:
1414
assert_image_equal_tofile(im, "Tests/images/bw_gradient.png")
1515

1616

1717
@pytest.mark.parametrize("data", (b"\n", b"\n-", b"width 1\n"))
18-
def test_invalid_file(data):
18+
def test_invalid_file(data: bytes) -> None:
1919
with io.BytesIO(data) as fp:
2020
with pytest.raises(SyntaxError):
2121
ImtImagePlugin.ImtImageFile(fp)

Tests/test_file_mcidas.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
from .helper import assert_image_equal_tofile
88

99

10-
def test_invalid_file():
10+
def test_invalid_file() -> None:
1111
invalid_file = "Tests/images/flower.jpg"
1212

1313
with pytest.raises(SyntaxError):
1414
McIdasImagePlugin.McIdasImageFile(invalid_file)
1515

1616

17-
def test_valid_file():
17+
def test_valid_file() -> None:
1818
# Arrange
1919
# https://ghrc.nsstc.nasa.gov/hydro/details/cmx3g8
2020
# https://ghrc.nsstc.nasa.gov/pub/fieldCampaigns/camex3/cmx3g8/browse/

Tests/test_file_pcd.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from PIL import Image
44

55

6-
def test_load_raw():
6+
def test_load_raw() -> None:
77
with Image.open("Tests/images/hopper.pcd") as im:
88
im.load() # should not segfault.
99

Tests/test_file_pixar.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
TEST_FILE = "Tests/images/hopper.pxr"
1010

1111

12-
def test_sanity():
12+
def test_sanity() -> None:
1313
with Image.open(TEST_FILE) as im:
1414
im.load()
1515
assert im.mode == "RGB"
@@ -21,7 +21,7 @@ def test_sanity():
2121
assert_image_similar(im, im2, 4.8)
2222

2323

24-
def test_invalid_file():
24+
def test_invalid_file() -> None:
2525
invalid_file = "Tests/images/flower.jpg"
2626

2727
with pytest.raises(SyntaxError):

Tests/test_file_qoi.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from .helper import assert_image_equal_tofile
88

99

10-
def test_sanity():
10+
def test_sanity() -> None:
1111
with Image.open("Tests/images/hopper.qoi") as im:
1212
assert im.mode == "RGB"
1313
assert im.size == (128, 128)
@@ -23,7 +23,7 @@ def test_sanity():
2323
assert_image_equal_tofile(im, "Tests/images/pil123rgba.png")
2424

2525

26-
def test_invalid_file():
26+
def test_invalid_file() -> None:
2727
invalid_file = "Tests/images/flower.jpg"
2828

2929
with pytest.raises(SyntaxError):

Tests/test_file_wal.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
TEST_FILE = "Tests/images/hopper.wal"
88

99

10-
def test_open():
10+
def test_open() -> None:
1111
with WalImageFile.open(TEST_FILE) as im:
1212
assert im.format == "WAL"
1313
assert im.format_description == "Quake2 Texture"
@@ -19,7 +19,7 @@ def test_open():
1919
assert_image_equal_tofile(im, "Tests/images/hopper_wal.png")
2020

2121

22-
def test_load():
22+
def test_load() -> None:
2323
with WalImageFile.open(TEST_FILE) as im:
2424
assert im.load()[0, 0] == 122
2525

Tests/test_file_webp_lossless.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
from pathlib import Path
4+
35
import pytest
46

57
from PIL import Image
@@ -10,7 +12,7 @@
1012
RGB_MODE = "RGB"
1113

1214

13-
def test_write_lossless_rgb(tmp_path):
15+
def test_write_lossless_rgb(tmp_path: Path) -> None:
1416
if _webp.WebPDecoderVersion() < 0x0200:
1517
pytest.skip("lossless not included")
1618

Tests/test_file_xpm.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
TEST_FILE = "Tests/images/hopper.xpm"
1010

1111

12-
def test_sanity():
12+
def test_sanity() -> None:
1313
with Image.open(TEST_FILE) as im:
1414
im.load()
1515
assert im.mode == "P"
@@ -20,14 +20,14 @@ def test_sanity():
2020
assert_image_similar(im.convert("RGB"), hopper("RGB"), 60)
2121

2222

23-
def test_invalid_file():
23+
def test_invalid_file() -> None:
2424
invalid_file = "Tests/images/flower.jpg"
2525

2626
with pytest.raises(SyntaxError):
2727
XpmImagePlugin.XpmImageFile(invalid_file)
2828

2929

30-
def test_load_read():
30+
def test_load_read() -> None:
3131
# Arrange
3232
with Image.open(TEST_FILE) as im:
3333
dummy_bytes = 1

Tests/test_file_xvthumb.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
TEST_FILE = "Tests/images/hopper.p7"
1010

1111

12-
def test_open():
12+
def test_open() -> None:
1313
# Act
1414
with Image.open(TEST_FILE) as im:
1515
# Assert
@@ -20,7 +20,7 @@ def test_open():
2020
assert_image_similar(im, im_hopper, 9)
2121

2222

23-
def test_unexpected_eof():
23+
def test_unexpected_eof() -> None:
2424
# Test unexpected EOF reading XV thumbnail file
2525
# Arrange
2626
bad_file = "Tests/images/hopper_bad.p7"
@@ -30,7 +30,7 @@ def test_unexpected_eof():
3030
XVThumbImagePlugin.XVThumbImageFile(bad_file)
3131

3232

33-
def test_invalid_file():
33+
def test_invalid_file() -> None:
3434
# Arrange
3535
invalid_file = "Tests/images/flower.jpg"
3636

Tests/test_fontfile.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
from __future__ import annotations
22

3+
from pathlib import Path
4+
35
import pytest
46

57
from PIL import FontFile
68

79

8-
def test_save(tmp_path):
10+
def test_save(tmp_path: Path) -> None:
911
tempname = str(tmp_path / "temp.pil")
1012

1113
font = FontFile.FontFile()

Tests/test_format_lab.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from PIL import Image
44

55

6-
def test_white():
6+
def test_white() -> None:
77
with Image.open("Tests/images/lab.tif") as i:
88
i.load()
99

@@ -24,15 +24,15 @@ def test_white():
2424
assert list(b) == [128] * 100
2525

2626

27-
def test_green():
27+
def test_green() -> None:
2828
# l= 50 (/100), a = -100 (-128 .. 128) b=0 in PS
2929
# == RGB: 0, 152, 117
3030
with Image.open("Tests/images/lab-green.tif") as i:
3131
k = i.getpixel((0, 0))
3232
assert k == (128, 28, 128)
3333

3434

35-
def test_red():
35+
def test_red() -> None:
3636
# l= 50 (/100), a = 100 (-128 .. 128) b=0 in PS
3737
# == RGB: 255, 0, 124
3838
with Image.open("Tests/images/lab-red.tif") as i:

Tests/test_lib_image.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from PIL import Image
66

77

8-
def test_setmode():
8+
def test_setmode() -> None:
99
im = Image.new("L", (1, 1), 255)
1010
im.im.setmode("1")
1111
assert im.im.getpixel((0, 0)) == 255

Tests/test_locale.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
path = "Tests/images/hopper.jpg"
2525

2626

27-
def test_sanity():
27+
def test_sanity() -> None:
2828
with Image.open(path):
2929
pass
3030
try:

Tests/test_main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import sys
66

77

8-
def test_main():
8+
def test_main() -> None:
99
out = subprocess.check_output([sys.executable, "-m", "PIL"]).decode("utf-8")
1010
lines = out.splitlines()
1111
assert lines[0] == "-" * 68

Tests/test_pyroma.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
pyroma = pytest.importorskip("pyroma", reason="Pyroma not installed")
88

99

10-
def test_pyroma():
10+
def test_pyroma() -> None:
1111
# Arrange
1212
data = pyroma.projectdata.get_data(".")
1313

0 commit comments

Comments
 (0)