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