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
026f8dc1
Kaydet (Commit)
026f8dc1
authored
Agu 19, 2004
tarafından
Tim Peters
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Now that they've settled down, document doctest directives.
üst
3caf9c1e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
83 additions
and
11 deletions
+83
-11
libdoctest.tex
Doc/lib/libdoctest.tex
+66
-8
test_doctest.py
Lib/test/test_doctest.py
+17
-3
No files found.
Doc/lib/libdoctest.tex
Dosyayı görüntüle @
026f8dc1
...
...
@@ -298,12 +298,12 @@ be left out, or could just as well be three (or three hundred) commas.
exception detail, were added]
{
2.4
}
\subsection
{
Option Flags and Directive
Name
s
\label
{
doctest-options
}}
\subsection
{
Option Flags and Directives
\label
{
doctest-options
}}
A number of option flags control various aspects of doctest's comparison
behavior. Symbolic names for the flags are supplied as module constants,
behavior.
Symbolic names for the flags are supplied as module constants,
which can be or'ed together and passed to various functions. The names
can also be used in doctest directives.
can also be used in doctest directives
(see below)
.
\begin{datadesc}
{
DONT
_
ACCEPT
_
TRUE
_
FOR
_
1
}
By default, if an expected output block contains just
\code
{
1
}
,
...
...
@@ -340,9 +340,10 @@ can also be used in doctest directives.
\begin{datadesc}
{
ELLIPSIS
}
When specified, an ellipsis marker (
\code
{
...
}
) in the expected output
can match any substring in the actual output. This includes
substrings that span line boundaries, so it's best to keep usage of
this simple. Complicated uses can lead to the same kinds of
surprises that
\regexp
{
.*
}
is prone to in regular expressions.
substrings that span line boundaries, and empty substrings, so it's
best to keep usage of this simple. Complicated uses can lead to the
same kinds of "oops, it matched too much!" surprises that
\regexp
{
.*
}
is prone to in regular expressions.
\end{datadesc}
\begin{datadesc}
{
UNIFIED
_
DIFF
}
...
...
@@ -356,11 +357,68 @@ can also be used in doctest directives.
\end{datadesc}
A "doctest directive" is a trailing Python comment on a line of a doctest
example:
\begin{productionlist}
[doctest]
\production
{
directive
}
{
"#" "doctest:"
\token
{
on
_
or
_
off
}
\token
{
directive
_
name
}}
\production
{
on
_
or
_
off
}
{
"+" | "-"
}
\production
{
directive
_
name
}
{
"DONT
_
ACCEPT
_
BLANKLINE" | "NORMALIZE
_
WHITESPACE" | ...
}
\end{productionlist}
Whitespace is not allowed between the
\code
{
+
}
or
\code
{
-
}
and the
directive name. The directive name can be any of the option names
explained above.
The doctest directives appearing in a single example modify doctest's
behavior for that single example. Use
\code
{
+
}
to enable the named
behavior, or
\code
{
-
}
to disable it.
For example, this test passes:
\begin{verbatim}
>>> print range(20) #doctest: +NORMALIZE
_
WHITESPACE
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
\end{verbatim}
Without the directive it would fail, both because the actual output
doesn't have two blanks before the single-digit list elements, and
because the actual output is on a single line. This test also passes,
and requires a directive to do so:
\begin{verbatim}
>>> print range(20) # doctest:+ELLIPSIS
[0, 1, ..., 18, 19]
\end{verbatim}
Only one directive per physical line is accepted. If you want to
use multiple directives for a single example, you can add
\samp
{
...
}
lines to your example containing only directives:
\begin{verbatim}
>>> print range(20) #doctest: +ELLIPSIS
... #doctest: +NORMALIZE
_
WHITESPACE
[0, 1, ..., 18, 19]
\end{verbatim}
Note that since all options are disabled by default, and directives apply
only to the example they appear in, enabling options (via
\code
{
+
}
in a
directive) is usually the only meaningful choice. However, option flags
can also be passed to functions that run doctests, establishing different
defaults. In such cases, disabling an option via
\code
{
-
}
in a directive
can be useful.
\versionchanged
[Constants
\constant
{
DONT
_
ACCEPT
_
BLANKLINE
}
,
\constant
{
NORMALIZE
_
WHITESPACE
}
,
\constant
{
ELLIPSIS
}
,
\constant
{
UNIFIED
_
DIFF
}
, and
\constant
{
CONTEXT
_
DIFF
}
were added, and by default
\code
{
<BLANKLINE>
}
in expected output
matches an empty line in actual output]
{
2.4
}
were added; by default
\code
{
<BLANKLINE>
}
in expected output
matches an empty line in actual output; and doctest directives
were added]
{
2.4
}
\subsection
{
Advanced Usage
}
...
...
Lib/test/test_doctest.py
Dosyayı görüntüle @
026f8dc1
...
...
@@ -758,6 +758,11 @@ treated as equal:
>>> doctest.DocTestRunner(verbose=False, optionflags=flags).run(test)
(0, 1)
An example from the docs:
>>> print range(20) #doctest: +NORMALIZE_WHITESPACE
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
The ELLIPSIS flag causes ellipsis marker ("...") in the expected
output to match any substring in the actual output:
...
...
@@ -780,8 +785,8 @@ output to match any substring in the actual output:
>>> doctest.DocTestRunner(verbose=False, optionflags=flags).run(test)
(0, 1)
... should also match nothing gracefully (note that a regular-expression
implementation of ELLIPSIS would take a loooong time to match this one!):
... should also match nothing gracefully (note that a regular-expression
implementation of ELLIPSIS would take a loooong time to match this one!):
>>> for i in range(100):
... print i**2 #doctest: +ELLIPSIS
...
...
@@ -801,7 +806,7 @@ implementation of ELLIPSIS would take a loooong time to match this one!):
9801
...
... can be surprising; e.g., this test passes:
... can be surprising; e.g., this test passes:
>>> for i in range(21): #doctest: +ELLIPSIS
... print i
...
...
@@ -815,6 +820,15 @@ implementation of ELLIPSIS would take a loooong time to match this one!):
...
0
Examples from the docs:
>>> print range(20) # doctest:+ELLIPSIS
[0, 1, ..., 18, 19]
>>> print range(20) # doctest: +ELLIPSIS
... # doctest: +NORMALIZE_WHITESPACE
[0, 1, ..., 18, 19]
The UNIFIED_DIFF flag causes failures that involve multi-line expected
and actual outputs to be displayed using a unified diff:
...
...
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