Prevent register_open from adding duplicates to ID

This commit is contained in:
Andrew Murray 2023-01-28 22:43:04 +11:00
parent 698951e19e
commit 3e37a919b1
2 changed files with 13 additions and 1 deletions

View File

@ -398,6 +398,17 @@ class TestImage:
with pytest.raises(ValueError):
source.alpha_composite(over, (0, 0), (0, -1))
def test_register_open_duplicates(self):
# Arrange
factory, accept = Image.OPEN["JPEG"]
id_length = len(Image.ID)
# Act
Image.register_open("JPEG", factory, accept)
# Assert
assert len(Image.ID) == id_length
def test_registered_extensions_uninitialized(self):
# Arrange
Image._initialized = 0

View File

@ -3406,6 +3406,7 @@ def register_open(id, factory, accept=None):
reject images having another format.
"""
id = id.upper()
if id not in ID:
ID.append(id)
OPEN[id] = factory, accept