classification
Title: test_time fails: time data 'LMT' does not match format '%Z'
Type: behavior Stage: resolved
Components: Library (Lib), Tests Versions: Python 3.3
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, belopolsky, flox, nadeem.vawda, pitrou, python-dev, rosslagerwall, vinay.sajip
Priority: deferred blocker Keywords: buildbot

Created on 2011-11-01 14:05 by flox, last changed 2011-11-16 16:35 by flox. This issue is now closed.

Messages (17)
msg146776 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2011-11-01 14:05
After changeset 55a3b563f0db the Gentoo buildbot is complaining.


======================================================================
FAIL: test_strptime (test.test_time.TimeTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.x.ochtman-gentoo-amd64/build/Lib/test/test_time.py", line 159, in test_strptime
    time.strptime(strf_output, format)
ValueError: time data 'LMT' does not match format '%Z'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.x.ochtman-gentoo-amd64/build/Lib/test/test_time.py", line 162, in test_strptime
    (format, strf_output))
AssertionError: conversion specifier '%Z' failed with 'LMT' input.

----------------------------------------------------------------------
msg146778 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-11-01 14:12
New changeset 2771f7e96a52 by Florent Xicluna in branch 'default':
Add temporary tests to troubleshoot issue #13309 on Gentoo buildbot.
http://hg.python.org/cpython/rev/2771f7e96a52
msg146780 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-11-01 15:07
New changeset bb0ae7df08f8 by Florent Xicluna in branch 'default':
Troubleshoot issue #13309 on Gentoo buildbot.
http://hg.python.org/cpython/rev/bb0ae7df08f8
msg146784 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-11-01 16:06
New changeset 5b1e1967ea9d by Florent Xicluna in branch 'default':
Replace temporary tests with the real test case for issue #13309 on Gentoo.
http://hg.python.org/cpython/rev/5b1e1967ea9d
msg146787 - (view) Author: Ross Lagerwall (rosslagerwall) (Python committer) Date: 2011-11-01 16:22
"""
import time
import sys

t = time.gmtime(time.time())
s = time.strftime('%Z', t)
print(s)

time.mktime((-1, 1, 1, 0, 0, 0, -1, -1, -1))

t = time.gmtime(time.time())
s = time.strftime('%Z', t)
print(s)
"""
outputs:
SAST
LMT

on my Gentoo box. I'm still figuring out why...
msg146790 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2011-11-01 16:40
It seems that "mktime" is buggy on Gentoo.
You can try to reset its state in some way before to retry strftime:


t = time.gmtime(time.time())
s = time.strftime('%Z', t)
print(s)

time.mktime((-1, 1, 1, 0, 0, 0, -1, -1, -1))
s = time.strftime('%Z', t)
print(s)

time.mktime((1, 1, 1, 0, 0, 0, 0, 0, -1))
s = time.strftime('%Z', t)
print(s)


I guess it could output:
SAST
LMT
SAST
msg146791 - (view) Author: Ross Lagerwall (rosslagerwall) (Python committer) Date: 2011-11-01 16:45
It outputs:
SAST
LMT
LMT

An equivalent C program to the first test:
"""
#include <time.h>
#include <stdlib.h>
#include <stdio.h>

int main() {

    time_t t;
    struct tm *tmp;

    t = time(NULL);
    tmp = localtime(&t);

    char str[200];
    strftime(str, sizeof(str), "%Z", tmp);

    puts(str);

    struct tm tmp2;
    tmp2.tm_sec = 0;
    tmp2.tm_min = 0;
    tmp2.tm_hour = 0;
    tmp2.tm_mday = 1;
    tmp2.tm_mon = 1;
    tmp2.tm_year = -1;
    tmp2.tm_wday = -1;
    tmp2.tm_yday = -1;
    tmp2.tm_isdst = -1;
    mktime(&tmp2);

    t = time(NULL);
    tmp = localtime(&t);

    strftime(str, sizeof(str), "%Z", tmp);

    puts(str);

    return 0;
}
"""

Outputs (as expected):
SAST
SAST

Perhaps it's not mktime?
msg146798 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2011-11-01 17:49
See also issue #13313 on timezone, seen on x86 FreeBSD 7.2
msg147081 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2011-11-05 12:07
It's not just Gentoo. I get this error repeatably on Ubuntu Oneiric 64- bit and Linux Mint Katya 64-bit, though not on the 32-bit variants.
msg147122 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-11-05 23:46
I also get this error on Mageia. If this can't be fixed, the test should be skipped or removed.
msg147266 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2011-11-07 23:27
LMT stands for Local Mean Time.

I found a report of someone having an issue parsing timezone with Python 2.6. Looks quite similar.
http://www.aczoom.com/forums/blockhosts/mar-10-151801-domains-blockhosts5599-error-failed-to-parse-date-for-ip-18911419951
msg147413 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-11-10 23:38
It is definitely a glibc issue. Here's a C snippet to reproduce:

"""
#include <time.h>
#include <stdlib.h>

int main() {
    time_t t;
    struct tm tmp;
    char str[200];

    t = time(NULL);
    tmp = *gmtime(&t);
    tmp.tm_gmtoff = 0;
    tmp.tm_zone = NULL;

    strftime(str, sizeof(str), "%Z", &tmp);
    puts(str);

    t = -2461446500;
    localtime(&t);

    t = time(NULL);
    tmp = *gmtime(&t);
    tmp.tm_gmtoff = 0;
    tmp.tm_zone = NULL;

    strftime(str, sizeof(str), "%Z", &tmp);
    puts(str);

    return 0;
}
"""

Output:
CET
PMT


Calling localtime() or mktime() with a time largely in the past seems to corrupt the glibc's internal time structures (the "char *tm_zone[]").
msg147417 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-11-11 02:09
New changeset 05164831011e by Antoine Pitrou in branch 'default':
Avoid a glibc bug in test_time (issue #13309)
http://hg.python.org/cpython/rev/05164831011e
msg147418 - (view) Author: Ross Lagerwall (rosslagerwall) (Python committer) Date: 2011-11-11 04:19
Has it been reported?
msg147426 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-11-11 11:15
> Has it been reported?

Yes, in http://sourceware.org/bugzilla/show_bug.cgi?id=13401
msg147440 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-11-11 18:00
New changeset bcd347cd6bf2 by Florent Xicluna in branch 'default':
Use unittest.skipUnless to skip the test related to the glibc bug, issue #13309.
http://hg.python.org/cpython/rev/bcd347cd6bf2
msg147441 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2011-11-11 18:02
Thank you for the investigation, and the bug report to the glibc team.
I propose to close it as "won't fix".
History
Date User Action Args
2011-11-16 16:35:20floxsetstatus: pending -> closed
2011-11-11 18:02:09floxsetstatus: open -> pending
resolution: wont fix
messages: + msg147441

stage: test needed -> resolved
2011-11-11 18:00:17python-devsetmessages: + msg147440
2011-11-11 11:15:19pitrousetmessages: + msg147426
2011-11-11 04:19:34rosslagerwallsetmessages: + msg147418
2011-11-11 02:09:20python-devsetmessages: + msg147417
2011-11-10 23:38:13pitrousetmessages: + msg147413
2011-11-09 19:45:27nadeem.vawdasetnosy: + nadeem.vawda
2011-11-07 23:27:54floxsetmessages: + msg147266
components: + Library (Lib)
2011-11-06 03:21:24Arfreversetnosy: + Arfrever
2011-11-05 23:46:43pitrousetnosy: + pitrou
messages: + msg147122
2011-11-05 12:07:54vinay.sajipsetnosy: + vinay.sajip
messages: + msg147081
2011-11-03 14:27:51pitrousetpriority: normal -> deferred blocker
2011-11-01 17:49:43floxsetmessages: + msg146798
2011-11-01 16:58:28floxsetnosy: + belopolsky
2011-11-01 16:45:48rosslagerwallsetmessages: + msg146791
2011-11-01 16:40:16floxsetmessages: + msg146790
2011-11-01 16:22:03rosslagerwallsetnosy: + rosslagerwall
messages: + msg146787
2011-11-01 16:06:54python-devsetmessages: + msg146784
2011-11-01 15:07:41python-devsetmessages: + msg146780
2011-11-01 14:12:51python-devsetnosy: + python-dev
messages: + msg146778
2011-11-01 14:05:03floxcreate