PHP 8.2.30
Preview: test_lazyloading.py Size: 1.13 KB
//opt/cloudlinux/venv/lib/python3.11/site-packages/numpy/tests/test_lazyloading.py

import sys
import importlib
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

        # test triggering the import of the package
        np.ndarray

    finally:
        if old_numpy:
            sys.modules["numpy"] = old_numpy
            sys.modules.update(numpy_modules)

Directory Contents

Dirs: 1 × Files: 11

Name Size Perms Modified Actions
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
12.00 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
1.13 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
1.81 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
1.21 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
1.54 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
16.48 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
2.30 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
1.61 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
2.23 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
221 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
0 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).