Lines Matching full: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
112 # - DocTest: a collection of examples, parsed from a docstring, plus
116 # - DocTestRunner: runs DocTest cases, and accumulates statistics.
122 # |object| --DocTestFinder-> | DocTest | --DocTestRunner-> |results|
170 # 2. Example & DocTest -- store test cases
171 # 3. DocTest Parser -- extracts examples from strings
172 # 4. DocTest Finder -- extracts test cases from objects
173 # 5. DocTest Runner -- runs test cases
426 ## 2. Example & DocTest
433 ## - A "doctest" is a collection of examples, typically extracted from
434 ## a string (such as an object's docstring). The DocTest class also
439 A single doctest example, consisting of source code and expected
458 - lineno: The line number within the DocTest string containing
460 zero-based, with respect to the beginning of the DocTest.
462 - indent: The example's indentation in the DocTest string.
505 class DocTest: class
507 A collection of doctest examples that should be run in a single
508 namespace. Each `DocTest` defines the following attributes:
515 - name: A name identifying the DocTest (typically, the name of
516 the object whose docstring this DocTest was extracted from).
518 - filename: The name of the file that this DocTest was extracted
521 - lineno: The line number within filename where this DocTest
531 Create a new DocTest containing the given examples. The
532 DocTest's globals are initialized with a copy of `globs`.
535 "DocTest no longer accepts str; use DocTestParser instead"
570 if not isinstance(other, DocTest):
582 A class used to parse strings containing doctest examples.
584 # This regular expression is used to find doctest examples in a
644 # Find all doctest examples in the string:
669 Extract all doctest examples from the given string, and
670 collect them into a `DocTest` object.
673 the new `DocTest` object. See the documentation for `DocTest`
676 return DocTest(self.get_examples(string, name), globs,
681 Extract all doctest examples from the given string, and return
739 # starting with "doctest:". Warning: this may give false
741 # "#doctest:". Eliminating these false positives would require
743 # line containing "#doctest:" that is *followed* by a quote mark.
744 _OPTION_DIRECTIVE_RE = re.compile(r'#\s*doctest:\s*([^\n\'"]*)$',
762 raise ValueError('line %r of the doctest for %s '
768 raise ValueError('line %r of the doctest for %s has an option '
812 ## 4. DocTest Finder
827 Create a new doctest finder.
830 function that should be used to create new DocTest objects (or
831 objects that implement the same interface as DocTest). The
833 of the DocTest constructor.
872 The globals for each DocTest is formed by combining `globs`
875 for each DocTest. If `globs` is not specified, then it
942 # verbose-mode output. This was a feature of doctest in Pythons
1051 Return a DocTest for the given object, if it defines a docstring;
1076 # Return a DocTest for this object.
1140 ## 5. DocTest Runner
1145 A class used to run DocTest test cases, and accumulate statistics.
1146 The `run` method is used to process a single DocTest case. It
1209 outputs of doctest examples.
1232 # Create a fake output target for capturing doctest output.
1291 # DocTest Running
1344 filename = '<doctest %s[%d]>' % (test.name, examplenum)
1421 Record the fact that the given DocTest (`test`) generated `f`
1429 __LINECACHE_FILENAME_RE = re.compile(r'<doctest '
1568 # Backward compatibility cruft to maintain doctest.master.
1585 A class used to check the whether the actual output from a doctest
1641 # This flag causes doctest to ignore any differences in the
1730 """A DocTest example has failed in debugging mode.
1734 - test: the DocTest object being run
1749 """A DocTest example has encountered an unexpected exception
1753 - test: the DocTest object being run
1838 doctest.UnexpectedException: <DocTest foo from foo.py:0 (2 examples)>
1897 See help(doctest) for an overview.
1938 class doctest.Tester, then merges the results into (or creates)
1939 global Tester instance doctest.master. Methods of doctest.master
1942 displaying a summary. Invoke doctest.master.summarize(verbose)
2056 class doctest.Tester, then merges the results into (or creates)
2057 global Tester instance doctest.master. Methods of doctest.master
2060 displaying a summary. Invoke doctest.master.summarize(verbose)
2141 >>> import doctest
2142 >>> old = doctest._unittest_reportflags
2143 >>> doctest.set_unittest_reportflags(REPORT_NDIFF |
2147 >>> doctest._unittest_reportflags == (REPORT_NDIFF |
2153 >>> doctest.set_unittest_reportflags(ELLIPSIS)
2158 >>> doctest.set_unittest_reportflags(old) == (REPORT_NDIFF |
2231 return ('Failed doctest test for %s\n'
2332 return "Doctest: " + self._dt_test.name
2360 Convert doctest tests for a module to a unittest test suite.
2363 contains doctest tests to a unittest test case. If any of the
2377 tests in each file. The setUp function will be passed a DocTest
2383 tests in each file. The tearDown function will be passed a DocTest
2391 A set of doctest option flags expressed as an integer.
2430 return ('Failed doctest test for %s\n File "%s", line 0\n\n%s'
2461 """A unittest suite for one or more doctest files.
2463 The path to each doctest file is given as a string; the
2493 tests in each file. The setUp function will be passed a DocTest
2499 tests in each file. The tearDown function will be passed a DocTest
2507 A set of doctest option flags expressed as an integer.
2616 """Extract the test sources from a doctest docstring as a script.
2632 """Debug a single doctest docstring, in argument `src`'"""
2657 """Debug a single doctest docstring.
2750 >>> print(list(range(1000))) #doctest: +ELLIPSIS
2757 >>> print(list(range(30))) #doctest: +NORMALIZE_WHITESPACE
2768 parser = argparse.ArgumentParser(description="doctest runner")
2773 help=('specify a doctest option flag to apply'