Lines Matching refs: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
66 # 2. Example & DocTest
68 'DocTest',
69 # 3. Doctest Parser
71 # 4. Doctest Finder
73 # 5. Doctest Runner
108 # - DocTest: a collection of examples, parsed from a docstring, plus
112 # - DocTestRunner: runs DocTest cases, and accumulates statistics.
118 # |object| --DocTestFinder-> | DocTest | --DocTestRunner-> |results|
164 # 2. Example & DocTest -- store test cases
165 # 3. DocTest Parser -- extracts examples from strings
166 # 4. DocTest Finder -- extracts test cases from objects
167 # 5. DocTest Runner -- runs test cases
390 ## 2. Example & DocTest
397 ## - A "doctest" is a collection of examples, typically extracted from
398 ## a string (such as an object's docstring). The DocTest class also
403 A single doctest example, consisting of source code and expected
422 - lineno: The line number within the DocTest string containing
424 zero-based, with respect to the beginning of the DocTest.
426 - indent: The example's indentation in the DocTest string.
473 class DocTest:
475 A collection of doctest examples that should be run in a single
476 namespace. Each `DocTest` defines the following attributes:
483 - name: A name identifying the DocTest (typically, the name of
484 the object whose docstring this DocTest was extracted from).
486 - filename: The name of the file that this DocTest was extracted
489 - lineno: The line number within filename where this DocTest
499 Create a new DocTest containing the given examples. The
500 DocTest's globals are initialized with a copy of `globs`.
503 "DocTest no longer accepts str; use DocTestParser instead"
518 return ('<DocTest %s from %s:%s (%s)>' %
540 if not isinstance(other, DocTest):
551 A class used to parse strings containing doctest examples.
553 # This regular expression is used to find doctest examples in a
613 # Find all doctest examples in the string:
638 Extract all doctest examples from the given string, and
639 collect them into a `DocTest` object.
642 the new `DocTest` object. See the documentation for `DocTest`
645 return DocTest(self.get_examples(string, name), globs,
650 Extract all doctest examples from the given string, and return
708 # starting with "doctest:". Warning: this may give false
710 # "#doctest:". Eliminating these false positives would require
712 # line containing "#doctest:" that is *followed* by a quote mark.
713 _OPTION_DIRECTIVE_RE = re.compile(r'#\s*doctest:\s*([^\n\'"]*)$',
731 raise ValueError('line %r of the doctest for %s '
737 raise ValueError('line %r of the doctest for %s has an option '
781 ## 4. DocTest Finder
796 Create a new doctest finder.
799 function that should be used to create new DocTest objects (or
800 objects that implement the same interface as DocTest). The
802 of the DocTest constructor.
841 The globals for each DocTest is formed by combining `globs`
844 for each DocTest. If `globs` is not specified, then it
902 # verbose-mode output. This was a feature of doctest in Pythons
993 Return a DocTest for the given object, if it defines a docstring;
1018 # Return a DocTest for this object.
1077 ## 5. DocTest Runner
1082 A class used to run DocTest test cases, and accumulate statistics.
1083 The `run` method is used to process a single DocTest case. It
1146 outputs of doctest examples.
1169 # Create a fake output target for capturing doctest output.
1228 # DocTest Running
1281 filename = '<doctest %s[%d]>' % (test.name, examplenum)
1357 Record the fact that the given DocTest (`test`) generated `f`
1365 __LINECACHE_FILENAME_RE = re.compile(r'<doctest '
1496 # Backward compatibility cruft to maintain doctest.master.
1513 A class used to check the whether the actual output from a doctest
1554 # This flag causes doctest to ignore any differences in the
1645 """A DocTest example has failed in debugging mode.
1649 - test: the DocTest object being run
1664 """A DocTest example has encountered an unexpected exception
1668 - test: the DocTest object being run
1753 UnexpectedException: <DocTest foo from foo.py:0 (2 examples)>
1812 See help(doctest) for an overview.
1853 class doctest.Tester, then merges the results into (or creates)
1854 global Tester instance doctest.master. Methods of doctest.master
1857 displaying a summary. Invoke doctest.master.summarize(verbose)
1971 class doctest.Tester, then merges the results into (or creates)
1972 global Tester instance doctest.master. Methods of doctest.master
1975 displaying a summary. Invoke doctest.master.summarize(verbose)
2056 "use class doctest.DocTestRunner instead",
2123 >>> import doctest
2124 >>> old = doctest._unittest_reportflags
2125 >>> doctest.set_unittest_reportflags(REPORT_NDIFF |
2129 >>> doctest._unittest_reportflags == (REPORT_NDIFF |
2135 >>> doctest.set_unittest_reportflags(ELLIPSIS)
2140 >>> doctest.set_unittest_reportflags(old) == (REPORT_NDIFF |
2210 return ('Failed doctest test for %s\n'
2314 return "Doctest: " + self._dt_test.name
2336 Convert doctest tests for a module to a unittest test suite.
2339 contains doctest tests to a unittest test case. If any of the
2353 tests in each file. The setUp function will be passed a DocTest
2359 tests in each file. The tearDown function will be passed a DocTest
2367 A set of doctest option flags expressed as an integer.
2385 # number of doctest examples in tests is zero (i.e. if no doctest
2416 return ('Failed doctest test for %s\n File "%s", line 0\n\n%s'
2450 """A unittest suite for one or more doctest files.
2452 The path to each doctest file is given as a string; the
2482 tests in each file. The setUp function will be passed a DocTest
2488 tests in each file. The tearDown function will be passed a DocTest
2496 A set of doctest option flags expressed as an integer.
2605 doctest docstring as a script.
2621 """Debug a single doctest docstring, in argument `src`'"""
2658 """Debug a single doctest docstring.
2751 >>> print range(1000) #doctest: +ELLIPSIS
2758 >>> print range(30) #doctest: +NORMALIZE_WHITESPACE