Home | History | Annotate | Download | only in Lib

Lines Matching defs:DocTest

1 # Module doctest.
9 r"""Module doctest -- a framework for running examples in docstrings.
14 import doctest
15 doctest.testmod()
44 of doctest's default behaviors. See the Library Reference Manual for
67 # 2. Example & DocTest
69 'DocTest',
70 # 3. Doctest Parser
72 # 4. Doctest Finder
74 # 5. Doctest Runner
113 # - DocTest: a collection of examples, parsed from a docstring, plus
117 # - DocTestRunner: runs DocTest cases, and accumulates statistics.
123 # |object| --DocTestFinder-> | DocTest | --DocTestRunner-> |results|
171 # 2. Example & DocTest -- store test cases
172 # 3. DocTest Parser -- extracts examples from strings
173 # 4. DocTest Finder -- extracts test cases from objects
174 # 5. DocTest Runner -- runs test cases
419 ## 2. Example & DocTest
426 ## - A "doctest" is a collection of examples, typically extracted from
427 ## a string (such as an object's docstring). The DocTest class also
432 A single doctest example, consisting of source code and expected
451 - lineno: The line number within the DocTest string containing
453 zero-based, with respect to the beginning of the DocTest.
455 - indent: The example's indentation in the DocTest string.
498 class DocTest:
500 A collection of doctest examples that should be run in a single
501 namespace. Each `DocTest` defines the following attributes:
508 - name: A name identifying the DocTest (typically, the name of
509 the object whose docstring this DocTest was extracted from).
511 - filename: The name of the file that this DocTest was extracted
514 - lineno: The line number within filename where this DocTest
524 Create a new DocTest containing the given examples. The
525 DocTest's globals are initialized with a copy of `globs`.
528 "DocTest no longer accepts str; use DocTestParser instead"
563 if not isinstance(other, DocTest):
575 A class used to parse strings containing doctest examples.
577 # This regular expression is used to find doctest examples in a
637 # Find all doctest examples in the string:
662 Extract all doctest examples from the given string, and
663 collect them into a `DocTest` object.
666 the new `DocTest` object. See the documentation for `DocTest`
669 return DocTest(self.get_examples(string, name), globs,
674 Extract all doctest examples from the given string, and return
732 # starting with "doctest:". Warning: this may give false
734 # "#doctest:". Eliminating these false positives would require
736 # line containing "#doctest:" that is *followed* by a quote mark.
737 _OPTION_DIRECTIVE_RE = re.compile(r'#\s*doctest:\s*([^\n\'"]*)$',
755 raise ValueError('line %r of the doctest for %s '
761 raise ValueError('line %r of the doctest for %s has an option '
805 ## 4. DocTest Finder
820 Create a new doctest finder.
823 function that should be used to create new DocTest objects (or
824 objects that implement the same interface as DocTest). The
826 of the DocTest constructor.
865 The globals for each DocTest is formed by combining `globs`
868 for each DocTest. If `globs` is not specified, then it
935 # verbose-mode output. This was a feature of doctest in Pythons
1034 Return a DocTest for the given object, if it defines a docstring;
1059 # Return a DocTest for this object.
1118 ## 5. DocTest Runner
1123 A class used to run DocTest test cases, and accumulate statistics.
1124 The `run` method is used to process a single DocTest case. It
1187 outputs of doctest examples.
1210 # Create a fake output target for capturing doctest output.
1269 # DocTest Running
1322 filename = '<doctest %s[%d]>' % (test.name, examplenum)
1399 Record the fact that the given DocTest (`test`) generated `f`
1407 __LINECACHE_FILENAME_RE = re.compile(r'<doctest '
1546 # Backward compatibility cruft to maintain doctest.master.
1563 A class used to check the whether the actual output from a doctest
1619 # This flag causes doctest to ignore any differences in the
1710 """A DocTest example has failed in debugging mode.
1714 - test: the DocTest object being run
1729 """A DocTest example has encountered an unexpected exception
1733 - test: the DocTest object being run
1818 doctest.UnexpectedException: <DocTest foo from foo.py:0 (2 examples)>
1877 See help(doctest) for an overview.
1918 class doctest.Tester, then merges the results into (or creates)
1919 global Tester instance doctest.master. Methods of doctest.master
1922 displaying a summary. Invoke doctest.master.summarize(verbose)
2036 class doctest.Tester, then merges the results into (or creates)
2037 global Tester instance doctest.master. Methods of doctest.master
2040 displaying a summary. Invoke doctest.master.summarize(verbose)
2121 >>> import doctest
2122 >>> old = doctest._unittest_reportflags
2123 >>> doctest.set_unittest_reportflags(REPORT_NDIFF |
2127 >>> doctest._unittest_reportflags == (REPORT_NDIFF |
2133 >>> doctest.set_unittest_reportflags(ELLIPSIS)
2138 >>> doctest.set_unittest_reportflags(old) == (REPORT_NDIFF |
2208 return ('Failed doctest test for %s\n'
2309 return "Doctest: " + self._dt_test.name
2337 Convert doctest tests for a module to a unittest test suite.
2340 contains doctest tests to a unittest test case. If any of the
2354 tests in each file. The setUp function will be passed a DocTest
2360 tests in each file. The tearDown function will be passed a DocTest
2368 A set of doctest option flags expressed as an integer.
2408 return ('Failed doctest test for %s\n File "%s", line 0\n\n%s'
2439 """A unittest suite for one or more doctest files.
2441 The path to each doctest file is given as a string; the
2471 tests in each file. The setUp function will be passed a DocTest
2477 tests in each file. The tearDown function will be passed a DocTest
2485 A set of doctest option flags expressed as an integer.
2594 """Extract the test sources from a doctest docstring as a script.
2610 """Debug a single doctest docstring, in argument `src`'"""
2635 """Debug a single doctest docstring.
2728 >>> print(list(range(1000))) #doctest: +ELLIPSIS
2735 >>> print(list(range(30))) #doctest: +NORMALIZE_WHITESPACE
2744 parser = argparse.ArgumentParser(description="doctest runner")
2749 help=('specify a doctest option flag to apply'