diff options
author | Edward Loper <edloper@gradient.cis.upenn.edu> | 2004-09-28 04:29:57 (GMT) |
---|---|---|
committer | Edward Loper <edloper@gradient.cis.upenn.edu> | 2004-09-28 04:29:57 (GMT) |
commit | aec3c9b54fe2cbd8f4b04b6034341d333bc3936b (patch) | |
tree | f5f85259f6804bafb6c6342c068a58e724e4cb62 /Doc | |
parent | bfef8695103b947f688b8c4a7ff8fc19477fc528 (diff) | |
download | cpython-aec3c9b54fe2cbd8f4b04b6034341d333bc3936b.zip cpython-aec3c9b54fe2cbd8f4b04b6034341d333bc3936b.tar.gz cpython-aec3c9b54fe2cbd8f4b04b6034341d333bc3936b.tar.bz2 |
Added a new NORMALIZE_NUMBERS option, which causes number literals in
the expected output to match corresponding number literals in the
actual output if their values are equal (to ten digits of precision).
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/lib/libdoctest.tex | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/Doc/lib/libdoctest.tex b/Doc/lib/libdoctest.tex index 2635486..a30a432 100644 --- a/Doc/lib/libdoctest.tex +++ b/Doc/lib/libdoctest.tex @@ -581,6 +581,17 @@ TypeError: object doesn't support item assignment \end{datadesc} +\begin{datadesc}{NORMALIZE_NUMBERS} + When specified, number literals in the expected output will match + corresponding number literals in the actual output if their values + are equal (to ten digits of precision). For example, \code{1.1} + will match \code{1.1000000000000001}; and \code{1L} will match + \code{1} and \code{1.0}. Currently, \constant{NORMALIZE_NUMBERS} + can fail to normalize numbers when used in conjunction with + ellipsis. In particular, if an ellipsis marker matches one or + more numbers, then number normalization is not supported. +\end{datadesc} + \begin{datadesc}{COMPARISON_FLAGS} A bitmask or'ing together all the comparison flags above. \end{datadesc} @@ -702,7 +713,7 @@ can be useful. \versionchanged[Constants \constant{DONT_ACCEPT_BLANKLINE}, \constant{NORMALIZE_WHITESPACE}, \constant{ELLIPSIS}, - \constant{IGNORE_EXCEPTION_DETAIL}, + \constant{IGNORE_EXCEPTION_DETAIL}, \constant{NORMALIZE_NUMBERS}, \constant{REPORT_UDIFF}, \constant{REPORT_CDIFF}, \constant{REPORT_NDIFF}, \constant{REPORT_ONLY_FIRST_FAILURE}, \constant{COMPARISON_FLAGS} and \constant{REPORTING_FLAGS} @@ -740,6 +751,7 @@ in any particular order, so a test like % Hey! What happened to Monty Python examples? % Tim: ask Guido -- it's his example! +% doctest: ignore \begin{verbatim} >>> foo() {"Hermione": "hippogryph", "Harry": "broomstick"} @@ -747,6 +759,7 @@ in any particular order, so a test like is vulnerable! One workaround is to do +% doctest: ignore \begin{verbatim} >>> foo() == {"Hermione": "hippogryph", "Harry": "broomstick"} True @@ -754,6 +767,7 @@ True instead. Another is to do +% doctest: ignore \begin{verbatim} >>> d = foo().items() >>> d.sort() @@ -765,6 +779,7 @@ There are others, but you get the idea. Another bad idea is to print things that embed an object address, like +% doctest: ignore \begin{verbatim} >>> id(1.0) # certain to fail some of the time 7948648 @@ -776,6 +791,7 @@ Another bad idea is to print things that embed an object address, like The \constant{ELLIPSIS} directive gives a nice approach for the last example: +% doctest: ignore \begin{verbatim} >>> C() #doctest: +ELLIPSIS <__main__.C instance at 0x...> @@ -785,6 +801,7 @@ Floating-point numbers are also subject to small output variations across platforms, because Python defers to the platform C library for float formatting, and C libraries vary widely in quality here. +% doctest: ignore \begin{verbatim} >>> 1./7 # risky 0.14285714285714285 @@ -1618,6 +1635,7 @@ Doctest provides several mechanisms for debugging doctest examples: Then an interactive Python session may look like this: +% doctest: ignore \begin{verbatim} >>> import a, doctest >>> doctest.testmod(a) |