[Python-Dev] Re: test_strptime; test_logging; test_time failure (was: cygwin errors)

Brett C. drifty@alum.berkeley.edu
Tue, 22 Jul 2003 16:40:35 -0700


Tim Peters wrote:

> Note that I'm on Win98SE now (previous email today was on Win2K).
> 
> Under current CVS, but with regrtest hacked not to do sys.exit():
> 
> C:\Code\python\PCbuild>python -i ../lib/test/regrtest.py test_strptime
>                                                          test_logging
>                                                          test_time
> test_strptime
> test_logging
> test_time
> All 3 tests OK.
> 
>>>>import forbrett
> 
> time.strftime("%c")
> '07/22/03 19:11:50'
> 
> _strptime.TimeRE()['c']
> '(?P<m>1[0-2]|0[1-9]|[1-9])/(?P<d>3[0-1]|[1-2]\\d|0[1-9]|
> [1-9]| [1-9])/(?P<y>\\d\\d)\\s*(?P<H>2[0-3]|[0-1]\\d|\\d)
> :(?P<M>[0-5]\\d|\\d):(?P<S>6[0-1]|[0-5]\\d|\\d)'
> 
> locale.getdefaultlocale()
> ('en_US', 'cp1252')
> 
> locale.getlocale(locale.LC_TIME)
> (None, None)
> 
> 
> 
> Again, but reverting Jeremy's test_logging locale fiddling:
> 
> C:\Code\python\PCbuild>python -i ../lib/test/regrtest.py test_strptime
>                                                          test_logging
>                                                          test_time
> test_strptime
> test_logging
> test_time
> test test_time failed -- Traceback (most recent call last):
>   File "C:\CODE\PYTHON\lib\test\test_time.py", line 49, in test_strptime
>     self.fail('conversion specifier: %r failed.' % format)
>   File "C:\CODE\PYTHON\lib\unittest.py", line 260, in fail
>     raise self.failureException, msg
> AssertionError: conversion specifier: ' %c' failed.
> 
> 2 tests OK.
> 1 test failed:
>     test_time
> 
>>>>import forbrett
> 
> time.strftime("%c")
> '07/22/2003 07:14:31 PM'
> 
> _strptime.TimeRE()['c']
> '(?P<m>1[0-2]|0[1-9]|[1-9])/(?P<d>3[0-1]|[1-2]\\d|0[1-9]|
> [1-9]| [1-9])/(?P<y>\\d\\d)\\s*(?P<H>2[0-3]|[0-1]\\d|\\d)
> :(?P<M>[0-5]\\d|\\d):(?P<S>6[0-1]|[0-5]\\d|\\d)'
> 
> locale.getdefaultlocale()
> ('en_US', 'cp1252')
> 
> locale.getlocale(locale.LC_TIME)
> ['English_United States', '1252']
> 
> 
> 
> 
> This is forbrett.py:
> 
> """
> def dump(tag, value):
>     import pprint
>     print tag
>     pprint.pprint(value)
>     print
> 
> import time
> dump('time.strftime("%c")',
>       time.strftime("%c"))
> 
> import _strptime
> dump("_strptime.TimeRE()['c']",
>       _strptime.TimeRE()['c'])
> 
> 
> import locale
> dump("locale.getdefaultlocale()",
>       locale.getdefaultlocale())
> 
> dump("locale.getlocale(locale.LC_TIME)",
>       locale.getlocale(locale.LC_TIME))
> """
> 
> [Brett C.]
> 
>>OK, the only thing I can think of is that the locale info has changed
>>ever so subtly and the checking of locale.getlocale(locale.LC_TIME)[0]
>>or locale.getdefaultlocale()[0] is not cutting it.  Next thing to try
>>is to see what values locale.getlocale(locale.LC_TIME) and
>>locale.getdefaultlocale() have (notice I am asking for the full value
>>and not just the 0 item) after each test is run.  It is possible the
>>cache in _strptime is not being cleared because it is not picking up
>>the change in locale by only checking the 0 item.
>>

I should have been more explicit; I meant after *every* individual test 
and not after the battery of tests.  Either way we can do a quick check, 
Tim, if you can try out this patch::

Index: Lib/_strptime.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/_strptime.py,v
retrieving revision 1.21
diff -u -r1.21 _strptime.py
--- Lib/_strptime.py    13 Jul 2003 01:31:38 -0000      1.21
+++ Lib/_strptime.py    22 Jul 2003 23:37:03 -0000
@@ -27,11 +27,11 @@

  def _getlang():
      # Figure out what the current language is set to.
-    current_lang = locale.getlocale(locale.LC_TIME)[0]
+    current_lang = locale.getlocale(locale.LC_TIME)
      if current_lang:
          return current_lang
      else:
-        current_lang = locale.getdefaultlocale()[0]
+        current_lang = locale.getdefaultlocale()
          if current_lang:
              return current_lang
          else:



We can see if that fixes it.  Obviously ignore the test_strptime 
failures that will pop up because of this.  If this does not fix it, 
then bye-bye caching.

>>If there is not some obvious difference in values then the cache will
>>have to be deleted and strptime performance will drop but the problem
>>will go away.
> 
> 
> Barry agrees <wink>.

Oh good.  Last thing I would want is Benevolent Dictator For A Release 
to disagree with me; must be because we are both American and not Dutch.  =)

-Brett