[issue10213] tests shouldn't fail with unset timezone

Ezio Melotti report at bugs.python.org
Sat Feb 23 08:38:38 CET 2013


Ezio Melotti added the comment:

I tried to reproduce the issue and copied /usr/share/zoneinfo/Factory to /etc/localtime as suggested in msg119762.
Only 2.7 and 3.2 are affected:
>>> import time
>>> time.strftime('%Z', time.gmtime(time.time()))
'Local time zone must be set--see zic manual page'

On 3.3+ this return 'GMT':
>>> import time
>>> time.strftime('%Z', time.gmtime(time.time()))
'GMT'

The error comes from the libc strftime:

$ cat tz.c 
#include <stdio.h>
#include <time.h>

int main() {
    int buflen;
    char outbuf[256];
    struct tm *buf;
    time_t curtime;

    time(&curtime);
    buf = localtime(&curtime);
    buflen = strftime(outbuf, 256, "%Z", buf);
    printf("outbuf: %s\nbuflen: %d\n", outbuf, buflen);
    return 0;
}
$ gcc -Wall -Wextra -O -ansi -pedantic tz.c -o tz
$ ./tz 
outbuf: Local time zone must be set--see zic manual page
buflen: 48

There are different possible solutions:
  1) we close the issue as out of date, since it's fixed in 3.3+;
  2) we fix the test on 2.7/3.2 by checking for the error message and raising a SkipTest;
  3) we fix the code on 2.7/3.2 by backporting the 3.3 implementation that returns 'GMT';
  4) we fix the code on 2.7/3.2 by checking for the error message and raising an exception;

----------
components: +Extension Modules
nosy: +ezio.melotti
stage:  -> needs patch
versions:  -Python 3.1
Added file: http://bugs.python.org/file29168/tz.c

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue10213>
_______________________________________


More information about the Python-bugs-list mailing list