From 60bf46fef99f5d7757a9e028a4dc5771c3f30d20 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 26 Oct 2024 13:58:08 +1100 Subject: [PATCH] Only test register_handler in a single thread --- Tests/test_file_bufrstub.py | 3 +++ Tests/test_file_gribstub.py | 3 +++ Tests/test_file_hdf5stub.py | 3 +++ Tests/test_file_wmf.py | 20 ++++++++++++-------- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Tests/test_file_bufrstub.py b/Tests/test_file_bufrstub.py index 77ee5b0ea..dacb620a8 100644 --- a/Tests/test_file_bufrstub.py +++ b/Tests/test_file_bufrstub.py @@ -51,6 +51,9 @@ def test_save(tmp_path: Path) -> None: def test_handler(tmp_path: Path) -> None: + if BufrStubImagePlugin._handler is not None: + return + class TestHandler(ImageFile.StubHandler): opened = False loaded = False diff --git a/Tests/test_file_gribstub.py b/Tests/test_file_gribstub.py index aba473d24..40ef2a3b1 100644 --- a/Tests/test_file_gribstub.py +++ b/Tests/test_file_gribstub.py @@ -51,6 +51,9 @@ def test_save(tmp_path: Path) -> None: def test_handler(tmp_path: Path) -> None: + if GribStubImagePlugin._handler is not None: + return + class TestHandler(ImageFile.StubHandler): opened = False loaded = False diff --git a/Tests/test_file_hdf5stub.py b/Tests/test_file_hdf5stub.py index 8275bd0d8..f3f6f00f1 100644 --- a/Tests/test_file_hdf5stub.py +++ b/Tests/test_file_hdf5stub.py @@ -53,6 +53,9 @@ def test_save() -> None: def test_handler(tmp_path: Path) -> None: + if Hdf5StubImagePlugin._handler is not None: + return + class TestHandler(ImageFile.StubHandler): opened = False loaded = False diff --git a/Tests/test_file_wmf.py b/Tests/test_file_wmf.py index 79e707263..8513b8578 100644 --- a/Tests/test_file_wmf.py +++ b/Tests/test_file_wmf.py @@ -34,15 +34,19 @@ def test_load() -> None: assert im.load()[0, 0] == (255, 255, 255) +class TestHandler(ImageFile.StubHandler): + methodCalled = False + + def load(self, im: ImageFile.StubImageFile) -> Image.Image: + return Image.new("RGB", (1, 1)) + + def save(self, im: Image.Image, fp: IO[bytes], filename: str) -> None: + self.methodCalled = True + + def test_register_handler(tmp_path: Path) -> None: - class TestHandler(ImageFile.StubHandler): - methodCalled = False - - def load(self, im: ImageFile.StubImageFile) -> Image.Image: - return Image.new("RGB", (1, 1)) - - def save(self, im: Image.Image, fp: IO[bytes], filename: str) -> None: - self.methodCalled = True + if isinstance(WmfImagePlugin._handler, TestHandler): + return handler = TestHandler() original_handler = WmfImagePlugin._handler