This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: IGNORE_CASE doctest option flag
Type: enhancement Stage: patch review
Components: Library (Lib) Versions: Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Gerald.Dalley, amaury.forgeotdarc, gregory.p.smith, justinba1010
Priority: normal Keywords: patch

Created on 2011-11-03 19:03 by Gerald.Dalley, last changed 2022-04-11 14:57 by admin.

Pull Requests
URL Status Linked Edit
PR 23547 open justinba1010, 2020-11-29 00:32
Messages (4)
msg146961 - (view) Author: Gerald Dalley (Gerald.Dalley) Date: 2011-11-03 19:03
It would be helpful to have a doctest flag that makes the test case insensitive.

Use case: nan values are printed as "nan" with typical Linux implementations, but as "NaN" on other operating systems like Solaris.

In a naive implementation, the core change to doctest.OutputChecker.check_output is:

+        if optionflags & IGNORE_CASE:
+            got        = got.lower()
+            want       = want.lower()
+            true_line  = "true\n"
+            false_line = "false\n"
+        else:
+            true_line  = "True\n"
+            false_line = "False\n"
+
         # Handle the common case first, for efficiency:
         # if they're string-identical, always return true.
         if got == want:
             return True

         # The values True and False replaced 1 and 0 as the return
         # value for boolean comparisons in Python 2.3.
         if not (optionflags & DONT_ACCEPT_TRUE_FOR_1):
-            if (got,want) == ("True\n", "1\n"):
+            if (got,want) == (true_line, "1\n"):
                 return True
-            if (got,want) == ("False\n", "0\n"):
+            if (got,want) == (false_line, "0\n"):
                 return True
msg146986 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2011-11-03 21:59
> Use case: nan values are printed as "nan" with typical Linux
> implementations, but as "NaN" on other operating systems like Solaris.

Did you test with Python 2.7 or above? ITSM that 
   repr(float("nan")) == "nan"
consistently on all platforms.
msg146989 - (view) Author: Gerald Dalley (Gerald.Dalley) Date: 2011-11-03 22:42
ITSM?

The motivating use case here comes from "nan" strings produced by libc in extension modules (even though python itself and some major libraries like numpy are consistent).  At least some versions Solaris and Linux differ in this particular case.
msg382022 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2020-11-28 22:10
FWIW, while i'm never a fan of doctests, this would also help reduce the impact of other golden value tests where different platforms capitalize their error messages or not.
History
Date User Action Args
2022-04-11 14:57:23adminsetgithub: 57546
2020-11-29 00:32:10justinba1010setkeywords: + patch
nosy: + justinba1010

pull_requests: + pull_request22426
stage: patch review
2020-11-28 22:10:30gregory.p.smithsetnosy: + gregory.p.smith

messages: + msg382022
versions: + Python 3.10, - Python 3.3
2011-11-04 22:50:36terry.reedysetversions: - Python 2.6, Python 3.1, Python 2.7, Python 3.2, Python 3.4
2011-11-03 22:42:44Gerald.Dalleysetmessages: + msg146989
2011-11-03 21:59:31amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg146986
2011-11-03 19:03:28Gerald.Dalleysettype: enhancement
2011-11-03 19:03:19Gerald.Dalleycreate