()
| 36 | |
| 37 | @pytest.mark.skipif(not HAS_REFCOUNT, reason="Python lacks refcounts") |
| 38 | def test_iter_refcount(): |
| 39 | # Make sure the iterator doesn't leak |
| 40 | |
| 41 | # Basic |
| 42 | a = arange(6) |
| 43 | dt = np.dtype('f4').newbyteorder() |
| 44 | rc_a = sys.getrefcount(a) |
| 45 | rc_dt = sys.getrefcount(dt) |
| 46 | with nditer(a, [], |
| 47 | [['readwrite', 'updateifcopy']], |
| 48 | casting='unsafe', |
| 49 | op_dtypes=[dt]) as it: |
| 50 | assert_(not it.iterationneedsapi) |
| 51 | assert_(sys.getrefcount(a) > rc_a) |
| 52 | assert_(sys.getrefcount(dt) > rc_dt) |
| 53 | # del 'it' |
| 54 | it = None |
| 55 | assert_equal(sys.getrefcount(a), rc_a) |
| 56 | assert_equal(sys.getrefcount(dt), rc_dt) |
| 57 | |
| 58 | # With a copy |
| 59 | a = arange(6, dtype='f4') |
| 60 | dt = np.dtype('f4') |
| 61 | rc_a = sys.getrefcount(a) |
| 62 | rc_dt = sys.getrefcount(dt) |
| 63 | it = nditer(a, [], |
| 64 | [['readwrite']], |
| 65 | op_dtypes=[dt]) |
| 66 | rc2_a = sys.getrefcount(a) |
| 67 | rc2_dt = sys.getrefcount(dt) |
| 68 | it2 = it.copy() |
| 69 | assert_(sys.getrefcount(a) > rc2_a) |
| 70 | assert_(sys.getrefcount(dt) > rc2_dt) |
| 71 | it = None |
| 72 | assert_equal(sys.getrefcount(a), rc2_a) |
| 73 | assert_equal(sys.getrefcount(dt), rc2_dt) |
| 74 | it2 = None |
| 75 | assert_equal(sys.getrefcount(a), rc_a) |
| 76 | assert_equal(sys.getrefcount(dt), rc_dt) |
| 77 | |
| 78 | del it2 # avoid pyflakes unused variable warning |
| 79 | |
| 80 | def test_iter_best_order(): |
| 81 | # The iterator should always find the iteration order |
nothing calls this directly
no test coverage detected