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
7a6b4f02
Kaydet (Commit)
7a6b4f02
authored
Tem 17, 2003
tarafından
Fred Drake
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
more markup chages
üst
032fffef
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
33 deletions
+38
-33
libdoctest.tex
Doc/lib/libdoctest.tex
+38
-33
No files found.
Doc/lib/libdoctest.tex
Dosyayı görüntüle @
7a6b4f02
...
@@ -85,17 +85,18 @@ if __name__ == "__main__":
...
@@ -85,17 +85,18 @@ if __name__ == "__main__":
_
test()
_
test()
\end{verbatim}
\end{verbatim}
If you run
\file
{
example.py
}
directly from the command line,
doctest works
If you run
\file
{
example.py
}
directly from the command line,
its magic:
\module
{
doctest
}
works
its magic:
\begin{verbatim}
\begin{verbatim}
$
python example.py
$
python example.py
$
$
\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
Pass
\programopt
{
-v
}
to the script, and doctest prints a detailed log
worked. Pass
\programopt
{
-v
}
to the script, and
\module
{
doctest
}
of what it's trying, and prints a summary at the end:
prints a detailed log of what it's trying, and prints a summary at the
end:
\begin{verbatim}
\begin{verbatim}
$
python example.py
-
v
$
python example.py
-
v
...
@@ -135,9 +136,10 @@ Test passed.
...
@@ -135,9 +136,10 @@ Test passed.
$
$
\end{verbatim}
\end{verbatim}
That's all you need to know to start making productive use of doctest! Jump
That's all you need to know to start making productive use of
in. The docstrings in doctest.py contain detailed information about all
\module
{
doctest
}
! Jump in. The docstrings in
\file
{
doctest.py
}
contain
aspects of doctest, and we'll just cover the more important points here.
detailed information about all aspects of
\module
{
doctest
}
, and we'll
just cover the more important points here.
\subsection
{
Normal Usage
}
\subsection
{
Normal Usage
}
...
@@ -285,8 +287,8 @@ are run.
...
@@ -285,8 +287,8 @@ are run.
\end{funcdesc}
\end{funcdesc}
\begin{funcdesc}
{
DocTestSuite
}{
\optional
{
module
}}
\begin{funcdesc}
{
DocTestSuite
}{
\optional
{
module
}}
Convert doctest tests for a module to a
\refmodule
{
unittest
}
Convert doctest tests for a module to a
\class
{
TestSuite
}
.
\class
{
\refmodule
{
unittest
}
.
TestSuite
}
.
The returned
\class
{
TestSuite
}
is to be run by the unittest framework
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,
and runs each doctest in the module. If any of the doctests fail,
...
@@ -320,10 +322,11 @@ are run.
...
@@ -320,10 +322,11 @@ are run.
\subsection
{
How are Docstring Examples Recognized?
}
\subsection
{
How are Docstring Examples Recognized?
}
In most cases a copy-and-paste of an interactive console session works fine
In most cases a copy-and-paste of an interactive console session works
--- just make sure the leading whitespace is rigidly consistent (you can mix
fine---just make sure the leading whitespace is rigidly consistent
tabs and spaces if you're too lazy to do it right, but doctest is not in
(you can mix tabs and spaces if you're too lazy to do it right, but
the business of guessing what you think a tab means).
\module
{
doctest
}
is not in the business of guessing what you think a tab
means).
\begin{verbatim}
\begin{verbatim}
>>> # comments are ignored
>>> # comments are ignored
...
@@ -486,25 +489,27 @@ def _test():
...
@@ -486,25 +489,27 @@ def _test():
\subsection
{
Soapbox
}
\subsection
{
Soapbox
}
The first word in doctest is "doc", and that's why the author wrote
The first word in ``doctest'' is ``doc,'' and that's why the author
doctest: to keep documentation up to date. It so happens that doctest
wrote
\refmodule
{
doctest
}
: to keep documentation up to date. It so
makes a pleasant unit testing environment, but that's not its primary
happens that
\refmodule
{
doctest
}
makes a pleasant unit testing
purpose.
environment, but that's not its primary purpose.
Choose docstring examples with care. There's an art to this that needs to
Choose docstring examples with care. There's an art to this that
be learned --- it may not be natural at first. Examples should add genuine
needs to be learned---it may not be natural at first. Examples should
value to the documentation. A good example can often be worth many words.
add genuine value to the documentation. A good example can often be
If possible, show just a few normal cases, show endcases, show interesting
worth many words. If possible, show just a few normal cases, show
subtle cases, and show an example of each kind of exception that can be
endcases, show interesting subtle cases, and show an example of each
raised. You're probably testing for endcases and subtle cases anyway in an
kind of exception that can be raised. You're probably testing for
interactive shell: doctest wants to make it as easy as possible to capture
endcases and subtle cases anyway in an interactive shell:
those sessions, and will verify they continue to work as designed forever
\refmodule
{
doctest
}
wants to make it as easy as possible to capture
after.
those sessions, and will verify they continue to work as designed
forever after.
If done with care, the examples will be invaluable for your users, and will
pay back the time it takes to collect them many times over as the years go
If done with care, the examples will be invaluable for your users, and
by and "things change". I'm still amazed at how often one of my doctest
will pay back the time it takes to collect them many times over as the
examples stops working after a "harmless" change.
years go by and things change. I'm still amazed at how often one of
my
\refmodule
{
doctest
}
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
\code
{__
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