Debian Codegraph @

jedi/third_party/typeshed/stdlib/doctest.pyi

raw symbols SCIP
1 import sys
2 import types
3 import unittest
4 from _typeshed import ExcInfo
5 from collections.abc import Callable
6 from typing import Any, Final, NamedTuple, type_check_only
7 from typing_extensions import Self, TypeAlias
8
9 __all__ = [
10 "register_optionflag",
11 "DONT_ACCEPT_TRUE_FOR_1",
12 "DONT_ACCEPT_BLANKLINE",
13 "NORMALIZE_WHITESPACE",
14 "ELLIPSIS",
15 "SKIP",
16 "IGNORE_EXCEPTION_DETAIL",
17 "COMPARISON_FLAGS",
18 "REPORT_UDIFF",
19 "REPORT_CDIFF",
20 "REPORT_NDIFF",
21 "REPORT_ONLY_FIRST_FAILURE",
22 "REPORTING_FLAGS",
23 "FAIL_FAST",
24 "Example",
25 "DocTest",
26 "DocTestParser",
27 "DocTestFinder",
28 "DocTestRunner",
29 "OutputChecker",
30 "DocTestFailure",
31 "UnexpectedException",
32 "DebugRunner",
33 "testmod",
34 "testfile",
35 "run_docstring_examples",
36 "DocTestSuite",
37 "DocFileSuite",
38 "set_unittest_reportflags",
39 "script_from_examples",
40 "testsource",
41 "debug_src",
42 "debug",
43 ]
44
45 if sys.version_info >= (3, 13):
46 @type_check_only
47 class _TestResultsBase(NamedTuple):
48 failed: int
49 attempted: int
50
51 class TestResults(_TestResultsBase):
52 def __new__(cls, failed: int, attempted: int, *, skipped: int = 0) -> Self: ...
53 skipped: int
54
55 else:
56 class TestResults(NamedTuple):
57 failed: int
58 attempted: int
59
60 OPTIONFLAGS_BY_NAME: Final[dict[str, int]]
61
62 def register_optionflag(name: str) -> int: ...
63
64 DONT_ACCEPT_TRUE_FOR_1: Final = 1
65 DONT_ACCEPT_BLANKLINE: Final = 2
66 NORMALIZE_WHITESPACE: Final = 4
67 ELLIPSIS: Final = 8
68 SKIP: Final = 16
69 IGNORE_EXCEPTION_DETAIL: Final = 32
70
71 COMPARISON_FLAGS: Final = 63
72
73 REPORT_UDIFF: Final = 64
74 REPORT_CDIFF: Final = 128
75 REPORT_NDIFF: Final = 256
76 REPORT_ONLY_FIRST_FAILURE: Final = 512
77 FAIL_FAST: Final = 1024
78
79 REPORTING_FLAGS: Final = 1984
80
81 BLANKLINE_MARKER: Final = "<BLANKLINE>"
82 ELLIPSIS_MARKER: Final = "..."
83
84 class Example:
85 source: str
86 want: str
87 exc_msg: str | None
88 lineno: int
89 indent: int
90 options: dict[int, bool]
91 def __init__(
92 self,
93 source: str,
94 want: str,
95 exc_msg: str | None = None,
96 lineno: int = 0,
97 indent: int = 0,
98 options: dict[int, bool] | None = None,
99 ) -> None: ...
100 def __hash__(self) -> int: ...
101 def __eq__(self, other: object) -> bool: ...
102
103 class DocTest:
104 examples: list[Example]
105 globs: dict[str, Any]
106 name: str
107 filename: str | None
108 lineno: int | None
109 docstring: str | None
110 def __init__(
111 self,
112 examples: list[Example],
113 globs: dict[str, Any],
114 name: str,
115 filename: str | None,
116 lineno: int | None,
117 docstring: str | None,
118 ) -> None: ...
119 def __hash__(self) -> int: ...
120 def __lt__(self, other: DocTest) -> bool: ...
121 def __eq__(self, other: object) -> bool: ...
122
123 class DocTestParser:
124 def parse(self, string: str, name: str = "<string>") -> list[str | Example]: ...
125 def get_doctest(self, string: str, globs: dict[str, Any], name: str, filename: str | None, lineno: int | None) -> DocTest: ...
126 def get_examples(self, string: str, name: str = "<string>") -> list[Example]: ...
127
128 class DocTestFinder:
129 def __init__(
130 self, verbose: bool = False, parser: DocTestParser = ..., recurse: bool = True, exclude_empty: bool = True
131 ) -> None: ...
132 def find(
133 self,
134 obj: object,
135 name: str | None = None,
136 module: None | bool | types.ModuleType = None,
137 globs: dict[str, Any] | None = None,
138 extraglobs: dict[str, Any] | None = None,
139 ) -> list[DocTest]: ...
140
141 _Out: TypeAlias = Callable[[str], object]
142
143 class DocTestRunner:
144 DIVIDER: str
145 optionflags: int
146 original_optionflags: int
147 tries: int
148 failures: int
149 if sys.version_info >= (3, 13):
150 skips: int
151 test: DocTest
152 def __init__(self, checker: OutputChecker | None = None, verbose: bool | None = None, optionflags: int = 0) -> None: ...
153 def report_start(self, out: _Out, test: DocTest, example: Example) -> None: ...
154 def report_success(self, out: _Out, test: DocTest, example: Example, got: str) -> None: ...
155 def report_failure(self, out: _Out, test: DocTest, example: Example, got: str) -> None: ...
156 def report_unexpected_exception(self, out: _Out, test: DocTest, example: Example, exc_info: ExcInfo) -> None: ...
157 def run(
158 self, test: DocTest, compileflags: int | None = None, out: _Out | None = None, clear_globs: bool = True
159 ) -> TestResults: ...
160 def summarize(self, verbose: bool | None = None) -> TestResults: ...
161 def merge(self, other: DocTestRunner) -> None: ...
162
163 class OutputChecker:
164 def check_output(self, want: str, got: str, optionflags: int) -> bool: ...
165 def output_difference(self, example: Example, got: str, optionflags: int) -> str: ...
166
167 class DocTestFailure(Exception):
168 test: DocTest
169 example: Example
170 got: str
171 def __init__(self, test: DocTest, example: Example, got: str) -> None: ...
172
173 class UnexpectedException(Exception):
174 test: DocTest
175 example: Example
176 exc_info: ExcInfo
177 def __init__(self, test: DocTest, example: Example, exc_info: ExcInfo) -> None: ...
178
179 class DebugRunner(DocTestRunner): ...
180
181 master: DocTestRunner | None
182
183 def testmod(
184 m: types.ModuleType | None = None,
185 name: str | None = None,
186 globs: dict[str, Any] | None = None,
187 verbose: bool | None = None,
188 report: bool = True,
189 optionflags: int = 0,
190 extraglobs: dict[str, Any] | None = None,
191 raise_on_error: bool = False,
192 exclude_empty: bool = False,
193 ) -> TestResults: ...
194 def testfile(
195 filename: str,
196 module_relative: bool = True,
197 name: str | None = None,
198 package: None | str | types.ModuleType = None,
199 globs: dict[str, Any] | None = None,
200 verbose: bool | None = None,
201 report: bool = True,
202 optionflags: int = 0,
203 extraglobs: dict[str, Any] | None = None,
204 raise_on_error: bool = False,
205 parser: DocTestParser = ...,
206 encoding: str | None = None,
207 ) -> TestResults: ...
208 def run_docstring_examples(
209 f: object,
210 globs: dict[str, Any],
211 verbose: bool = False,
212 name: str = "NoName",
213 compileflags: int | None = None,
214 optionflags: int = 0,
215 ) -> None: ...
216 def set_unittest_reportflags(flags: int) -> int: ...
217
218 class DocTestCase(unittest.TestCase):
219 def __init__(
220 self,
221 test: DocTest,
222 optionflags: int = 0,
223 setUp: Callable[[DocTest], object] | None = None,
224 tearDown: Callable[[DocTest], object] | None = None,
225 checker: OutputChecker | None = None,
226 ) -> None: ...
227 def runTest(self) -> None: ...
228 def format_failure(self, err: str) -> str: ...
229 def __hash__(self) -> int: ...
230 def __eq__(self, other: object) -> bool: ...
231
232 class SkipDocTestCase(DocTestCase):
233 def __init__(self, module: types.ModuleType) -> None: ...
234 def test_skip(self) -> None: ...
235
236 class _DocTestSuite(unittest.TestSuite): ...
237
238 def DocTestSuite(
239 module: None | str | types.ModuleType = None,
240 globs: dict[str, Any] | None = None,
241 extraglobs: dict[str, Any] | None = None,
242 test_finder: DocTestFinder | None = None,
243 **options: Any,
244 ) -> _DocTestSuite: ...
245
246 class DocFileCase(DocTestCase): ...
247
248 def DocFileTest(
249 path: str,
250 module_relative: bool = True,
251 package: None | str | types.ModuleType = None,
252 globs: dict[str, Any] | None = None,
253 parser: DocTestParser = ...,
254 encoding: str | None = None,
255 **options: Any,
256 ) -> DocFileCase: ...
257 def DocFileSuite(*paths: str, **kw: Any) -> _DocTestSuite: ...
258 def script_from_examples(s: str) -> str: ...
259 def testsource(module: None | str | types.ModuleType, name: str) -> str: ...
260 def debug_src(src: str, pm: bool = False, globs: dict[str, Any] | None = None) -> None: ...
261 def debug_script(src: str, pm: bool = False, globs: dict[str, Any] | None = None) -> None: ...
262 def debug(module: None | str | types.ModuleType, name: str, pm: bool = False) -> None: ...