From 6bfd3bfe8f83db9eb9aef5d337aad6850c070dac Mon Sep 17 00:00:00 2001 From: Alexander Piskun Date: Sun, 3 Jul 2022 18:15:27 +0300 Subject: [PATCH] added `test_open_to_numpy_mem_leaks` --- tests/leaks_test.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/leaks_test.py b/tests/leaks_test.py index 424fbb16..e16e6fab 100644 --- a/tests/leaks_test.py +++ b/tests/leaks_test.py @@ -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()) @@ -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"