@@ -357,24 +357,39 @@ def test_new_policy(get_module):
357
357
c = np .arange (10 )
358
358
assert np .core .multiarray .get_handler_name (c ) == orig_policy_name
359
359
360
- def test_switch_owner (get_module ):
360
+ @pytest .mark .xfail (sys .implementation .name == "pypy" ,
361
+ reason = ("bad interaction between getenv and "
362
+ "os.environ inside pytest" ))
363
+ @pytest .mark .parametrize ("policy" , ["0" , "1" , None ])
364
+ def test_switch_owner (get_module , policy ):
361
365
a = get_module .get_array ()
362
366
assert np .core .multiarray .get_handler_name (a ) is None
363
367
get_module .set_own (a )
364
368
oldval = os .environ .get ('NUMPY_WARN_IF_NO_MEM_POLICY' , None )
365
- os .environ ['NUMPY_WARN_IF_NO_MEM_POLICY' ] = "1"
369
+ if policy is None :
370
+ if 'NUMPY_WARN_IF_NO_MEM_POLICY' in os .environ :
371
+ os .environ .pop ('NUMPY_WARN_IF_NO_MEM_POLICY' )
372
+ else :
373
+ os .environ ['NUMPY_WARN_IF_NO_MEM_POLICY' ] = policy
366
374
try :
367
375
# The policy should be NULL, so we have to assume we can call
368
- # "free"
369
- with assert_warns (RuntimeWarning ) as w :
376
+ # "free". A warning is given if the policy == "1"
377
+ if policy == "1" :
378
+ with assert_warns (RuntimeWarning ) as w :
379
+ del a
380
+ gc .collect ()
381
+ else :
370
382
del a
371
383
gc .collect ()
384
+
372
385
finally :
373
386
if oldval is None :
374
- os .environ .pop ('NUMPY_WARN_IF_NO_MEM_POLICY' )
387
+ if 'NUMPY_WARN_IF_NO_MEM_POLICY' in os .environ :
388
+ os .environ .pop ('NUMPY_WARN_IF_NO_MEM_POLICY' )
375
389
else :
376
390
os .environ ['NUMPY_WARN_IF_NO_MEM_POLICY' ] = oldval
377
391
392
+ def test_owner_is_base (get_module ):
378
393
a = get_module .get_array_with_base ()
379
394
with pytest .warns (UserWarning , match = 'warn_on_free' ):
380
395
del a
0 commit comments