1from typing import Any, Callable, Dict, List, NamedTuple, Optional, Tuple, Type, Union
2
3import sys
4import types
5import unittest
6
7class TestResults(NamedTuple):
8    failed: int
9    attempted: int
10
11OPTIONFLAGS_BY_NAME: Dict[str, int]
12def register_optionflag(name: str) -> int: ...
13DONT_ACCEPT_TRUE_FOR_1: int
14DONT_ACCEPT_BLANKLINE: int
15NORMALIZE_WHITESPACE: int
16ELLIPSIS: int
17SKIP: int
18IGNORE_EXCEPTION_DETAIL: int
19
20COMPARISON_FLAGS: int
21
22REPORT_UDIFF: int
23REPORT_CDIFF: int
24REPORT_NDIFF: int
25REPORT_ONLY_FIRST_FAILURE: int
26if sys.version_info >= (3, 4):
27    FAIL_FAST: int
28
29REPORTING_FLAGS: int
30
31BLANKLINE_MARKER: str
32ELLIPSIS_MARKER: str
33
34class Example:
35    source: str
36    want: str
37    exc_msg: Optional[str]
38    lineno: int
39    indent: int
40    options: Dict[int, bool]
41    def __init__(self, source: str, want: str, exc_msg: Optional[str] = ..., lineno: int = ..., indent: int = ...,
42                 options: Optional[Dict[int, bool]] = ...) -> None: ...
43    def __hash__(self) -> int: ...
44
45class DocTest:
46    examples: List[Example]
47    globs: Dict[str, Any]
48    name: str
49    filename: Optional[str]
50    lineno: Optional[int]
51    docstring: Optional[str]
52    def __init__(self, examples: List[Example], globs: Dict[str, Any], name: str, filename: Optional[str], lineno: Optional[int], docstring: Optional[str]) -> None: ...
53    def __hash__(self) -> int: ...
54    def __lt__(self, other: DocTest) -> bool: ...
55
56class DocTestParser:
57    def parse(self, string: str, name: str = ...) -> List[Union[str, Example]]: ...
58    def get_doctest(self, string: str, globs: Dict[str, Any], name: str, filename: Optional[str], lineno: Optional[int]) -> DocTest: ...
59    def get_examples(self, string: str, name: str = ...) -> List[Example]: ...
60
61class DocTestFinder:
62    def __init__(self, verbose: bool = ..., parser: DocTestParser = ...,
63                 recurse: bool = ..., exclude_empty: bool = ...) -> None: ...
64    def find(self, obj: object, name: Optional[str] = ..., module: Union[None, bool, types.ModuleType] = ...,
65             globs: Optional[Dict[str, Any]] = ..., extraglobs: Optional[Dict[str, Any]] = ...) -> List[DocTest]: ...
66
67_Out = Callable[[str], Any]
68_ExcInfo = Tuple[Type[BaseException], BaseException, types.TracebackType]
69
70class DocTestRunner:
71    DIVIDER: str
72    optionflags: int
73    original_optionflags: int
74    tries: int
75    failures: int
76    test: DocTest
77
78    def __init__(self, checker: Optional[OutputChecker] = ..., verbose: Optional[bool] = ..., optionflags: int = ...) -> None: ...
79    def report_start(self, out: _Out, test: DocTest, example: Example) -> None: ...
80    def report_success(self, out: _Out, test: DocTest, example: Example, got: str) -> None: ...
81    def report_failure(self, out: _Out, test: DocTest, example: Example, got: str) -> None: ...
82    def report_unexpected_exception(self, out: _Out, test: DocTest, example: Example, exc_info: _ExcInfo) -> None: ...
83    def run(self, test: DocTest, compileflags: Optional[int] = ..., out: Optional[_Out] = ..., clear_globs: bool = ...) -> TestResults: ...
84    def summarize(self, verbose: Optional[bool] = ...) -> TestResults: ...
85    def merge(self, other: DocTestRunner) -> None: ...
86
87class OutputChecker:
88    def check_output(self, want: str, got: str, optionflags: int) -> bool: ...
89    def output_difference(self, example: Example, got: str, optionflags: int) -> str: ...
90
91class DocTestFailure(Exception):
92    test: DocTest
93    example: Example
94    got: str
95
96    def __init__(self, test: DocTest, example: Example, got: str) -> None: ...
97
98class UnexpectedException(Exception):
99    test: DocTest
100    example: Example
101    exc_info: _ExcInfo
102
103    def __init__(self, test: DocTest, example: Example, exc_info: _ExcInfo) -> None: ...
104
105class DebugRunner(DocTestRunner): ...
106
107master: Optional[DocTestRunner]
108
109def testmod(m: Optional[types.ModuleType] = ..., name: Optional[str] = ..., globs: Optional[Dict[str, Any]] = ..., verbose: Optional[bool] = ...,
110            report: bool = ..., optionflags: int = ..., extraglobs: Optional[Dict[str, Any]] = ...,
111            raise_on_error: bool = ..., exclude_empty: bool = ...) -> TestResults: ...
112def testfile(filename: str, module_relative: bool = ..., name: Optional[str] = ..., package: Union[None, str, types.ModuleType] = ...,
113             globs: Optional[Dict[str, Any]] = ..., verbose: Optional[bool] = ..., report: bool = ..., optionflags: int = ...,
114             extraglobs: Optional[Dict[str, Any]] = ..., raise_on_error: bool = ..., parser: DocTestParser = ...,
115             encoding: Optional[str] = ...) -> TestResults: ...
116def run_docstring_examples(f: object, globs: Dict[str, Any], verbose: bool = ..., name: str = ...,
117                           compileflags: Optional[int] = ..., optionflags: int = ...) -> None: ...
118def set_unittest_reportflags(flags: int) -> int: ...
119
120class DocTestCase(unittest.TestCase):
121    def __init__(self, test: DocTest, optionflags: int = ..., setUp: Optional[Callable[[DocTest], Any]] = ...,
122                 tearDown: Optional[Callable[[DocTest], Any]] = ...,
123                 checker: Optional[OutputChecker] = ...) -> None: ...
124    def setUp(self) -> None: ...
125    def tearDown(self) -> None: ...
126    def runTest(self) -> None: ...
127    def format_failure(self, err: str) -> str: ...
128    def debug(self) -> None: ...
129    def id(self) -> str: ...
130    def __hash__(self) -> int: ...
131    def shortDescription(self) -> str: ...
132
133class SkipDocTestCase(DocTestCase):
134    def __init__(self, module: types.ModuleType) -> None: ...
135    def setUp(self) -> None: ...
136    def test_skip(self) -> None: ...
137    def shortDescription(self) -> str: ...
138
139if sys.version_info >= (3, 4):
140    class _DocTestSuite(unittest.TestSuite): ...
141else:
142    _DocTestSuite = unittest.TestSuite
143
144def DocTestSuite(module: Union[None, str, types.ModuleType] = ..., globs: Optional[Dict[str, Any]] = ...,
145                 extraglobs: Optional[Dict[str, Any]] = ..., test_finder: Optional[DocTestFinder] = ...,
146                 **options: Any) -> _DocTestSuite: ...
147
148class DocFileCase(DocTestCase):
149    def id(self) -> str: ...
150    def format_failure(self, err: str) -> str: ...
151
152def DocFileTest(path: str, module_relative: bool = ..., package: Union[None, str, types.ModuleType] = ...,
153                globs: Optional[Dict[str, Any]] = ..., parser: DocTestParser = ...,
154                encoding: Optional[str] = ..., **options: Any) -> DocFileCase: ...
155def DocFileSuite(*paths: str, **kw: Any) -> _DocTestSuite: ...
156def script_from_examples(s: str) -> str: ...
157def testsource(module: Union[None, str, types.ModuleType], name: str) -> str: ...
158def debug_src(src: str, pm: bool = ..., globs: Optional[Dict[str, Any]] = ...) -> None: ...
159def debug_script(src: str, pm: bool = ..., globs: Optional[Dict[str, Any]] = ...) -> None: ...
160def debug(module: Union[None, str, types.ModuleType], name: str, pm: bool = ...) -> None: ...
161