- Updated example output to match actual output

- Minor wording changes
- Changed the docs to reflect the fact that multiple option directives
  can be specified on a single line (and updated the directive
  production list, as well).
This commit is contained in:
Edward Loper 2004-09-19 01:16:44 +00:00
parent 33db656dbf
commit 6cc1350807

View file

@ -100,21 +100,28 @@ end:
\begin{verbatim} \begin{verbatim}
$ python example.py -v $ python example.py -v
Trying: factorial(5) Trying:
Expecting: 120 factorial(5)
Expecting:
120
ok ok
Trying: [factorial(n) for n in range(6)] Trying:
Expecting: [1, 1, 2, 6, 24, 120] [factorial(n) for n in range(6)]
Expecting:
[1, 1, 2, 6, 24, 120]
ok ok
Trying: [factorial(long(n)) for n in range(6)] Trying:
Expecting: [1, 1, 2, 6, 24, 120] [factorial(long(n)) for n in range(6)]
Expecting:
[1, 1, 2, 6, 24, 120]
ok ok
\end{verbatim} \end{verbatim}
And so on, eventually ending with: And so on, eventually ending with:
\begin{verbatim} \begin{verbatim}
Trying: factorial(1e100) Trying:
factorial(1e100)
Expecting: Expecting:
Traceback (most recent call last): Traceback (most recent call last):
... ...
@ -181,7 +188,7 @@ prohibit it by passing \code{verbose=False}. In either of those cases,
In any case, \function{testmod()} returns a 2-tuple of ints \code{(\var{f}, In any case, \function{testmod()} returns a 2-tuple of ints \code{(\var{f},
\var{t})}, where \var{f} is the number of docstring examples that \var{t})}, where \var{f} is the number of docstring examples that
failed and \var{t} is the total number of docstring examples failed and \var{t} is the total number of docstring examples
attempted. tried.
\subsection{Which Docstrings Are Examined?} \subsection{Which Docstrings Are Examined?}
@ -266,7 +273,7 @@ ValueError: multi
detail detail
\end{verbatim} \end{verbatim}
The last three (starting with \exception{ValueError}) lines are The last three lines (starting with \exception{ValueError}) are
compared against the exception's type and detail, and the rest are compared against the exception's type and detail, and the rest are
ignored. ignored.
@ -442,16 +449,20 @@ example:
\begin{productionlist}[doctest] \begin{productionlist}[doctest]
\production{directive} \production{directive}
{"\#" "doctest:" \token{on_or_off} \token{directive_name}} {"\#" "doctest:" \token{directive_options}}
\production{directive_options}
{\token{directive_option} ("," \token{directive_option})*}
\production{directive_option}
{\token{on_or_off} \token{directive_option_name}}
\production{on_or_off} \production{on_or_off}
{"+" | "-"} {"+" | "-"}
\production{directive_name} \production{directive_option_name}
{"DONT_ACCEPT_BLANKLINE" | "NORMALIZE_WHITESPACE" | ...} {"DONT_ACCEPT_BLANKLINE" | "NORMALIZE_WHITESPACE" | ...}
\end{productionlist} \end{productionlist}
Whitespace is not allowed between the \code{+} or \code{-} and the Whitespace is not allowed between the \code{+} or \code{-} and the
directive name. The directive name can be any of the option names directive option name. The directive option name can be any of the
explained above. option names explained above.
The doctest directives appearing in a single example modify doctest's The doctest directives appearing in a single example modify doctest's
behavior for that single example. Use \code{+} to enable the named behavior for that single example. Use \code{+} to enable the named
@ -475,16 +486,34 @@ and also requires a directive to do so:
[0, 1, ..., 18, 19] [0, 1, ..., 18, 19]
\end{verbatim} \end{verbatim}
Only one directive per physical line is accepted. If you want to Multiple directives can be used on a single physical line, separated
use multiple directives for a single example, you can add by commas:
\samp{...} lines to your example containing only directives:
\begin{verbatim} \begin{verbatim}
>>> print range(20) #doctest: +ELLIPSIS >>> print range(20) # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
... #doctest: +NORMALIZE_WHITESPACE
[0, 1, ..., 18, 19] [0, 1, ..., 18, 19]
\end{verbatim} \end{verbatim}
If multiple directives are used for a single example, then they are
combined:
\begin{verbatim}
>>> print range(20) # doctest: +ELLIPSIS
... # doctest: +NORMALIZE_WHITESPACE
[0, 1, ..., 18, 19]
\end{verbatim}
As the previous example shows, you can add \samp{...} lines to your
example containing only directives. This can also be useful when an
example is too long for a directive to comfortably fit on the same
line:
\begin{verbatim}
>>> print range(5) + range(10,20) + range(30,40) + range(50,60)
... # doctest: +ELLIPSIS
[0, ..., 4, 10, ..., 19, 30, ..., 39, 50, ..., 59]
\end{verbatim}
Note that since all options are disabled by default, and directives apply Note that since all options are disabled by default, and directives apply
only to the example they appear in, enabling options (via \code{+} in a only to the example they appear in, enabling options (via \code{+} in a
directive) is usually the only meaningful choice. However, option flags directive) is usually the only meaningful choice. However, option flags