Skip to content

Commit

Permalink
Autotype tests (#7756)
Browse files Browse the repository at this point in the history
* autotyping: --none-return
* autotyping: --scalar-return
* autotyping: --int-param
* autotyping: --float-param
* autotyping: --str-param
* autotyping: --annotate-named-param tmp_path:pathlib.Path
  • Loading branch information
hugovk committed Jan 31, 2024
1 parent db43738 commit 4a4b90c
Show file tree
Hide file tree
Showing 108 changed files with 1,866 additions and 1,798 deletions.
8 changes: 4 additions & 4 deletions Tests/bench_cffi_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
# Not running this test by default. No DOS against CI.


def iterate_get(size, access):
def iterate_get(size, access) -> None:
(w, h) = size
for x in range(w):
for y in range(h):
access[(x, y)]


def iterate_set(size, access):
def iterate_set(size, access) -> None:
(w, h) = size
for x in range(w):
for y in range(h):
access[(x, y)] = (x % 256, y % 256, 0)


def timer(func, label, *args):
def timer(func, label, *args) -> None:
iterations = 5000
starttime = time.time()
for x in range(iterations):
Expand All @@ -38,7 +38,7 @@ def timer(func, label, *args):
)


def test_direct():
def test_direct() -> None:
im = hopper()
im.load()
# im = Image.new("RGB", (2000, 2000), (1, 3, 2))
Expand Down
6 changes: 3 additions & 3 deletions Tests/test_bmp_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
base = os.path.join("Tests", "images", "bmp")


def get_files(d, ext=".bmp"):
def get_files(d, ext: str = ".bmp"):
return [
os.path.join(base, d, f) for f in os.listdir(os.path.join(base, d)) if ext in f
]


def test_bad():
def test_bad() -> None:
"""These shouldn't crash/dos, but they shouldn't return anything
either"""
for f in get_files("b"):
Expand Down Expand Up @@ -56,7 +56,7 @@ def test_questionable():
raise


def test_good():
def test_good() -> None:
"""These should all work. There's a set of target files in the
html directory that we can compare against."""

Expand Down
34 changes: 17 additions & 17 deletions Tests/test_box_blur.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
# fmt: on


def test_imageops_box_blur():
def test_imageops_box_blur() -> None:
i = sample.filter(ImageFilter.BoxBlur(1))
assert i.mode == sample.mode
assert i.size == sample.size
assert isinstance(i, Image.Image)


def box_blur(image, radius=1, n=1):
def box_blur(image, radius: int = 1, n: int = 1):
return image._new(image.im.box_blur((radius, radius), n))


def assert_image(im, data, delta=0):
def assert_image(im, data, delta: int = 0) -> None:
it = iter(im.getdata())
for data_row in data:
im_row = [next(it) for _ in range(im.size[0])]
Expand All @@ -37,15 +37,15 @@ def assert_image(im, data, delta=0):
next(it)


def assert_blur(im, radius, data, passes=1, delta=0):
def assert_blur(im, radius, data, passes: int = 1, delta: int = 0) -> None:
# check grayscale image
assert_image(box_blur(im, radius, passes), data, delta)
rgba = Image.merge("RGBA", (im, im, im, im))
for band in box_blur(rgba, radius, passes).split():
assert_image(band, data, delta)


def test_color_modes():
def test_color_modes() -> None:
with pytest.raises(ValueError):
box_blur(sample.convert("1"))
with pytest.raises(ValueError):
Expand All @@ -65,7 +65,7 @@ def test_color_modes():
box_blur(sample.convert("YCbCr"))


def test_radius_0():
def test_radius_0() -> None:
assert_blur(
sample,
0,
Expand All @@ -81,7 +81,7 @@ def test_radius_0():
)


def test_radius_0_02():
def test_radius_0_02() -> None:
assert_blur(
sample,
0.02,
Expand All @@ -98,7 +98,7 @@ def test_radius_0_02():
)


def test_radius_0_05():
def test_radius_0_05() -> None:
assert_blur(
sample,
0.05,
Expand All @@ -115,7 +115,7 @@ def test_radius_0_05():
)


def test_radius_0_1():
def test_radius_0_1() -> None:
assert_blur(
sample,
0.1,
Expand All @@ -132,7 +132,7 @@ def test_radius_0_1():
)


def test_radius_0_5():
def test_radius_0_5() -> None:
assert_blur(
sample,
0.5,
Expand All @@ -149,7 +149,7 @@ def test_radius_0_5():
)


def test_radius_1():
def test_radius_1() -> None:
assert_blur(
sample,
1,
Expand All @@ -166,7 +166,7 @@ def test_radius_1():
)


def test_radius_1_5():
def test_radius_1_5() -> None:
assert_blur(
sample,
1.5,
Expand All @@ -183,7 +183,7 @@ def test_radius_1_5():
)


def test_radius_bigger_then_half():
def test_radius_bigger_then_half() -> None:
assert_blur(
sample,
3,
Expand All @@ -200,7 +200,7 @@ def test_radius_bigger_then_half():
)


def test_radius_bigger_then_width():
def test_radius_bigger_then_width() -> None:
assert_blur(
sample,
10,
Expand All @@ -215,7 +215,7 @@ def test_radius_bigger_then_width():
)


def test_extreme_large_radius():
def test_extreme_large_radius() -> None:
assert_blur(
sample,
600,
Expand All @@ -230,7 +230,7 @@ def test_extreme_large_radius():
)


def test_two_passes():
def test_two_passes() -> None:
assert_blur(
sample,
1,
Expand All @@ -248,7 +248,7 @@ def test_two_passes():
)


def test_three_passes():
def test_three_passes() -> None:
assert_blur(
sample,
1,
Expand Down
Loading

0 comments on commit 4a4b90c

Please sign in to comment.