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

Function test_import_lazy_import

numpy/tests/test_public_api.py:67–85  ·  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

65@pytest.mark.skipif(IS_WASM, reason="can't start subprocess")
66@pytest.mark.parametrize('name', ['testing'])
67def test_import_lazy_import(name):
68 """Make sure we can actually use the modules we lazy load.
69
70 While not exported as part of the public API, it was accessible. With the
71 use of __getattr__ and __dir__, this isn't always true It can happen that
72 an infinite recursion may happen.
73
74 This is the only way I found that would force the failure to appear on the
75 badly implemented code.
76
77 We also test for the presence of the lazily imported modules in dir
78
79 """
80 exe = (sys.executable, '-c', "import numpy; numpy." + name)
81 result = subprocess.check_output(exe)
82 assert not result
83
84 # Make sure they are still in the __dir__
85 assert name in dir(np)
86
87
88def test_dir_testing():

Callers

nothing calls this directly

Calls 1

check_outputMethod · 0.45

Tested by

no test coverage detected