8000 TST: Work around memory leak in ctypes to prevent another test failing · numpy/numpy@63e9cfb · GitHub
[go: up one dir, main page]

Skip to content

Commit 63e9cfb

Browse files
committed
TST: Work around memory leak in ctypes to prevent another test failing
1 parent 056babb commit 63e9cfb

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

numpy/core/tests/test_multiarray.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6522,12 +6522,20 @@ def test_max_dims(self):
65226522
a = np.empty((1,) * 32)
65236523
self._check_roundtrip(a)
65246524

6525+
def _make_ctype(shape, scalar_type):
6526+
t = scalar_type
6527+
for dim in shape[::-1]:
6528+
t = dim * t
6529+
return t
6530+
6531+
# This creates deeply nested reference cycles that cause
6532+
# np.lib.tests.test_io.test_load_refcount to erroneously fail (gh-10891).
6533+
# Not making it a local ensure that the GC doesn't touch it during the tests
6534+
c_u8_33d = _make_ctype((1,)*33, ctypes.c_uint8)
6535+
65256536
def test_error_too_many_dims(self):
65266537
# construct a memoryview with 33 dimensions
6527-
ct = ctypes.c_uint8
6528-
for i in range(33):
6529-
ct = 1 * ct
6530-
m = memoryview(ct())
6538+
m = memoryview(self.c_u8_33d())
65316539
assert_equal(m.ndim, 33)
65326540

65336541
assert_raises_regex(

0 commit comments

Comments
 (0)
0