[Python-bugs-list] [ python-Bugs-661354 ] test_strptime fails on the Mac

SourceForge.net noreply@sourceforge.net
Sat, 04 Jan 2003 00:34:00 -0800


Bugs item #661354, was opened at 2003-01-02 14:29
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=661354&group_id=5470

Category: Python Library
Group: Python 2.3
Status: Open
Resolution: None
Priority: 7
Submitted By: Jack Jansen (jackjansen)
Assigned to: Jack Jansen (jackjansen)
Summary: test_strptime fails on the Mac

Initial Comment:
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


----------------------------------------------------------------------

Comment By: Brett Cannon (bcannon)
Date: 2003-01-04 00:34

Message:
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.

----------------------------------------------------------------------

Comment By: Jack Jansen (jackjansen)
Date: 2003-01-03 18:26

Message:
Logged In: YES 
user_id=45365

Nou, dank je wel... :-)

----------------------------------------------------------------------

Comment By: Jack Jansen (jackjansen)
Date: 2003-01-03 16:01

Message:
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")
''
>>> 

----------------------------------------------------------------------

Comment By: Brett Cannon (bcannon)
Date: 2003-01-03 14:52

Message:
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?

----------------------------------------------------------------------

Comment By: Jack Jansen (jackjansen)
Date: 2003-01-03 08:10

Message:
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:-)

----------------------------------------------------------------------

Comment By: Brett Cannon (bcannon)
Date: 2003-01-02 16:39

Message:
Logged In: YES 
user_id=357491

And for Jack's own personal knowledge, test_strptime is only
run against _strptime.py.

----------------------------------------------------------------------

Comment By: Brett Cannon (bcannon)
Date: 2003-01-02 16:38

Message:
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.

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2003-01-02 16:01

Message:
Logged In: YES 
user_id=31435

FYI, it also passes on Windows (98SE and 2K).

----------------------------------------------------------------------

Comment By: Brett Cannon (bcannon)
Date: 2003-01-02 15:54

Message:
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>.

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2003-01-02 14:44

Message:
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.

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2003-01-02 14:40

Message:
Logged In: YES 
user_id=6380

I've forwarded this to Brett Cannon -- he's the author,
maybe he understands what's going on.


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=661354&group_id=5470