Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8a3b69c

Browse files
committed
Excruciatingly slow progress on the docs. Option flags / directive names
are documented now, and ripped out a bunch of "private name" convolutions.
1 parent 79b52b7 commit 8a3b69c

1 file changed

Lines changed: 77 additions & 54 deletions

File tree

Doc/lib/libdoctest.tex

Lines changed: 77 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ \subsection{Simple Usage}
214214
created for each docstring with examples, so that each docstring's
215215
examples start with a clean slate.
216216

217-
Optional argument \var{extraglobs} gives a dicti merged into the
217+
Optional argument \var{extraglobs} gives a dict merged into the
218218
globals used to execute examples. This works like
219219
\method{dict.update()}: if \var{globs} and \var{extraglobs} have a
220220
common key, the associated value in \var{extraglobs} appears in the
@@ -234,45 +234,8 @@ \subsection{Simple Usage}
234234
detailed, else the summary is very brief (in fact, empty if all tests
235235
passed).
236236

237-
Optional argument \var{optionflags} or's together module constants,
238-
and defaults to 0.
239-
240-
% Possible values:
241-
%
242-
% DONT_ACCEPT_TRUE_FOR_1
243-
% By default, if an expected output block contains just "1",
244-
% an actual output block containing just "True" is considered
245-
% to be a match, and similarly for "0" versus "False". When
246-
% DONT_ACCEPT_TRUE_FOR_1 is specified, neither substitution
247-
% is allowed.
248-
%
249-
% DONT_ACCEPT_BLANKLINE
250-
% By default, if an expected output block contains a line
251-
% containing only the string "<BLANKLINE>", then that line
252-
% will match a blank line in the actual output. When
253-
% DONT_ACCEPT_BLANKLINE is specified, this substitution is
254-
% not allowed.
255-
%
256-
% NORMALIZE_WHITESPACE
257-
% When NORMALIZE_WHITESPACE is specified, all sequences of
258-
% whitespace are treated as equal. I.e., any sequence of
259-
% whitespace within the expected output will match any
260-
% sequence of whitespace within the actual output.
261-
%
262-
% ELLIPSIS
263-
% When ELLIPSIS is specified, then an ellipsis marker
264-
% ("...") in the expected output can match any substring in
265-
% the actual output.
266-
%
267-
% UNIFIED_DIFF
268-
% When UNIFIED_DIFF is specified, failures that involve
269-
% multi-line expected and actual outputs will be displayed
270-
% using a unified diff.
271-
%
272-
% CONTEXT_DIFF
273-
% When CONTEXT_DIFF is specified, failures that involve
274-
% multi-line expected and actual outputs will be displayed
275-
% using a context diff.
237+
Optional argument \var{optionflags} or's together option flags. See
238+
see section \ref{doctest-options}.
276239

277240
Optional argument \var{raise_on_error} defaults to false. If true,
278241
an exception is raised upon the first failure or unexpected exception
@@ -299,37 +262,33 @@ \subsection{Simple Usage}
299262

300263
\versionchanged[The parameter \var{optionflags} was added]{2.3}
301264

302-
\versionchanged[Many new module constants for use with \var{optionflags}
303-
were added]{2.4}
304-
305265
\versionchanged[The parameters \var{extraglobs} and \var{raise_on_error}
306266
were added]{2.4}
307267
\end{funcdesc}
308268

309269

310270
\subsection{Which Docstrings Are Examined?}
311271

312-
See the docstrings in \file{doctest.py} for all the details. They're
313-
unsurprising: the module docstring, and all function, class and method
314-
docstrings are searched. Optionally, the tester can be directed to
315-
exclude docstrings attached to objects with private names. Objects
316-
imported into the module are not searched.
272+
The module docstring, and all function, class and method docstrings are
273+
searched. Objects imported into the module are not searched.
317274

318275
In addition, if \code{M.__test__} exists and "is true", it must be a
319276
dict, and each entry maps a (string) name to a function object, class
320277
object, or string. Function and class object docstrings found from
321-
\code{M.__test__} are searched even if the tester has been
322-
directed to skip over private names in the rest of the module.
323-
In output, a key \code{K} in \code{M.__test__} appears with name
278+
\code{M.__test__} are searched, and strings are treated as if they
279+
were docstrings. In output, a key \code{K} in \code{M.__test__} appears
280+
with name
324281

325282
\begin{verbatim}
326283
<name of M>.__test__.K
327284
\end{verbatim}
328285

329286
Any classes found are recursively searched similarly, to test docstrings in
330-
their contained methods and nested classes. While private names reached
331-
from \module{M}'s globals can be optionally skipped, all names reached from
332-
\code{M.__test__} are searched.
287+
their contained methods and nested classes.
288+
289+
\versionchanged[A "private name" concept is deprecated and no longer
290+
documented.]{2.4}
291+
333292

334293
\subsection{What's the Execution Context?}
335294

@@ -363,6 +322,70 @@ \subsection{What About Exceptions?}
363322
between can be left out (unless they add significantly to the documentation
364323
value of the example).
365324

325+
\subsection{Option Flags and Directive Names\label{doctest-options}}
326+
327+
A number of option flags control various aspects of doctest's behavior.
328+
Symbolic names for the flags are supplied as module constants, which
329+
can be or'ed together and passed to various functions. The names can
330+
also be used in doctest directives.
331+
332+
\begin{datadesc}{DONT_ACCEPT_TRUE_FOR_1}
333+
By default, if an expected output block contains just \code{1},
334+
an actual output block containing just \code{1} or just
335+
\code{True} is considered to be a match, and similarly for \code{0}
336+
versus \code{False}. When \constant{DONT_ACCEPT_TRUE_FOR_1} is
337+
specified, neither substitution is allowed. The default behavior
338+
caters to that Python changed the return type of many functions
339+
from integer to boolean; doctests expecting "little integer"
340+
output still work in these cases. This option will probably go
341+
away, but not for several years.
342+
\end{datadesc}
343+
344+
\begin{datadesc}{DONT_ACCEPT_BLANKLINE}
345+
By default, if an expected output block contains a line
346+
containing only the string \code{<BLANKLINE>}, then that line
347+
will match a blank line in the actual output. Because a
348+
genuinely blank line delimits the expected output, this is
349+
the only way to communicate that a blank line is expected. When
350+
\constant{DONT_ACCEPT_BLANKLINE} is specified, this substitution
351+
is not allowed.
352+
\end{datadesc}
353+
354+
\begin{datadesc}{NORMALIZE_WHITESPACE}
355+
When specified, all sequences of whitespace (blanks and newlines) are
356+
treated as equal. Any sequence of whitespace within the expected
357+
output will match any sequence of whitespace within the actual output.
358+
By default, whitespace must match exactly.
359+
\constant{NORMALIZE_WHITESPACE} is especially useful when a line
360+
of expected output is very long, and you want to wrap it across
361+
multiple lines in your source.
362+
\end{datadesc}
363+
364+
\begin{datadesc}{ELLIPSIS}
365+
When specified, an ellipsis marker (\code{...}) in the expected output
366+
can match any substring in the actual output. This includes
367+
substrings that span line boundaries, so it's best to keep usage of
368+
this simple. Complicated uses can lead to the same kinds of
369+
surprises that \code{.*} is prone to in regular expressions.
370+
\end{datadesc}
371+
372+
\begin{datadesc}{UNIFIED_DIFF}
373+
When specified, failures that involve multi-line expected and
374+
actual outputs are displayed using a unified diff.
375+
\end{datadesc}
376+
377+
\begin{datadesc}{CONTEXT_DIFF}
378+
When specified, failures that involve multi-line expected and
379+
actual outputs will be displayed using a context diff.
380+
\end{datadesc}
381+
382+
383+
\versionchanged[Constants \constant{DONT_ACCEPT_BLANKLINE},
384+
\constant{NORMALIZE_WHITESPACE}, \constant{ELLIPSIS},
385+
\constant{UNIFIED_DIFF}, and \constant{CONTEXT_DIFF}
386+
were added, and \code{<BLANKLINE>} in expected output matches
387+
an empty line in actual output by default.]{2.4}
388+
366389
\subsection{Advanced Usage}
367390

368391
Several module level functions are available for controlling how doctests

0 commit comments

Comments
 (0)