summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2003-06-27 20:48:05 (GMT)
committerTim Peters <tim.peters@gmail.com>2003-06-27 20:48:05 (GMT)
commit6ebe61fa807d250ccab419473abd8d746a932e75 (patch)
tree18350da8265076dbebafc9fca16fe1b5506f6206 /Doc
parent6cf26195c6e206cba1bb3ebe554e82ab52304bd5 (diff)
downloadcpython-6ebe61fa807d250ccab419473abd8d746a932e75.zip
cpython-6ebe61fa807d250ccab419473abd8d746a932e75.tar.gz
cpython-6ebe61fa807d250ccab419473abd8d746a932e75.tar.bz2
A hack to ease compatibility with pre-2.3 Pythons: by default, doctest
now accepts "True" when a test expects "1", and similarly for "False" versus "0". This is un-doctest-like, but on balance makes it much more pleasant to write doctests that pass under 2.2 and 2.3. I expect it to go away again, when 2.2 is forgotten. In the meantime, there's a new doctest module constant that can be passed to a new optional argument, if you want to turn this behavior off. Note that this substitution is very simple-minded: the expected and actual outputs have to consist of single tokens. No attempt is made, e.g., to accept [True, False] when a test expects [1, 0]. This is a simple hack for simple tests, and I intend to keep it that way.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/lib/libdoctest.tex17
1 files changed, 17 insertions, 0 deletions
diff --git a/Doc/lib/libdoctest.tex b/Doc/lib/libdoctest.tex
index 9a795e9..253d6b4 100644
--- a/Doc/lib/libdoctest.tex
+++ b/Doc/lib/libdoctest.tex
@@ -398,6 +398,23 @@ def _test():
import doctest, sys
doctest.testmod()
\end{verbatim}
+
+\item WYSIWYG isn't always the case, starting in Python 2.3. The
+ string form of boolean results changed from \code{"0"} and
+ \code{"1"} to \code{"False"} and \code{"True"} in Python 2.3.
+ This makes it clumsy to write a doctest showing boolean results that
+ passes under multiple versions of Python. In Python 2.3, by default,
+ and as a special case, if an expected output block consists solely
+ of \code{"0"} and the actual output block consists solely of
+ \code{"False"}, that's accepted as an exact match, and similarly for
+ \code{"1"} versus \code{"True"}. This behavior can be turned off by
+ passing the new (in 2.3) module constant
+ \constant{DONT_ACCEPT_TRUE_FOR_1} as the value of \function{testmod()}'s
+ new (in 2.3) optional \var{optionflags} argument. Some years after
+ the integer spellings of booleans are history, this hack will
+ probably be removed again.
+
+
\end{enumerate}