Skip to content

Commit

Permalink
added test_open_to_numpy_mem_leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
bigcat88 committed Jul 3, 2022
1 parent 4017f34 commit 6bfd3bf
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/leaks_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import pillow_heif

pytest.importorskip("pympler", reason="`pympler` not installed")
pytest.importorskip("numpy", reason="`numpy` not installed")

print(pillow_heif.libheif_info())

Expand Down Expand Up @@ -72,3 +73,23 @@ def test_open_save_leaks(ctx_in_memory):
mem_limit = mem + 1
continue
assert mem <= mem_limit, f"memory usage limit exceeded after {i + 1} iterations"


def perform_open_to_numpy(iterations, image_path):
import numpy as np

for _ in range(iterations):
heif_file = pillow_heif.open_heif(image_path)
_array = np.asarray(heif_file[0]) # noqa


def test_open_to_numpy_mem_leaks():
mem_limit = None
for i in range(1000):
perform_open_to_numpy(1, Path("images/rgb8_512_512_1_0.heic"))
gc.collect()
mem = _get_mem_usage()
if i < 300:
mem_limit = mem + 1
continue
assert mem <= mem_limit, f"memory usage limit exceeded after {i + 1} iterations"

0 comments on commit 6bfd3bf

Please sign in to comment.