Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
9dff7c2f
Commit
9dff7c2f
authored
Feb 17, 2001
by
Fred Drake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make a variety of minor markup adjustments.
Close some environments so that this will actually format.
parent
59c44c8d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
33 deletions
+37
-33
Doc/lib/libdoctest.tex
Doc/lib/libdoctest.tex
+37
-33
No files found.
Doc/lib/libdoctest.tex
View file @
9dff7c2f
...
@@ -94,8 +94,8 @@ $
...
@@ -94,8 +94,8 @@ $
\end{verbatim}
\end{verbatim}
There's no output! That's normal, and it means all the examples worked.
There's no output! That's normal, and it means all the examples worked.
Pass
\
code
{
-v
}
to the script, and doctest prints a detailed log of what it's
Pass
\
programopt
{
-v
}
to the script, and doctest prints a detailed log
trying, and prints a summary at the end:
of what it's
trying, and prints a summary at the end:
\begin{verbatim}
\begin{verbatim}
$
python example.py
-
v
$
python example.py
-
v
...
@@ -161,24 +161,25 @@ python M.py
...
@@ -161,24 +161,25 @@ python M.py
This won't display anything unless an example fails, in which case the
This won't display anything unless an example fails, in which case the
failing example(s) and the cause(s) of the failure(s) are printed to stdout,
failing example(s) and the cause(s) of the failure(s) are printed to stdout,
and the final line of output is
\code
{
"Test failed."
}
.
and the final line of output is
\code
{
'Test failed.'
}
.
Run it with the
\
code
{
-v
}
switch instead:
Run it with the
\
programopt
{
-v
}
switch instead:
\begin{verbatim}
\begin{verbatim}
python M.py -v
python M.py -v
\end{verbatim}
\end{verbatim}
and a detailed report of all examples tried is printed to
\
var
{
stdout
}
,
and a detailed report of all examples tried is printed to
\
code
{
stdout
}
,
along with assorted summaries at the end.
along with assorted summaries at the end.
You can force verbose mode by passing
\code
{
verbose=1
}
to testmod, or
You can force verbose mode by passing
\code
{
verbose=1
}
to testmod, or
prohibit it by passing
\code
{
verbose=0
}
. In either of those cases,
prohibit it by passing
\code
{
verbose=0
}
. In either of those cases,
\
var
{
sys.argv
}
is not examined by testmod.
\
code
{
sys.argv
}
is not examined by testmod.
In any case, testmod returns a 2-tuple of ints
\var
{
(f, t)
}
, where
\var
{
f
}
In any case, testmod returns a 2-tuple of ints
\code
{
(
\var
{
f
}
,
is the number of docstring examples that failed and
\var
{
t
}
is the total
\var
{
t
}
)
}
, where
\var
{
f
}
is the number of docstring examples that
number of docstring examples attempted.
failed and
\var
{
t
}
is the total number of docstring examples
attempted.
\subsection
{
Which Docstrings Are Examined?
}
\subsection
{
Which Docstrings Are Examined?
}
...
@@ -187,12 +188,12 @@ module docstring, and all function, class and method docstrings are
...
@@ -187,12 +188,12 @@ module docstring, and all function, class and method docstrings are
searched, with the exception of docstrings attached to objects with private
searched, with the exception of docstrings attached to objects with private
names.
names.
In addition, if
\
var
{
M.
__
test
__}
exists and "is true", it must be a dict,
In addition, if
\
code
{
M.
__
test
__}
exists and "is true", it must be a
and each entry maps a (string) name to a function object, class object, or
dict, and each entry maps a (string) name to a function object, class
string. Function and class object docstrings found from
\var
{
M.
__
test
__}
object, or string. Function and class object docstrings found from
are searched even if the name is private, and strings are searched directly
\code
{
M.
__
test
__}
are searched even if the name is private, and
as if they were docstrings. In output, a key
\var
{
K
}
in
\var
{
M.
__
test
__}
strings are searched directly as if they were docstrings. In output,
appears with name
a
key
\code
{
K
}
in
\code
{
M.
__
test
__}
a
ppears with name
\begin{verbatim}
\begin{verbatim}
<name of M>.
__
test
__
.K
<name of M>.
__
test
__
.K
...
@@ -201,7 +202,7 @@ appears with name
...
@@ -201,7 +202,7 @@ appears with name
Any classes found are recursively searched similarly, to test docstrings in
Any classes found are recursively searched similarly, to test docstrings in
their contained methods and nested classes. While private names reached
their contained methods and nested classes. While private names reached
from
\module
{
M
}
's globals are skipped, all names reached from
from
\module
{
M
}
's globals are skipped, all names reached from
\
var
{
M.
__
test
__}
are searched.
\
code
{
M.
__
test
__}
are searched.
\subsection
{
What's the Execution Context?
}
\subsection
{
What's the Execution Context?
}
...
@@ -216,7 +217,7 @@ docstrings to use globals inappropriate for them.
...
@@ -216,7 +217,7 @@ docstrings to use globals inappropriate for them.
You can force use of your own dict as the execution context by passing
You can force use of your own dict as the execution context by passing
\code
{
globs=your
_
dict
}
to
\function
{
testmod()
}
instead. Presumably this
\code
{
globs=your
_
dict
}
to
\function
{
testmod()
}
instead. Presumably this
would be a copy of
\
var
{
M.
__
dict
__}
merged with the globals from other
would be a copy of
\
code
{
M.
__
dict
__}
merged with the globals from other
imported modules.
imported modules.
\subsection
{
What About Exceptions?
}
\subsection
{
What About Exceptions?
}
...
@@ -233,19 +234,19 @@ traceback itself. For example:
...
@@ -233,19 +234,19 @@ traceback itself. For example:
\end{verbatim}
\end{verbatim}
Note that only the exception type and value are compared (specifically,
Note that only the exception type and value are compared (specifically,
only the last line in the traceback). The various
\code
{
"File"
}
lines in
only the last line in the traceback). The various
``File''
lines in
between can be left out (unless they add significantly to the documentation
between can be left out (unless they add significantly to the documentation
value of the example).
value of the example).
\subsection
{
Advanced Usage
}
\subsection
{
Advanced Usage
}
\function
{
testmod()
}
actually creates a local instance of class
\function
{
testmod()
}
actually creates a local instance of class
\class
{
doctest.
Tester
}
, runs appropriate methods of that class, and merges
\class
{
Tester
}
, runs appropriate methods of that class, and merges
the results into global
\class
{
Tester
}
instance
\
var
{
doctest.
master
}
.
the results into global
\class
{
Tester
}
instance
\
code
{
master
}
.
You can create your own instances of
\class
{
doctest.Tester
}
, and so build
You can create your own instances of
\class
{
Tester
}
, and so build your
your own policies, or even run methods of
\var
{
doctest.master
}
directly.
own policies, or even run methods of
\code
{
master
}
directly. See
See
\var
{
doctest.
Tester.
__
doc
__}
for details.
\code
{
Tester.
__
doc
__}
for details.
\subsection
{
How are Docstring Examples Recognized?
}
\subsection
{
How are Docstring Examples Recognized?
}
...
@@ -275,7 +276,7 @@ the business of guessing what you think a tab means).
...
@@ -275,7 +276,7 @@ the business of guessing what you think a tab means).
Any expected output must immediately follow the final
\code
{
">>>"
}
or
Any expected output must immediately follow the final
\code
{
">>>"
}
or
\code
{
"..."
}
line containing the code, and the expected output (if any)
\code
{
"..."
}
line containing the code, and the expected output (if any)
extends to the next
\code
{
">>>"
}
or all-whitespace line.
That's it.
extends to the next
\code
{
">>>"
}
or all-whitespace line.
The fine print:
The fine print:
...
@@ -304,13 +305,14 @@ The starting column doesn't matter:
...
@@ -304,13 +305,14 @@ The starting column doesn't matter:
\begin{verbatim}
\begin{verbatim}
>>> assert "Easy!"
>>> assert "Easy!"
>>> import math
>>> import math
>>> math.floor(1.9)
>>> math.floor(1.9)
1.0
1.0
\end{verbatim}
\end{verbatim}
and as many leading whitespace characters are stripped from the expected
and as many leading whitespace characters are stripped from the expected
output as appeared in the initial ">>>" line that triggered it.
output as appeared in the initial ">>>" line that triggered it.
\end{itemize}
\subsection
{
Warnings
}
\subsection
{
Warnings
}
...
@@ -322,11 +324,12 @@ output as appeared in the initial ">>>" line that triggered it.
...
@@ -322,11 +324,12 @@ output as appeared in the initial ">>>" line that triggered it.
from XYZ import XYZclass
from XYZ import XYZclass
\end{verbatim}
\end{verbatim}
then
\class
{
XYZclass
}
is a name in
\var
{
M.
__
dict
__}
too, and doctest has no
then
\class
{
XYZclass
}
is a name in
\code
{
M.
__
dict
__}
too, and doctest
way to know that
\class
{
XYZclass
}
wasn't *defined* in
\module
{
M
}
. So it may
has no way to know that
\class
{
XYZclass
}
wasn't
\emph
{
defined
}
in
try to execute the examples in
\class
{
XYZclass
}
's docstring, and those in
\module
{
M
}
. So it may try to execute the examples in
turn may require a different set of globals to work correctly. I prefer to
\class
{
XYZclass
}
's docstring, and those in turn may require a
do
\code
{
import *
}
- friendly imports, a la
different set of globals to work correctly. I prefer to do
``
\code
{
import *
}
''-friendly imports, a la
\begin{verbatim}
\begin{verbatim}
from XYZ import XYZclass as
_
XYZclass
from XYZ import XYZclass as
_
XYZclass
...
@@ -400,6 +403,7 @@ often contrive doctest examples to produce numbers of that form:
...
@@ -400,6 +403,7 @@ often contrive doctest examples to produce numbers of that form:
Simple fractions are also easier for people to understand, and that makes
Simple fractions are also easier for people to understand, and that makes
for better documentation.
for better documentation.
\end{enumerate}
\subsection
{
Soapbox
}
\subsection
{
Soapbox
}
...
@@ -425,4 +429,4 @@ by and "things change". I'm still amazed at how often one of my doctest
...
@@ -425,4 +429,4 @@ by and "things change". I'm still amazed at how often one of my doctest
examples stops working after a "harmless" change.
examples stops working after a "harmless" change.
For exhaustive testing, or testing boring cases that add no value to the
For exhaustive testing, or testing boring cases that add no value to the
docs, define a
\
var
{__
test
__}
dict instead. That's what it's for.
docs, define a
\
code
{__
test
__}
dict instead. That's what it's for.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment