Skip to content

Commit

Permalink
Always return fresh not-yet-loaded image for hopper(None)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Mar 31, 2024
1 parent 199bff3 commit ed5cd18
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions Tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,20 +255,22 @@ def hopper(mode: str | None = None) -> Image.Image:
# Use caching to reduce reading from disk, but return a copy
# so that the cached image isn't modified by the tests
# (for fast, isolated, repeatable tests).
return _cached_hopper(mode).copy()


@lru_cache(maxsize=None)
def _cached_hopper(mode: str | None = None) -> Image.Image:
if mode is None:
# Always return fresh not-yet-loaded version of image.
# Operations on not-yet-loaded images is separate class of errors
# what we should catch.
return Image.open("Tests/images/hopper.ppm")

return _cached_hopper(mode).copy()


@lru_cache(maxsize=None)
def _cached_hopper(mode: str | None = None) -> Image.Image:
if mode == "F":
im = _cached_hopper("L").convert(mode)
im = hopper("L").convert(mode)
else:
im = _cached_hopper().convert(mode)
im = hopper().convert(mode)
return im


Expand Down

0 comments on commit ed5cd18

Please sign in to comment.