|
4 | 4 | import warnings |
5 | 5 | from io import BytesIO |
6 | 6 | from pathlib import Path |
| 7 | +from types import ModuleType |
| 8 | +from typing import Generator |
7 | 9 |
|
8 | 10 | import pytest |
9 | 11 |
|
|
20 | 22 | is_win32, |
21 | 23 | ) |
22 | 24 |
|
| 25 | +ElementTree: ModuleType | None |
23 | 26 | try: |
24 | 27 | from defusedxml import ElementTree |
25 | 28 | except ImportError: |
@@ -156,7 +159,7 @@ def test_int_resolution(self) -> None: |
156 | 159 | "resolution_unit, dpi", |
157 | 160 | [(None, 72.8), (2, 72.8), (3, 184.912)], |
158 | 161 | ) |
159 | | - def test_load_float_dpi(self, resolution_unit, dpi) -> None: |
| 162 | + def test_load_float_dpi(self, resolution_unit: int | None, dpi: float) -> None: |
160 | 163 | with Image.open( |
161 | 164 | "Tests/images/hopper_float_dpi_" + str(resolution_unit) + ".tif" |
162 | 165 | ) as im: |
@@ -284,7 +287,7 @@ def test_unknown_pixel_mode(self) -> None: |
284 | 287 | ("Tests/images/multipage.tiff", 3), |
285 | 288 | ), |
286 | 289 | ) |
287 | | - def test_n_frames(self, path, n_frames) -> None: |
| 290 | + def test_n_frames(self, path: str, n_frames: int) -> None: |
288 | 291 | with Image.open(path) as im: |
289 | 292 | assert im.n_frames == n_frames |
290 | 293 | assert im.is_animated == (n_frames != 1) |
@@ -402,7 +405,7 @@ def test__delitem__(self) -> None: |
402 | 405 | assert len_before == len_after + 1 |
403 | 406 |
|
404 | 407 | @pytest.mark.parametrize("legacy_api", (False, True)) |
405 | | - def test_load_byte(self, legacy_api) -> None: |
| 408 | + def test_load_byte(self, legacy_api: bool) -> None: |
406 | 409 | ifd = TiffImagePlugin.ImageFileDirectory_v2() |
407 | 410 | data = b"abc" |
408 | 411 | ret = ifd.load_byte(data, legacy_api) |
@@ -431,7 +434,7 @@ def test_ifd_tag_type(self) -> None: |
431 | 434 | assert 0x8825 in im.tag_v2 |
432 | 435 |
|
433 | 436 | def test_exif(self, tmp_path: Path) -> None: |
434 | | - def check_exif(exif) -> None: |
| 437 | + def check_exif(exif: Image.Exif) -> None: |
435 | 438 | assert sorted(exif.keys()) == [ |
436 | 439 | 256, |
437 | 440 | 257, |
@@ -511,7 +514,7 @@ def test_exif_frames(self) -> None: |
511 | 514 | assert im.getexif()[273] == (1408, 1907) |
512 | 515 |
|
513 | 516 | @pytest.mark.parametrize("mode", ("1", "L")) |
514 | | - def test_photometric(self, mode, tmp_path: Path) -> None: |
| 517 | + def test_photometric(self, mode: str, tmp_path: Path) -> None: |
515 | 518 | filename = str(tmp_path / "temp.tif") |
516 | 519 | im = hopper(mode) |
517 | 520 | im.save(filename, tiffinfo={262: 0}) |
@@ -660,7 +663,7 @@ def test_planar_configuration_save(self, tmp_path: Path) -> None: |
660 | 663 | assert_image_equal_tofile(reloaded, infile) |
661 | 664 |
|
662 | 665 | @pytest.mark.parametrize("mode", ("P", "PA")) |
663 | | - def test_palette(self, mode, tmp_path: Path) -> None: |
| 666 | + def test_palette(self, mode: str, tmp_path: Path) -> None: |
664 | 667 | outfile = str(tmp_path / "temp.tif") |
665 | 668 |
|
666 | 669 | im = hopper(mode) |
@@ -689,7 +692,7 @@ def test_tiff_save_all(self) -> None: |
689 | 692 | assert reread.n_frames == 3 |
690 | 693 |
|
691 | 694 | # Test appending using a generator |
692 | | - def im_generator(ims): |
| 695 | + def im_generator(ims: list[Image.Image]) -> Generator[Image.Image, None, None]: |
693 | 696 | yield from ims |
694 | 697 |
|
695 | 698 | mp = BytesIO() |
@@ -860,7 +863,7 @@ def test_timeout(self) -> None: |
860 | 863 | ], |
861 | 864 | ) |
862 | 865 | @pytest.mark.timeout(2) |
863 | | - def test_oom(self, test_file) -> None: |
| 866 | + def test_oom(self, test_file: str) -> None: |
864 | 867 | with pytest.raises(UnidentifiedImageError): |
865 | 868 | with pytest.warns(UserWarning): |
866 | 869 | with Image.open(test_file): |
|
0 commit comments