| 33 | class TestImageFile: |
| 34 | def test_parser(self, monkeypatch: pytest.MonkeyPatch) -> None: |
| 35 | def roundtrip(format: str) -> tuple[Image.Image, Image.Image]: |
| 36 | im = hopper("L").resize((1000, 1000), Image.Resampling.NEAREST) |
| 37 | if format in ("MSP", "XBM"): |
| 38 | im = im.convert("1") |
| 39 | |
| 40 | test_file = BytesIO() |
| 41 | |
| 42 | im.copy().save(test_file, format) |
| 43 | |
| 44 | data = test_file.getvalue() |
| 45 | |
| 46 | parser = ImageFile.Parser() |
| 47 | parser.feed(data) |
| 48 | im_out = parser.close() |
| 49 | |
| 50 | return im, im_out |
| 51 | |
| 52 | assert_image_equal(*roundtrip("BMP")) |
| 53 | im1, im2 = roundtrip("GIF") |