@@ -357,24 +357,39 @@ def test_new_policy(get_module):
357357 c = np .arange (10 )
358358 assert np .core .multiarray .get_handler_name (c ) == orig_policy_name
359359
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 ):
361365 a = get_module .get_array ()
362366 assert np .core .multiarray .get_handler_name (a ) is None
363367 get_module .set_own (a )
364368 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
366374 try :
367375 # 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 :
370382 del a
371383 gc .collect ()
384+
372385 finally :
373386 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' )
375389 else :
376390 os .environ ['NUMPY_WARN_IF_NO_MEM_POLICY' ] = oldval
377391
392+ def test_owner_is_base (get_module ):
378393 a = get_module .get_array_with_base ()
379394 with pytest .warns (UserWarning , match = 'warn_on_free' ):
380395 del a
0 commit comments