From 6ad98ba3c0c371c9bddf53b0939e7632ede8c2b7 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 18 Jun 2020 21:40:38 +1000 Subject: [PATCH] Do not ignore viewer if order is zero when registering --- Tests/test_imageshow.py | 12 +++++++----- src/PIL/ImageShow.py | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Tests/test_imageshow.py b/Tests/test_imageshow.py index 64f15326b..fddc73bd1 100644 --- a/Tests/test_imageshow.py +++ b/Tests/test_imageshow.py @@ -17,19 +17,21 @@ def test_register(): ImageShow._viewers.pop() -def test_viewer_show(): +@pytest.mark.parametrize( + "order", [-1, 0], +) +def test_viewer_show(order): class TestViewer(ImageShow.Viewer): - methodCalled = False - def show_image(self, image, **options): self.methodCalled = True return True viewer = TestViewer() - ImageShow.register(viewer, -1) + ImageShow.register(viewer, order) for mode in ("1", "I;16", "LA", "RGB", "RGBA"): - with hopper() as im: + viewer.methodCalled = False + with hopper(mode) as im: assert ImageShow.show(im) assert viewer.methodCalled diff --git a/src/PIL/ImageShow.py b/src/PIL/ImageShow.py index fc5089423..cd85e81b4 100644 --- a/src/PIL/ImageShow.py +++ b/src/PIL/ImageShow.py @@ -31,7 +31,7 @@ def register(viewer, order=1): pass # raised if viewer wasn't a class if order > 0: _viewers.append(viewer) - elif order < 0: + else: _viewers.insert(0, viewer)