Checks for reference counting leaks during cleanup. Using explicit reference counts lead to occasional false positives (at least in parallel test setups). This test now should still test leaks correctly when run e.g. with pytest-valgrind or pytest-leaks
(in_dtype, buf_dtype, steps)
| 3209 | ]) |
| 3210 | @pytest.mark.parametrize("steps", [1, 2, 3]) |
| 3211 | def test_partial_iteration_cleanup(in_dtype, buf_dtype, steps): |
| 3212 | """ |
| 3213 | Checks for reference counting leaks during cleanup. Using explicit |
| 3214 | reference counts lead to occasional false positives (at least in parallel |
| 3215 | test setups). This test now should still test leaks correctly when |
| 3216 | run e.g. with pytest-valgrind or pytest-leaks |
| 3217 | """ |
| 3218 | value = 2**30 + 1 # just a random value that Python won't intern |
| 3219 | arr = np.full(int(np.BUFSIZE * 2.5), value).astype(in_dtype) |
| 3220 | |
| 3221 | it = np.nditer(arr, op_dtypes=[np.dtype(buf_dtype)], |
| 3222 | flags=["buffered", "external_loop", "refs_ok"], casting="unsafe") |
| 3223 | for step in range(steps): |
| 3224 | # The iteration finishes in 3 steps, the first two are partial |
| 3225 | next(it) |
| 3226 | |
| 3227 | del it # not necessary, but we test the cleanup |
| 3228 | |
| 3229 | # Repeat the test with `iternext` |
| 3230 | it = np.nditer(arr, op_dtypes=[np.dtype(buf_dtype)], |
| 3231 | flags=["buffered", "external_loop", "refs_ok"], casting="unsafe") |
| 3232 | for step in range(steps): |
| 3233 | it.iternext() |
| 3234 | |
| 3235 | del it # not necessary, but we test the cleanup |
| 3236 | |
| 3237 | @pytest.mark.skipif(not HAS_REFCOUNT, reason="Python lacks refcounts") |
| 3238 | @pytest.mark.parametrize(["in_dtype", "buf_dtype"], |