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: test_strptime fails on the Mac
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: jackjansen Nosy List: brett.cannon, gvanrossum, jackjansen, tim.peters
Priority: high Keywords:

Created on 2003-01-02 22:29 by jackjansen, last changed 2022-04-10 16:06 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
strptimetest.txt jackjansen, 2003-01-03 16:10
Messages (13)
msg13825 - (view) Author: Jack Jansen (jackjansen) * (Python committer) Date: 2003-01-02 22:29
test_strptime fails for MacPython-OS9. It appears to be an error in the test itself, but it could be this error is triggered only on the Mac (because it doesn't have a builtin strptime() function but uses the pure Python strptime implementation). Here is the first stacktrace from the test (a lot of very similar ones follow):
Traceback (most recent call last):
  File "Moes:SWdev:Jack:MacPython:Lib:test:test_strptime.py", line 183, in test_compile
    compiled = self.time_re.compile("%%%s"% directive)
  File "Moes:SWdev:Jack:MacPython:Lib:_strptime.py", line 394, in compile
    return re_compile(self.pattern(format), IGNORECASE)
  File "Moes:SWdev:Jack:MacPython:Lib:sre.py", line 179, in compile
    return _compile(pattern, flags)
  File "Moes:SWdev:Jack:MacPython:Lib:sre.py", line 229, in _compile
    raise error, v # invalid expression
error: redefinition of group name 'Z' as group 2; was group 1
msg13826 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2003-01-02 22:40
Logged In: YES 
user_id=6380

I've forwarded this to Brett Cannon -- he's the author,
maybe he understands what's going on.
msg13827 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2003-01-02 22:44
Logged In: YES 
user_id=6380

BTW, there's an #undef HAVE_STRPTIME in timemodule.c, so
that *everybody* will *always* be using the Python
implementation. The test passes for me on Linux, FWIW.
msg13828 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2003-01-02 23:54
Logged In: YES 
user_id=357491

As for the bug, obviously a regex is being created where the
regex group Z is being specified twice.  I will take a look,
but I just ran the tests and I am having no problems on OS X
10.2.3.  I have some ideas on where this trouble could be
produced, though, so I will see if I can find a problem or
come up with some code Jack can run to try to help figure
out the problem.  Are the "very similar ones" that follow
this stack trace all from the same line in test_strptime, or
all from the same line in _strptime?  In other words, are
they all the same error being caused by the same test or the
same chunk of code in _strptime?  Or am I so unlucky that it
is just the same redefinition error but with everything else
different every time?

Oh, and one quick syntax thing; line 394 in test_strptime.py
has a string where the ``%`` operator has no space between
it and the string being worked on.  I know what a stickler
you are, Guido, so I thought you should know <wink>.
msg13829 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2003-01-03 00:01
Logged In: YES 
user_id=31435

FYI, it also passes on Windows (98SE and 2K).
msg13830 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2003-01-03 00:38
Logged In: YES 
user_id=357491

OK, with Tim's info I am starting to wonder if this isn't
some how an OS 9-specific thing.  To make sure, Jack, can
you run this code?::

>>> import _strptime
>>> _strptime.TimeRE().compile("%Z").pattern

The ``TimeRE`` class is what handles the creation of the
final regex to use for parsing the input string.  the
``.compile()`` method takes the directive format string and
outputs the regex pattern object.  The above code should
spit out a string similar to ``(?#)(?P<Z>PST|PDT|)`` (and
yes, that emptiness after the last pipe is expected; have to
handle chance that no timezone is actually in the input
string since it *could* be there).

If this has two Z groups, then we have found our problem. 
If not, then I am goiing to need basically all the
tracebacks to figure  this one out.
msg13831 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2003-01-03 00:39
Logged In: YES 
user_id=357491

And for Jack's own personal knowledge, test_strptime is only
run against _strptime.py.
msg13832 - (view) Author: Jack Jansen (jackjansen) * (Python committer) Date: 2003-01-03 16:10
Logged In: YES 
user_id=45365

No two Z groups, but I do get something different than you, with no timezone names:

>>> import _strptime
>>> _strptime.TimeRE().compile("%Z").pattern
'(?#)(?P<Z>||)'

I've attached the whole output of test_strptime. Enjoy! (hihi:-)
msg13833 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2003-01-03 22:52
Logged In: YES 
user_id=357491

Congrats, Jack, you have found another edge case I didn't
expect; a platform that doesn't know its own possible
timezones.  =)  This means that ``time.tzname`` comes out
with an tuple with no values.  Does ``time.strftime("%Z")``
output anything?

That regex will match absolutely anything.  This would
explain why there are ending up more than one Z group in the
regex (probably happening when creating an LC_* value).

So, I will write up a patch later today that will check for
this special edge case of a possible regex that will match
anything and make sure it doesn't output anything (basically
make the Z regex be the empty string).  _strptime already
leaves the timezone value at -1 if it can't determine what
timezone it is so at least that doesn't change anything.  I
will also add a test to the suite.

Oh,, and a question for  you, Guido.  Would  you prefer it
if I removed the ``__author__`` and ``__email__`` variables
and just added a small comment in the doc string for author
and contact info?  Or should I just leave them?
msg13834 - (view) Author: Jack Jansen (jackjansen) * (Python committer) Date: 2003-01-04 00:01
Logged In: YES 
user_id=45365

Close, but not an empty tuple but a tuple of empty strings:
>>> import time
>>> time.tzname
('', '')
>>> time.strftime("%Z")
''
>>> 
msg13835 - (view) Author: Jack Jansen (jackjansen) * (Python committer) Date: 2003-01-04 02:26
Logged In: YES 
user_id=45365

Nou, dank je wel... :-)
msg13836 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2003-01-04 08:34
Logged In: YES 
user_id=357491

Patch #662053 fixes _strptime.py to handle any possibility
of a locale not knowing anything about a certain thing
(timezone, AM/PM as in Swedish, etc.).

Also added two tests to the test suite.  Left unassigned and
said it was for the LIbrary and not MacOS specifically since
it is a general fix.
msg13837 - (view) Author: Jack Jansen (jackjansen) * (Python committer) Date: 2003-01-15 23:03
Logged In: YES 
user_id=45365

Fix checked in as _strptime.py rev 1.9.
History
Date User Action Args
2022-04-10 16:06:05adminsetgithub: 37695
2003-01-02 22:29:55jackjansencreate