summaryrefslogtreecommitdiffstats
path: root/Doc/library/doctest.rst
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2008-04-25 01:29:10 (GMT)
committerBenjamin Peterson <benjamin@python.org>2008-04-25 01:29:10 (GMT)
commitc7b05920d6536f7edba098d5018a470d35f2e864 (patch)
treece0f68baf5c7794f235604c64cde02c12aeed3de /Doc/library/doctest.rst
parent1c596d5604e4fc79944281ddc5baa666f6e27e85 (diff)
downloadcpython-c7b05920d6536f7edba098d5018a470d35f2e864.zip
cpython-c7b05920d6536f7edba098d5018a470d35f2e864.tar.gz
cpython-c7b05920d6536f7edba098d5018a470d35f2e864.tar.bz2
reformat some documentation of classes so methods and attributes are under the class directive
Diffstat (limited to 'Doc/library/doctest.rst')
-rw-r--r--Doc/library/doctest.rst315
1 files changed, 158 insertions, 157 deletions
diff --git a/Doc/library/doctest.rst b/Doc/library/doctest.rst
index 110411f..31e6d0f 100644
--- a/Doc/library/doctest.rst
+++ b/Doc/library/doctest.rst
@@ -1179,48 +1179,48 @@ DocTest Objects
.. versionadded:: 2.4
-:class:`DocTest` defines the following member variables. They are initialized
-by the constructor, and should not be modified directly.
+ :class:`DocTest` defines the following member variables. They are initialized by
+ the constructor, and should not be modified directly.
-.. attribute:: DocTest.examples
+ .. attribute:: examples
- A list of :class:`Example` objects encoding the individual interactive Python
- examples that should be run by this test.
+ A list of :class:`Example` objects encoding the individual interactive Python
+ examples that should be run by this test.
-.. attribute:: DocTest.globs
+ .. attribute:: globs
- The namespace (aka globals) that the examples should be run in. This is a
- dictionary mapping names to values. Any changes to the namespace made by the
- examples (such as binding new variables) will be reflected in :attr:`globs`
- after the test is run.
+ The namespace (aka globals) that the examples should be run in. This is a
+ dictionary mapping names to values. Any changes to the namespace made by the
+ examples (such as binding new variables) will be reflected in :attr:`globs`
+ after the test is run.
-.. attribute:: DocTest.name
+ .. attribute:: name
- A string name identifying the :class:`DocTest`. Typically, this is the name of
- the object or file that the test was extracted from.
+ A string name identifying the :class:`DocTest`. Typically, this is the name
+ of the object or file that the test was extracted from.
-.. attribute:: DocTest.filename
+ .. attribute:: filename
- The name of the file that this :class:`DocTest` was extracted from; or ``None``
- if the filename is unknown, or if the :class:`DocTest` was not extracted from a
- file.
+ The name of the file that this :class:`DocTest` was extracted from; or
+ ``None`` if the filename is unknown, or if the :class:`DocTest` was not
+ extracted from a file.
-.. attribute:: DocTest.lineno
+ .. attribute:: lineno
- The line number within :attr:`filename` where this :class:`DocTest` begins, or
- ``None`` if the line number is unavailable. This line number is zero-based with
- respect to the beginning of the file.
+ The line number within :attr:`filename` where this :class:`DocTest` begins, or
+ ``None`` if the line number is unavailable. This line number is zero-based
+ with respect to the beginning of the file.
-.. attribute:: DocTest.docstring
+ .. attribute:: docstring
- The string that the test was extracted from, or 'None' if the string is
- unavailable, or if the test was not extracted from a string.
+ The string that the test was extracted from, or 'None' if the string is
+ unavailable, or if the test was not extracted from a string.
.. _doctest-example:
@@ -1237,53 +1237,53 @@ Example Objects
.. versionadded:: 2.4
-:class:`Example` defines the following member variables. They are initialized
-by the constructor, and should not be modified directly.
+ :class:`Example` defines the following member variables. They are initialized by
+ the constructor, and should not be modified directly.
-.. attribute:: Example.source
+ .. attribute:: source
- A string containing the example's source code. This source code consists of a
- single Python statement, and always ends with a newline; the constructor adds a
- newline when necessary.
+ A string containing the example's source code. This source code consists of a
+ single Python statement, and always ends with a newline; the constructor adds
+ a newline when necessary.
-.. attribute:: Example.want
+ .. attribute:: want
- The expected output from running the example's source code (either from stdout,
- or a traceback in case of exception). :attr:`want` ends with a newline unless
- no output is expected, in which case it's an empty string. The constructor adds
- a newline when necessary.
+ The expected output from running the example's source code (either from
+ stdout, or a traceback in case of exception). :attr:`want` ends with a
+ newline unless no output is expected, in which case it's an empty string. The
+ constructor adds a newline when necessary.
-.. attribute:: Example.exc_msg
+ .. attribute:: exc_msg
- The exception message generated by the example, if the example is expected to
- generate an exception; or ``None`` if it is not expected to generate an
- exception. This exception message is compared against the return value of
- :func:`traceback.format_exception_only`. :attr:`exc_msg` ends with a newline
- unless it's ``None``. The constructor adds a newline if needed.
+ The exception message generated by the example, if the example is expected to
+ generate an exception; or ``None`` if it is not expected to generate an
+ exception. This exception message is compared against the return value of
+ :func:`traceback.format_exception_only`. :attr:`exc_msg` ends with a newline
+ unless it's ``None``. The constructor adds a newline if needed.
-.. attribute:: Example.lineno
+ .. attribute:: lineno
- The line number within the string containing this example where the example
- begins. This line number is zero-based with respect to the beginning of the
- containing string.
+ The line number within the string containing this example where the example
+ begins. This line number is zero-based with respect to the beginning of the
+ containing string.
-.. attribute:: Example.indent
+ .. attribute:: indent
- The example's indentation in the containing string, i.e., the number of space
- characters that precede the example's first prompt.
+ The example's indentation in the containing string, i.e., the number of space
+ characters that precede the example's first prompt.
-.. attribute:: Example.options
+ .. attribute:: options
- A dictionary mapping from option flags to ``True`` or ``False``, which is used
- to override default options for this example. Any option flags not contained in
- this dictionary are left at their default value (as specified by the
- :class:`DocTestRunner`'s :attr:`optionflags`). By default, no options are set.
+ A dictionary mapping from option flags to ``True`` or ``False``, which is used
+ to override default options for this example. Any option flags not contained
+ in this dictionary are left at their default value (as specified by the
+ :class:`DocTestRunner`'s :attr:`optionflags`). By default, no options are set.
.. _doctest-doctestfinder:
@@ -1314,44 +1314,44 @@ DocTestFinder objects
.. versionadded:: 2.4
-:class:`DocTestFinder` defines the following method:
+ :class:`DocTestFinder` defines the following method:
-.. method:: DocTestFinder.find(obj[, name][, module][, globs][, extraglobs])
+ .. method:: find(obj[, name][, module][, globs][, extraglobs])
- Return a list of the :class:`DocTest`\ s that are defined by *obj*'s docstring,
- or by any of its contained objects' docstrings.
+ Return a list of the :class:`DocTest`\ s that are defined by *obj*'s
+ docstring, or by any of its contained objects' docstrings.
- The optional argument *name* specifies the object's name; this name will be used
- to construct names for the returned :class:`DocTest`\ s. If *name* is not
- specified, then ``obj.__name__`` is used.
+ The optional argument *name* specifies the object's name; this name will be
+ used to construct names for the returned :class:`DocTest`\ s. If *name* is
+ not specified, then ``obj.__name__`` is used.
- The optional parameter *module* is the module that contains the given object.
- If the module is not specified or is None, then the test finder will attempt to
- automatically determine the correct module. The object's module is used:
+ The optional parameter *module* is the module that contains the given object.
+ If the module is not specified or is None, then the test finder will attempt
+ to automatically determine the correct module. The object's module is used:
- * As a default namespace, if *globs* is not specified.
+ * As a default namespace, if *globs* is not specified.
- * To prevent the DocTestFinder from extracting DocTests from objects that are
- imported from other modules. (Contained objects with modules other than
- *module* are ignored.)
+ * To prevent the DocTestFinder from extracting DocTests from objects that are
+ imported from other modules. (Contained objects with modules other than
+ *module* are ignored.)
- * To find the name of the file containing the object.
+ * To find the name of the file containing the object.
- * To help find the line number of the object within its file.
+ * To help find the line number of the object within its file.
- If *module* is ``False``, no attempt to find the module will be made. This is
- obscure, of use mostly in testing doctest itself: if *module* is ``False``, or
- is ``None`` but cannot be found automatically, then all objects are considered
- to belong to the (non-existent) module, so all contained objects will
- (recursively) be searched for doctests.
+ If *module* is ``False``, no attempt to find the module will be made. This is
+ obscure, of use mostly in testing doctest itself: if *module* is ``False``, or
+ is ``None`` but cannot be found automatically, then all objects are considered
+ to belong to the (non-existent) module, so all contained objects will
+ (recursively) be searched for doctests.
- The globals for each :class:`DocTest` is formed by combining *globs* and
- *extraglobs* (bindings in *extraglobs* override bindings in *globs*). A new
- shallow copy of the globals dictionary is created for each :class:`DocTest`. If
- *globs* is not specified, then it defaults to the module's *__dict__*, if
- specified, or ``{}`` otherwise. If *extraglobs* is not specified, then it
- defaults to ``{}``.
+ The globals for each :class:`DocTest` is formed by combining *globs* and
+ *extraglobs* (bindings in *extraglobs* override bindings in *globs*). A new
+ shallow copy of the globals dictionary is created for each :class:`DocTest`.
+ If *globs* is not specified, then it defaults to the module's *__dict__*, if
+ specified, or ``{}`` otherwise. If *extraglobs* is not specified, then it
+ defaults to ``{}``.
.. _doctest-doctestparser:
@@ -1367,32 +1367,32 @@ DocTestParser objects
.. versionadded:: 2.4
-:class:`DocTestParser` defines the following methods:
+ :class:`DocTestParser` defines the following methods:
-.. method:: DocTestParser.get_doctest(string, globs, name, filename, lineno)
+ .. method:: get_doctest(string, globs, name, filename, lineno)
- Extract all doctest examples from the given string, and collect them into a
- :class:`DocTest` object.
+ Extract all doctest examples from the given string, and collect them into a
+ :class:`DocTest` object.
- *globs*, *name*, *filename*, and *lineno* are attributes for the new
- :class:`DocTest` object. See the documentation for :class:`DocTest` for more
- information.
+ *globs*, *name*, *filename*, and *lineno* are attributes for the new
+ :class:`DocTest` object. See the documentation for :class:`DocTest` for more
+ information.
-.. method:: DocTestParser.get_examples(string[, name])
+ .. method:: get_examples(string[, name])
- Extract all doctest examples from the given string, and return them as a list of
- :class:`Example` objects. Line numbers are 0-based. The optional argument
- *name* is a name identifying this string, and is only used for error messages.
+ Extract all doctest examples from the given string, and return them as a list
+ of :class:`Example` objects. Line numbers are 0-based. The optional argument
+ *name* is a name identifying this string, and is only used for error messages.
-.. method:: DocTestParser.parse(string[, name])
+ .. method:: parse(string[, name])
- Divide the given string into examples and intervening text, and return them as a
- list of alternating :class:`Example`\ s and strings. Line numbers for the
- :class:`Example`\ s are 0-based. The optional argument *name* is a name
- identifying this string, and is only used for error messages.
+ Divide the given string into examples and intervening text, and return them as
+ a list of alternating :class:`Example`\ s and strings. Line numbers for the
+ :class:`Example`\ s are 0-based. The optional argument *name* is a name
+ identifying this string, and is only used for error messages.
.. _doctest-doctestrunner:
@@ -1436,83 +1436,84 @@ DocTestRunner objects
.. versionadded:: 2.4
-:class:`DocTestParser` defines the following methods:
+ :class:`DocTestParser` defines the following methods:
-.. method:: DocTestRunner.report_start(out, test, example)
+ .. method:: report_start(out, test, example)
- Report that the test runner is about to process the given example. This method
- is provided to allow subclasses of :class:`DocTestRunner` to customize their
- output; it should not be called directly.
+ Report that the test runner is about to process the given example. This method
+ is provided to allow subclasses of :class:`DocTestRunner` to customize their
+ output; it should not be called directly.
- *example* is the example about to be processed. *test* is the test containing
- *example*. *out* is the output function that was passed to
- :meth:`DocTestRunner.run`.
+ *example* is the example about to be processed. *test* is the test
+ *containing example*. *out* is the output function that was passed to
+ :meth:`DocTestRunner.run`.
-.. method:: DocTestRunner.report_success(out, test, example, got)
+ .. method:: report_success(out, test, example, got)
- Report that the given example ran successfully. This method is provided to
- allow subclasses of :class:`DocTestRunner` to customize their output; it should
- not be called directly.
+ Report that the given example ran successfully. This method is provided to
+ allow subclasses of :class:`DocTestRunner` to customize their output; it
+ should not be called directly.
- *example* is the example about to be processed. *got* is the actual output from
- the example. *test* is the test containing *example*. *out* is the output
- function that was passed to :meth:`DocTestRunner.run`.
+ *example* is the example about to be processed. *got* is the actual output
+ from the example. *test* is the test containing *example*. *out* is the
+ output function that was passed to :meth:`DocTestRunner.run`.
-.. method:: DocTestRunner.report_failure(out, test, example, got)
+ .. method:: report_failure(out, test, example, got)
- Report that the given example failed. This method is provided to allow
- subclasses of :class:`DocTestRunner` to customize their output; it should not be
- called directly.
+ Report that the given example failed. This method is provided to allow
+ subclasses of :class:`DocTestRunner` to customize their output; it should not
+ be called directly.
- *example* is the example about to be processed. *got* is the actual output from
- the example. *test* is the test containing *example*. *out* is the output
- function that was passed to :meth:`DocTestRunner.run`.
+ *example* is the example about to be processed. *got* is the actual output
+ from the example. *test* is the test containing *example*. *out* is the
+ output function that was passed to :meth:`DocTestRunner.run`.
-.. method:: DocTestRunner.report_unexpected_exception(out, test, example, exc_info)
+ .. method:: report_unexpected_exception(out, test, example, exc_info)
- Report that the given example raised an unexpected exception. This method is
- provided to allow subclasses of :class:`DocTestRunner` to customize their
- output; it should not be called directly.
+ Report that the given example raised an unexpected exception. This method is
+ provided to allow subclasses of :class:`DocTestRunner` to customize their
+ output; it should not be called directly.
- *example* is the example about to be processed. *exc_info* is a tuple containing
- information about the unexpected exception (as returned by
- :func:`sys.exc_info`). *test* is the test containing *example*. *out* is the
- output function that was passed to :meth:`DocTestRunner.run`.
+ *example* is the example about to be processed. *exc_info* is a tuple
+ containing information about the unexpected exception (as returned by
+ :func:`sys.exc_info`). *test* is the test containing *example*. *out* is the
+ output function that was passed to :meth:`DocTestRunner.run`.
-.. method:: DocTestRunner.run(test[, compileflags][, out][, clear_globs])
+ .. method:: run(test[, compileflags][, out][, clear_globs])
- Run the examples in *test* (a :class:`DocTest` object), and display the results
- using the writer function *out*.
+ Run the examples in *test* (a :class:`DocTest` object), and display the
+ results using the writer function *out*.
- The examples are run in the namespace ``test.globs``. If *clear_globs* is true
- (the default), then this namespace will be cleared after the test runs, to help
- with garbage collection. If you would like to examine the namespace after the
- test completes, then use *clear_globs=False*.
+ The examples are run in the namespace ``test.globs``. If *clear_globs* is
+ true (the default), then this namespace will be cleared after the test runs,
+ to help with garbage collection. If you would like to examine the namespace
+ after the test completes, then use *clear_globs=False*.
- *compileflags* gives the set of flags that should be used by the Python compiler
- when running the examples. If not specified, then it will default to the set of
- future-import flags that apply to *globs*.
+ *compileflags* gives the set of flags that should be used by the Python
+ compiler when running the examples. If not specified, then it will default to
+ the set of future-import flags that apply to *globs*.
- The output of each example is checked using the :class:`DocTestRunner`'s output
- checker, and the results are formatted by the :meth:`DocTestRunner.report_\*`
- methods.
+ The output of each example is checked using the :class:`DocTestRunner`'s
+ output checker, and the results are formatted by the
+ :meth:`DocTestRunner.report_\*` methods.
-.. method:: DocTestRunner.summarize([verbose])
+ .. method:: summarize([verbose])
- Print a summary of all the test cases that have been run by this DocTestRunner,
- and return a :term:`named tuple` ``TestResults(failed, attempted)``.
+ Print a summary of all the test cases that have been run by this DocTestRunner,
+ and return a :term:`named tuple` ``TestResults(failed, attempted)``.
- The optional *verbose* argument controls how detailed the summary is. If the
- verbosity is not specified, then the :class:`DocTestRunner`'s verbosity is used.
+ The optional *verbose* argument controls how detailed the summary is. If the
+ verbosity is not specified, then the :class:`DocTestRunner`'s verbosity is
+ used.
- .. versionchanged:: 2.6
- Use a named tuple.
+ .. versionchanged:: 2.6
+ Use a named tuple.
.. _doctest-outputchecker:
@@ -1531,23 +1532,23 @@ OutputChecker objects
.. versionadded:: 2.4
-:class:`OutputChecker` defines the following methods:
+ :class:`OutputChecker` defines the following methods:
-.. method:: OutputChecker.check_output(want, got, optionflags)
+ .. method:: check_output(want, got, optionflags)
- Return ``True`` iff the actual output from an example (*got*) matches the
- expected output (*want*). These strings are always considered to match if they
- are identical; but depending on what option flags the test runner is using,
- several non-exact match types are also possible. See section
- :ref:`doctest-options` for more information about option flags.
+ Return ``True`` iff the actual output from an example (*got*) matches the
+ expected output (*want*). These strings are always considered to match if
+ they are identical; but depending on what option flags the test runner is
+ using, several non-exact match types are also possible. See section
+ :ref:`doctest-options` for more information about option flags.
-.. method:: OutputChecker.output_difference(example, got, optionflags)
+ .. method:: output_difference(example, got, optionflags)
- Return a string describing the differences between the expected output for a
- given example (*example*) and the actual output (*got*). *optionflags* is the
- set of option flags used to compare *want* and *got*.
+ Return a string describing the differences between the expected output for a
+ given example (*example*) and the actual output (*got*). *optionflags* is the
+ set of option flags used to compare *want* and *got*.
.. _doctest-debugging: