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
96976f8d
Commit
96976f8d
authored
Sep 25, 2004
by
Tim Peters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Since the LaTeX isn't doctest'ed, examples are always wrong <wink>.
parent
25422056
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
17 deletions
+21
-17
Doc/lib/libdoctest.tex
Doc/lib/libdoctest.tex
+21
-17
No files found.
Doc/lib/libdoctest.tex
View file @
96976f8d
...
...
@@ -2,8 +2,8 @@
Test interactive Python examples
}
\declaremodule
{
standard
}{
doctest
}
\moduleauthor
{
Tim Peters
}{
tim
_
one@users.sourceforge.net
}
\sectionauthor
{
Tim Peters
}{
tim
_
one@users.sourceforge.net
}
\moduleauthor
{
Tim Peters
}{
tim
@python.org
}
\sectionauthor
{
Tim Peters
}{
tim
@python.org
}
\sectionauthor
{
Moshe Zadka
}{
moshez@debian.org
}
\sectionauthor
{
Edward Loper
}{
edloper@users.sourceforge.net
}
...
...
@@ -11,17 +11,21 @@
The
\module
{
doctest
}
module searches for pieces of text that look like
interactive Python sessions, and then executes those sessions to
verify that they work exactly as shown. There are
two
common ways to
verify that they work exactly as shown. There are
several
common ways to
use doctest:
\begin{
enumerat
e}
\begin{
itemiz
e}
\item
To check that a module's docstrings are up-to-date by verifying
that all interactive examples still work as documented.
\item
To perform regression testing by verifying that interactive
examples from a test file or a test object work as expected.
\end{enumerate}
\item
To write tutorial documentation for a package, liberally
illustrated with input-ouput examples. Depending on whether
the examples or the expository text are emphasized, this has
the flavor of "literate testing" or "executable documentation".
\end{itemize}
Here's a complete but small example:
Here's a complete but small example
module
:
\begin{verbatim}
"""
...
...
@@ -81,16 +85,13 @@ def factorial(n):
result = 1
factor = 2
while factor <= n:
try:
result *= factor
except OverflowError:
result *= long(factor)
result *= factor
factor += 1
return result
def
_
test():
import doctest
return
doctest.testmod()
doctest.testmod()
if
__
name
__
== "
__
main
__
":
_
test()
...
...
@@ -138,10 +139,12 @@ Expecting:
...
OverflowError: n too large
ok
1
items had no tests:
__
main
__
.
_
test
2
items passed all tests:
1
tests in
example
8
tests in
example
.factorial
9
tests in
2
items.
1
tests in
__
main
__
8
tests in
__
main
__
.factorial
9
tests in
3
items.
9
passed and
0
failed.
Test passed.
$
...
...
@@ -150,9 +153,10 @@ $
That's all you need to know to start making productive use of
\module
{
doctest
}
! Jump in. The following sections provide full
details. Note that there are many examples of doctests in
the standard Python test suite and libraries.
the standard Python test suite and libraries. Especially useful examples
can be found in the standard test file
\file
{
Lib/test/test
_
doctest.py
}
.
\subsection
{
Simple Usage: Checking Examples in
\subsection
{
Simple Usage: Checking Examples in
Docstrings
\label
{
doctest-simple-testmod
}}
The simplest way to start using doctest (but not necessarily the way
...
...
@@ -1262,7 +1266,7 @@ initialized by the constructor, and should not be modified directly.
\class
{
DocTestFinder
}
defines the following method:
\begin{methoddesc}
{
find
}{
obj
\optional
{
, name
}
\optional
{
,
\begin{methoddesc}
{
find
}{
obj
\optional
{
, name
}
\optional
{
,
module
}
\optional
{
, globs
}
\optional
{
, extraglobs
}}
Return a list of the
\class
{
DocTest
}
s that are defined by
\var
{
obj
}
's docstring, or by any of its contained objects'
...
...
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