REDROOM
PHP 8.2.30
Path:
Logout
Edit File
Size: 3.20 KB
Close
//proc/thread-self/root/opt/cloudlinux/venv/lib/python3.11/site-packages/numpy/typing/tests/test_runtime.py
Text
Base64
"""Test the runtime usage of `numpy.typing`.""" from __future__ import annotations from typing import ( get_type_hints, Union, NamedTuple, get_args, get_origin, Any, ) import pytest import numpy as np import numpy.typing as npt import numpy._typing as _npt class TypeTup(NamedTuple): typ: type args: tuple[type, ...] origin: None | type NDArrayTup = TypeTup(npt.NDArray, npt.NDArray.__args__, np.ndarray) TYPES = { "ArrayLike": TypeTup(npt.ArrayLike, npt.ArrayLike.__args__, Union), "DTypeLike": TypeTup(npt.DTypeLike, npt.DTypeLike.__args__, Union), "NBitBase": TypeTup(npt.NBitBase, (), None), "NDArray": NDArrayTup, } @pytest.mark.parametrize("name,tup", TYPES.items(), ids=TYPES.keys()) def test_get_args(name: type, tup: TypeTup) -> None: """Test `typing.get_args`.""" typ, ref = tup.typ, tup.args out = get_args(typ) assert out == ref @pytest.mark.parametrize("name,tup", TYPES.items(), ids=TYPES.keys()) def test_get_origin(name: type, tup: TypeTup) -> None: """Test `typing.get_origin`.""" typ, ref = tup.typ, tup.origin out = get_origin(typ) assert out == ref @pytest.mark.parametrize("name,tup", TYPES.items(), ids=TYPES.keys()) def test_get_type_hints(name: type, tup: TypeTup) -> None: """Test `typing.get_type_hints`.""" typ = tup.typ # Explicitly set `__annotations__` in order to circumvent the # stringification performed by `from __future__ import annotations` def func(a): pass func.__annotations__ = {"a": typ, "return": None} out = get_type_hints(func) ref = {"a": typ, "return": type(None)} assert out == ref @pytest.mark.parametrize("name,tup", TYPES.items(), ids=TYPES.keys()) def test_get_type_hints_str(name: type, tup: TypeTup) -> None: """Test `typing.get_type_hints` with string-representation of types.""" typ_str, typ = f"npt.{name}", tup.typ # Explicitly set `__annotations__` in order to circumvent the # stringification performed by `from __future__ import annotations` def func(a): pass func.__annotations__ = {"a": typ_str, "return": None} out = get_type_hints(func) ref = {"a": typ, "return": type(None)} assert out == ref def test_keys() -> None: """Test that ``TYPES.keys()`` and ``numpy.typing.__all__`` are synced.""" keys = TYPES.keys() ref = set(npt.__all__) assert keys == ref PROTOCOLS: dict[str, tuple[type[Any], object]] = { "_SupportsDType": (_npt._SupportsDType, np.int64(1)), "_SupportsArray": (_npt._SupportsArray, np.arange(10)), "_SupportsArrayFunc": (_npt._SupportsArrayFunc, np.arange(10)), "_NestedSequence": (_npt._NestedSequence, [1]), } @pytest.mark.parametrize("cls,obj", PROTOCOLS.values(), ids=PROTOCOLS.keys()) class TestRuntimeProtocol: def test_isinstance(self, cls: type[Any], obj: object) -> None: assert isinstance(obj, cls) assert not isinstance(None, cls) def test_issubclass(self, cls: type[Any], obj: object) -> None: if cls is _npt._SupportsDType: pytest.xfail( "Protocols with non-method members don't support issubclass()" ) assert issubclass(type(obj), cls) assert not issubclass(type(None), cls)
Save
Close
Exit & Reset
Text mode: syntax highlighting auto-detects file type.
Directory Contents
Dirs: 2 × Files: 4
Delete Selected
Select All
Select None
Sort:
Name
Size
Modified
Enable drag-to-move
Name
Size
Perms
Modified
Actions
data
DIR
-
drwxr-xr-x
2026-02-06 08:01:08
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
__pycache__
DIR
-
drwxr-xr-x
2026-02-06 08:01:08
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
test_isfile.py
812 B
lrw-r--r--
2026-01-20 13:01:47
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
test_runtime.py
3.20 KB
lrw-r--r--
2026-01-20 13:01:47
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
test_typing.py
14.95 KB
lrw-r--r--
2026-01-20 13:01:47
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
__init__.py
0 B
lrw-r--r--
2026-01-20 13:01:47
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Zip Selected
If ZipArchive is unavailable, a
.tar
will be created (no compression).