Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
92f21b13
Kaydet (Commit)
92f21b13
authored
Tem 11, 2003
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Document Jim Fulton's docttest extensions.
üst
b6d2f3e0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
70 additions
and
8 deletions
+70
-8
libdoctest.tex
Doc/lib/libdoctest.tex
+70
-8
No files found.
Doc/lib/libdoctest.tex
Dosyayı görüntüle @
92f21b13
...
...
@@ -65,7 +65,7 @@ def factorial(n):
raise ValueError("n must be >= 0")
if math.floor(n) != n:
raise ValueError("n must be exact integer")
if n+1 == n: #
e.g.,
1e300
if n+1 == n: #
catch a value like
1e300
raise OverflowError("n too large")
result = 1
factor = 2
...
...
@@ -243,13 +243,75 @@ value of the example).
\subsection
{
Advanced Usage
}
\function
{
testmod()
}
actually creates a local instance of class
\class
{
Tester
}
, runs appropriate methods of that class, and merges
the results into global
\class
{
Tester
}
instance
\code
{
master
}
.
You can create your own instances of
\class
{
Tester
}
, and so build your
own policies, or even run methods of
\code
{
master
}
directly. See
\code
{
Tester.
__
doc
__}
for details.
Several module level functions are available for controlling how doctests
are run.
\begin{funcdesc}
{
debug
}{
module, name
}
Debug a single docstring containing doctests.
Provide the
\var
{
module
}
(or dotted name of the module) containing the
docstring to be debugged and the
\var
{
name
}
(within the module) of the
object with the docstring to be debugged.
The doctest examples are extracted (see function
\function
{
testsource()
}
),
and written to a temporary file. The Python debugger,
\refmodule
{
pdb
}
,
is then invoked on that file.
\versionadded
{
2.3
}
\end{funcdesc}
\begin{funcdesc}
{
testmod
}{}
This function provides the most basic interface to the doctests.
It creates a local instance of class
\class
{
Tester
}
, runs appropriate
methods of that class, and merges the results into the global
\class
{
Tester
}
instance,
\code
{
master
}
.
To get finer control than
\function
{
testmod()
}
offers, create an instance
of
\class
{
Tester
}
with custom policies and run the methods of
\code
{
master
}
directly. See
\code
{
Tester.
__
doc
__}
for details.
\end{funcdesc}
\begin{funcdesc}
{
testsource
}{
module, name
}
Extract the doctest examples from a docstring.
Provide the
\var
{
module
}
(or dotted name of the module) containing the
tests to be extracted and the
\var
{
name
}
(within the module) of the object
with the docstring containing the tests to be extracted.
The doctest examples are returned as a string containing Python
code. The expected output blocks in the examples are converted
to Python comments.
\versionadded
{
2.3
}
\end{funcdesc}
\begin{funcdesc}
{
DocTestSuite
}{
\optional
{
module
}}
Convert doctest tests for a module to a
\refmodule
{
unittest
}
\class
{
TestSuite
}
.
The returned
\class
{
TestSuite
}
is to be run by the unittest framework
and runs each doctest in the module. If any of the doctests fail,
then the synthesized unit test fails, and a
\exception
{
DocTestTestFailure
}
exception is raised showing the name of the file containing the test and a
(sometimes approximate) line number.
The optional
\var
{
module
}
argument provides the module to be tested. It
can be a module object or a (possibly dotted) module name. If not
specified, the module calling
\function
{
DocTestSuite()
}
is used.
Example using one of the many ways that the
\refmodule
{
unittest
}
module
can use a
\class
{
TestSuite
}
:
\begin{verbatim}
import unittest
import doctest
import my
_
module
_
with
_
doctests
suite = doctest.DocTestSuite(my
_
module
_
with
_
doctests)
runner = unittest.TextTestRunner()
runner.run(suite)
\end{verbatim}
\versionadded
{
2.3
}
\end{funcdesc}
\subsection
{
How are Docstring Examples Recognized?
}
...
...
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