summaryrefslogtreecommitdiff
path: root/.venv/lib/python3.12/site-packages/numpy/tests/test_lazyloading.py
diff options
context:
space:
mode:
authorblackhao <13851610112@163.com>2025-08-22 02:51:50 -0500
committerblackhao <13851610112@163.com>2025-08-22 02:51:50 -0500
commit4aab4087dc97906d0b9890035401175cdaab32d4 (patch)
tree4e2e9d88a711ec5b1cfa02e8ac72a55183b99123 /.venv/lib/python3.12/site-packages/numpy/tests/test_lazyloading.py
parentafa8f50d1d21c721dabcb31ad244610946ab65a3 (diff)
2.0
Diffstat (limited to '.venv/lib/python3.12/site-packages/numpy/tests/test_lazyloading.py')
-rw-r--r--.venv/lib/python3.12/site-packages/numpy/tests/test_lazyloading.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/.venv/lib/python3.12/site-packages/numpy/tests/test_lazyloading.py b/.venv/lib/python3.12/site-packages/numpy/tests/test_lazyloading.py
new file mode 100644
index 0000000..5f6233f
--- /dev/null
+++ b/.venv/lib/python3.12/site-packages/numpy/tests/test_lazyloading.py
@@ -0,0 +1,38 @@
+import sys
+from importlib.util import LazyLoader, find_spec, module_from_spec
+
+import pytest
+
+
+# Warning raised by _reload_guard() in numpy/__init__.py
+@pytest.mark.filterwarnings("ignore:The NumPy module was reloaded")
+def test_lazy_load():
+ # gh-22045. lazyload doesn't import submodule names into the namespace
+ # muck with sys.modules to test the importing system
+ old_numpy = sys.modules.pop("numpy")
+
+ numpy_modules = {}
+ for mod_name, mod in list(sys.modules.items()):
+ if mod_name[:6] == "numpy.":
+ numpy_modules[mod_name] = mod
+ sys.modules.pop(mod_name)
+
+ try:
+ # create lazy load of numpy as np
+ spec = find_spec("numpy")
+ module = module_from_spec(spec)
+ sys.modules["numpy"] = module
+ loader = LazyLoader(spec.loader)
+ loader.exec_module(module)
+ np = module
+
+ # test a subpackage import
+ from numpy.lib import recfunctions # noqa: F401
+
+ # test triggering the import of the package
+ np.ndarray
+
+ finally:
+ if old_numpy:
+ sys.modules["numpy"] = old_numpy
+ sys.modules.update(numpy_modules)