From 6ec855e0b7512477fa87dca52f3f3148cce2f643 Mon Sep 17 00:00:00 2001 From: wiredfool Date: Sun, 25 Aug 2024 16:00:08 +0100 Subject: [PATCH] Lifetime check --- Tests/test_arrow.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/Tests/test_arrow.py b/Tests/test_arrow.py index 86309b473..57b22443b 100644 --- a/Tests/test_arrow.py +++ b/Tests/test_arrow.py @@ -63,3 +63,41 @@ def test_to_array(mode: str, dtype: Any, mask: Any ) -> None: arr = pyarrow.array(img) _test_img_equals_pyarray(img, arr, mask) assert arr.type == dtype + + +def test_lifetime(): + # valgrind shouldn't error out here. + # arrays should be accessible after the image is deleted. + + img = hopper('L') + + arr_1 = pyarrow.array(img) + arr_2 = pyarrow.array(img) + + del(img) + + assert arr_1.sum().as_py() > 0 + del(arr_1) + + assert arr_2.sum().as_py() > 0 + del(arr_2) + +def test_lifetime2(): + # valgrind shouldn't error out here. + # img should remain after the arrays are collected. + + img = hopper('L') + + arr_1 = pyarrow.array(img) + arr_2 = pyarrow.array(img) + + + assert arr_1.sum().as_py() > 0 + del(arr_1) + + assert arr_2.sum().as_py() > 0 + del(arr_2) + + img2 = img.copy() + px = img2.load() + assert isinstance(px[0,0], int)