Issue 10213: tests shouldn't fail with unset timezone (original) (raw)

Created on 2010-10-27 11:51 by djc, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
tz.c ezio.melotti,2013-02-23 07:38
Messages (11)
msg119696 - (view) Author: Dirkjan Ochtman (djc) * (Python committer) Date: 2010-10-27 11:51
test_strptime in test_time fails when the timezone is not set: ====================================================================== FAIL: test_strptime (test.test_time.TimeTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "/var/tmp/portage/dev-lang/python-2.6.4/work/Python-2.6.4/Lib/test/test_time.py", line 117, in test_strptime (format, strf_output)) AssertionError: conversion specifier '%Z' failed with 'Local time zone must be set--see zic manual page' input. ---------------------------------------------------------------------- Ran 14 tests in 1.206s Maybe something like this is good enough? Index: test_time.py =================================================================== --- test_time.py (revision 85856) +++ test_time.py (working copy) @@ -111,6 +111,8 @@ try: time.strptime(strf_output, format) except ValueError: + if 'Local time zone must be set' in strf_output: + continue self.fail("conversion specifier %r failed with '%s' input." % (format, strf_output))
msg119715 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-10-27 14:48
My first reaction to this was the feeling that the error message was correct and appropriate :) But it is true that since it doesn't represent a failure in Python itself it shouldn't be reported as a failure. The test should be skipped, though, rather than just doing a continue, so that it appears as a skip in verbose test output. (You do that by raising a unittest.SkipTest exception.)
msg119716 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2010-10-27 15:20
On Wed, Oct 27, 2010 at 10:48 AM, R. David Murray <report@bugs.python.org> wrote: .. > My first reaction to this was the feeling that the error message was correct and appropriate :) > That was my first reaction as well. > But it is true that since it doesn't represent a failure in Python itself it shouldn't be reported as a failure. >  The test should be skipped, though, rather than just doing a continue, so that it appears as a skip in verbose > test output.  (You do that by raising a unittest.SkipTest exception.) I am not so sure about that. Changing fail to skip will pretty much disable the test. There is no assert in the test. Maybe we should replace the fail on ValueError with a real round-trip test? Now, if the test has prerequisites such as set timezone, it should be skipped entirely if prerequisites are not met and not after strptime fails. Is 'TZ' in os.environ a prerequisite on all system?
msg119717 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-10-27 15:35
Just put the Z at the end, so the skip only happens if all of the others pass? What we really need, of course, is parameterized tests :)
msg119719 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2010-10-27 15:53
On Wed, Oct 27, 2010 at 11:35 AM, R. David Murray <report@bugs.python.org> wrote: .. > Just put the Z at the end, so the skip only happens if all of the others pass? What if time.strptime('%Z', ..) fails because of a bug in python? We don't want that to be reported as a skipped test. BTW, where does 'Local time zone must be set--see zic manual page' error message come from? This does not look like a system message and time.strptime is implemented in python rather than as a wrapper around a libc call.
msg119727 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-10-27 19:04
Well, djc's patch (turned into a skip) would only skip if the specific system error checked for was found. The message is a system message, you'll see it in the 'date' command output if the timezone isn't set. A little googling indicates that it is not Gentoo specific. (Oddly, if I rename my /etc/localtime file date falls back to UTC, but I know I've seen this error when initially installing Gentoo, before I've set /etc/localtime).
msg119762 - (view) Author: Dirkjan Ochtman (djc) * (Python committer) Date: 2010-10-28 07:24
You can easily reproduce (at least on Gentoo) by copying /usr/share/zoneinfo/Factory to /etc/localtime. By checking for this exact message, I don't think the chance is very high that we're hiding a Python bug. I also think that Python tests should test Python; if we see this message, we know we can't reliably test Python, in which case I think a skipped test (hey, we can't test this!) is better than a failed test (implication that Python failed).
msg119790 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-10-28 14:35
Indeed, Factory is part of the standard tz (zoneinfo) database, as can be seen on this web page that makes the database browsable: http://twiki.org/cgi-bin/xtra/tzdatepick.html Whether or not a distribution uses Factory initially is of course a distribution decision, but for our purposes we can consider that message to be a constant provided by upstream that indicates there is no valid timezone to test.
msg182722 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013-02-23 07:38
I tried to reproduce the issue and copied /usr/share/zoneinfo/Factory to /etc/localtime as suggested in . 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;
msg182728 - (view) Author: Dirkjan Ochtman (djc) * (Python committer) Date: 2013-02-23 09:10
I guess option 3 would be the best (in that people get more usable libraries). Option 2 seems okay as well. I don't much like 1 or 4.
msg222809 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-07-11 22:52
Given the extended EOL I'd assume that this is worth doing for 2.7.
History
Date User Action Args
2022-04-11 14:57:07 admin set github: 54422
2016-09-15 23:21:52 belopolsky set status: open -> closedresolution: out of date
2014-07-11 22:53:00 BreamoreBoy set nosy: + BreamoreBoymessages: + versions: - Python 3.2
2013-02-23 09:10:34 djc set messages: +
2013-02-23 07:38:38 ezio.melotti set files: + tz.ccomponents: + Extension Modulesversions: - Python 3.1nosy: + ezio.melottimessages: + stage: needs patch
2010-10-28 14:35:09 r.david.murray set messages: +
2010-10-28 07:24:52 djc set messages: +
2010-10-27 19:04:06 r.david.murray set messages: +
2010-10-27 15:53:09 belopolsky set messages: +
2010-10-27 15:35:20 r.david.murray set messages: +
2010-10-27 15:20:54 belopolsky set messages: +
2010-10-27 14:48:58 r.david.murray set versions: + Python 3.1, Python 2.7, Python 3.2, - Python 2.6nosy: + r.david.murraymessages: + type: behavior
2010-10-27 11:51:24 djc create