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

Created on 2011-11-03 19:03 by Gerald.Dalley, last changed 2011-11-04 22:50 by terry.reedy.

Messages (3)
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.
History
Date User Action Args
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