forked from numpy/numpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testing.pyi
173 lines (129 loc) · 8.6 KB
/
testing.pyi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
from __future__ import annotations
import re
import sys
from typing import Any, Callable, TypeVar
from pathlib import Path
import numpy as np
import numpy.typing as npt
AR_f8: npt.NDArray[np.float64]
AR_i8: npt.NDArray[np.int64]
bool_obj: bool
suppress_obj: np.testing.suppress_warnings
FT = TypeVar("FT", bound=Callable[..., Any])
def func() -> int: ...
def func2(
x: npt.NDArray[np.number[Any]],
y: npt.NDArray[np.number[Any]],
) -> npt.NDArray[np.bool_]: ...
reveal_type(np.testing.KnownFailureException()) # E: KnownFailureException
reveal_type(np.testing.IgnoreException()) # E: IgnoreException
reveal_type(np.testing.clear_and_catch_warnings(modules=[np.testing])) # E: _clear_and_catch_warnings_without_records
reveal_type(np.testing.clear_and_catch_warnings(True)) # E: _clear_and_catch_warnings_with_records
reveal_type(np.testing.clear_and_catch_warnings(False)) # E: _clear_and_catch_warnings_without_records
reveal_type(np.testing.clear_and_catch_warnings(bool_obj)) # E: clear_and_catch_warnings
reveal_type(np.testing.clear_and_catch_warnings.class_modules) # E: tuple[types.ModuleType, ...]
reveal_type(np.testing.clear_and_catch_warnings.modules) # E: set[types.ModuleType]
with np.testing.clear_and_catch_warnings(True) as c1:
reveal_type(c1) # E: builtins.list[warnings.WarningMessage]
with np.testing.clear_and_catch_warnings() as c2:
reveal_type(c2) # E: None
reveal_type(np.testing.suppress_warnings("once")) # E: suppress_warnings
reveal_type(np.testing.suppress_warnings()(func)) # E: def () -> builtins.int
reveal_type(suppress_obj.filter(RuntimeWarning)) # E: None
reveal_type(suppress_obj.record(RuntimeWarning)) # E: list[warnings.WarningMessage]
with suppress_obj as c3:
reveal_type(c3) # E: suppress_warnings
reveal_type(np.testing.verbose) # E: int
reveal_type(np.testing.IS_PYPY) # E: bool
reveal_type(np.testing.HAS_REFCOUNT) # E: bool
reveal_type(np.testing.HAS_LAPACK64) # E: bool
reveal_type(np.testing.assert_(1, msg="test")) # E: None
reveal_type(np.testing.assert_(2, msg=lambda: "test")) # E: None
if sys.platform == "win32" or sys.platform == "cygwin":
reveal_type(np.testing.memusage()) # E: builtins.int
elif sys.platform == "linux":
reveal_type(np.testing.memusage()) # E: Union[None, builtins.int]
else:
reveal_type(np.testing.memusage()) # E: <nothing>
reveal_type(np.testing.jiffies()) # E: builtins.int
reveal_type(np.testing.build_err_msg([0, 1, 2], "test")) # E: str
reveal_type(np.testing.build_err_msg(range(2), "test", header="header")) # E: str
reveal_type(np.testing.build_err_msg(np.arange(9).reshape(3, 3), "test", verbose=False)) # E: str
reveal_type(np.testing.build_err_msg("abc", "test", names=["x", "y"])) # E: str
reveal_type(np.testing.build_err_msg([1.0, 2.0], "test", precision=5)) # E: str
reveal_type(np.testing.assert_equal({1}, {1})) # E: None
reveal_type(np.testing.assert_equal([1, 2, 3], [1, 2, 3], err_msg="fail")) # E: None
reveal_type(np.testing.assert_equal(1, 1.0, verbose=True)) # E: None
reveal_type(np.testing.print_assert_equal('Test XYZ of func xyz', [0, 1], [0, 1])) # E: None
reveal_type(np.testing.assert_almost_equal(1.0, 1.1)) # E: None
reveal_type(np.testing.assert_almost_equal([1, 2, 3], [1, 2, 3], err_msg="fail")) # E: None
reveal_type(np.testing.assert_almost_equal(1, 1.0, verbose=True)) # E: None
reveal_type(np.testing.assert_almost_equal(1, 1.0001, decimal=2)) # E: None
reveal_type(np.testing.assert_approx_equal(1.0, 1.1)) # E: None
reveal_type(np.testing.assert_approx_equal("1", "2", err_msg="fail")) # E: None
reveal_type(np.testing.assert_approx_equal(1, 1.0, verbose=True)) # E: None
reveal_type(np.testing.assert_approx_equal(1, 1.0001, significant=2)) # E: None
reveal_type(np.testing.assert_array_compare(func2, AR_i8, AR_f8, err_msg="test")) # E: None
reveal_type(np.testing.assert_array_compare(func2, AR_i8, AR_f8, verbose=True)) # E: None
reveal_type(np.testing.assert_array_compare(func2, AR_i8, AR_f8, header="header")) # E: None
reveal_type(np.testing.assert_array_compare(func2, AR_i8, AR_f8, precision=np.int64())) # E: None
reveal_type(np.testing.assert_array_compare(func2, AR_i8, AR_f8, equal_nan=False)) # E: None
reveal_type(np.testing.assert_array_compare(func2, AR_i8, AR_f8, equal_inf=True)) # E: None
reveal_type(np.testing.assert_array_equal(AR_i8, AR_f8)) # E: None
reveal_type(np.testing.assert_array_equal(AR_i8, AR_f8, err_msg="test")) # E: None
reveal_type(np.testing.assert_array_equal(AR_i8, AR_f8, verbose=True)) # E: None
reveal_type(np.testing.assert_array_almost_equal(AR_i8, AR_f8)) # E: None
reveal_type(np.testing.assert_array_almost_equal(AR_i8, AR_f8, err_msg="test")) # E: None
reveal_type(np.testing.assert_array_almost_equal(AR_i8, AR_f8, verbose=True)) # E: None
reveal_type(np.testing.assert_array_almost_equal(AR_i8, AR_f8, decimal=1)) # E: None
reveal_type(np.testing.assert_array_less(AR_i8, AR_f8)) # E: None
reveal_type(np.testing.assert_array_less(AR_i8, AR_f8, err_msg="test")) # E: None
reveal_type(np.testing.assert_array_less(AR_i8, AR_f8, verbose=True)) # E: None
reveal_type(np.testing.runstring("1 + 1", {})) # E: Any
reveal_type(np.testing.runstring("int64() + 1", {"int64": np.int64})) # E: Any
reveal_type(np.testing.assert_string_equal("1", "1")) # E: None
reveal_type(np.testing.rundocs()) # E: None
reveal_type(np.testing.rundocs("test.py")) # E: None
reveal_type(np.testing.rundocs(Path("test.py"), raise_on_error=True)) # E: None
@np.testing.raises(RuntimeError, RuntimeWarning)
def func3(a: int) -> bool: ...
reveal_type(func3) # E: def (a: builtins.int) -> builtins.bool
reveal_type(np.testing.assert_raises(RuntimeWarning)) # E: _AssertRaisesContext[builtins.RuntimeWarning]
reveal_type(np.testing.assert_raises(RuntimeWarning, func3, 5)) # E: None
reveal_type(np.testing.assert_raises_regex(RuntimeWarning, r"test")) # E: _AssertRaisesContext[builtins.RuntimeWarning]
reveal_type(np.testing.assert_raises_regex(RuntimeWarning, b"test", func3, 5)) # E: None
reveal_type(np.testing.assert_raises_regex(RuntimeWarning, re.compile(b"test"), func3, 5)) # E: None
class Test: ...
def decorate(a: FT) -> FT:
return a
reveal_type(np.testing.decorate_methods(Test, decorate)) # E: None
reveal_type(np.testing.decorate_methods(Test, decorate, None)) # E: None
reveal_type(np.testing.decorate_methods(Test, decorate, "test")) # E: None
reveal_type(np.testing.decorate_methods(Test, decorate, b"test")) # E: None
reveal_type(np.testing.decorate_methods(Test, decorate, re.compile("test"))) # E: None
reveal_type(np.testing.measure("for i in range(1000): np.sqrt(i**2)")) # E: float
reveal_type(np.testing.measure(b"for i in range(1000): np.sqrt(i**2)", times=5)) # E: float
reveal_type(np.testing.assert_allclose(AR_i8, AR_f8)) # E: None
reveal_type(np.testing.assert_allclose(AR_i8, AR_f8, rtol=0.005)) # E: None
reveal_type(np.testing.assert_allclose(AR_i8, AR_f8, atol=1)) # E: None
reveal_type(np.testing.assert_allclose(AR_i8, AR_f8, equal_nan=True)) # E: None
reveal_type(np.testing.assert_allclose(AR_i8, AR_f8, err_msg="err")) # E: None
reveal_type(np.testing.assert_allclose(AR_i8, AR_f8, verbose=False)) # E: None
reveal_type(np.testing.assert_array_almost_equal_nulp(AR_i8, AR_f8, nulp=2)) # E: None
reveal_type(np.testing.assert_array_max_ulp(AR_i8, AR_f8, maxulp=2)) # E: ndarray[Any, dtype[Any]]
reveal_type(np.testing.assert_array_max_ulp(AR_i8, AR_f8, dtype=np.float32)) # E: ndarray[Any, dtype[Any]]
reveal_type(np.testing.assert_warns(RuntimeWarning)) # E: _GeneratorContextManager[None]
reveal_type(np.testing.assert_warns(RuntimeWarning, func3, 5)) # E: bool
reveal_type(np.testing.assert_no_warnings()) # E: _GeneratorContextManager[None]
reveal_type(np.testing.assert_no_warnings(func3, 5)) # E: bool
reveal_type(np.testing.tempdir("test_dir")) # E: _GeneratorContextManager[builtins.str]
reveal_type(np.testing.tempdir(prefix=b"test")) # E: _GeneratorContextManager[builtins.bytes]
reveal_type(np.testing.tempdir("test_dir", dir=Path("here"))) # E: _GeneratorContextManager[builtins.str]
reveal_type(np.testing.temppath("test_dir", text=True)) # E: _GeneratorContextManager[builtins.str]
reveal_type(np.testing.temppath(prefix=b"test")) # E: _GeneratorContextManager[builtins.bytes]
reveal_type(np.testing.temppath("test_dir", dir=Path("here"))) # E: _GeneratorContextManager[builtins.str]
reveal_type(np.testing.assert_no_gc_cycles()) # E: _GeneratorContextManager[None]
reveal_type(np.testing.assert_no_gc_cycles(func3, 5)) # E: None
reveal_type(np.testing.break_cycles()) # E: None
reveal_type(np.testing.TestCase()) # E: unittest.case.TestCase
reveal_type(np.testing.run_module_suite(file_to_run="numpy/tests/test_matlib.py")) # E: None