MCPcopy Create free account
hub / github.com/numpy/numpy / test_set_policy

Function test_set_policy

numpy/core/tests/test_mem_policy.py:222–247  ·  view source on GitHub ↗
(get_module)

Source from the content-addressed store, hash-verified

220
221@pytest.mark.skipif(sys.version_info >= (3, 12), reason="no numpy.distutils")
222def test_set_policy(get_module):
223
224 get_handler_name = np.core.multiarray.get_handler_name
225 get_handler_version = np.core.multiarray.get_handler_version
226 orig_policy_name = get_handler_name()
227
228 a = np.arange(10).reshape((2, 5)) # a doesn't own its own data
229 assert get_handler_name(a) is None
230 assert get_handler_version(a) is None
231 assert get_handler_name(a.base) == orig_policy_name
232 assert get_handler_version(a.base) == 1
233
234 orig_policy = get_module.set_secret_data_policy()
235
236 b = np.arange(10).reshape((2, 5)) # b doesn't own its own data
237 assert get_handler_name(b) is None
238 assert get_handler_version(b) is None
239 assert get_handler_name(b.base) == 'secret_data_allocator'
240 assert get_handler_version(b.base) == 1
241
242 if orig_policy_name == 'default_allocator':
243 get_module.set_old_policy(None) # tests PyDataMem_SetHandler(NULL)
244 assert get_handler_name() == 'default_allocator'
245 else:
246 get_module.set_old_policy(orig_policy)
247 assert get_handler_name() == orig_policy_name
248
249
250@pytest.mark.skipif(sys.version_info >= (3, 12), reason="no numpy.distutils")

Callers

nothing calls this directly

Calls 3

get_handler_nameFunction · 0.85
get_handler_versionFunction · 0.85
reshapeMethod · 0.80

Tested by

no test coverage detected