MCPcopy Index your code
hub / github.com/numpy/numpy / test_import_lazy_import

Function test_import_lazy_import

numpy/tests/test_public_api.py:51–69  ·  view source on GitHub ↗

Make sure we can actually use the modules we lazy load. While not exported as part of the public API, it was accessible. With the use of __getattr__ and __dir__, this isn't always true It can happen that an infinite recursion may happen. This is the only way I found that would for

(name)

Source from the content-addressed store, hash-verified

49@pytest.mark.skipif(IS_WASM, reason="can't start subprocess")
50@pytest.mark.parametrize('name', ['testing'])
51def test_import_lazy_import(name):
52 """Make sure we can actually use the modules we lazy load.
53
54 While not exported as part of the public API, it was accessible. With the
55 use of __getattr__ and __dir__, this isn't always true It can happen that
56 an infinite recursion may happen.
57
58 This is the only way I found that would force the failure to appear on the
59 badly implemented code.
60
61 We also test for the presence of the lazily imported modules in dir
62
63 """
64 exe = (sys.executable, '-c', "import numpy; numpy." + name)
65 result = run_subprocess(exe)
66 assert not result.stdout
67
68 # Make sure they are still in the __dir__
69 assert name in dir(np)
70
71
72def test_dir_testing():

Callers

nothing calls this directly

Calls 1

run_subprocessFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…