Possible bug in to_datetime() or incorrect unit tests?

12 views
Skip to first unread message

Willmer, Alex (PTS)

unread,
Mar 26, 2014, 12:03:29 PM3/26/14
to trac...@googlegroups.com

I’m not sure what to make of this, whether it’s a bug, fragile tests, and expected failure, or something else?

 

Three unit tests fail in latest trunk (r12624 on Ubuntu 13.10/Python 2.7.5, set to the UK timezone. It appears that trac.util.to_datetime() returns a datetime object that is 1 hour ahead of that returned by datetime.fromtimestamp() when a timestamp is provided.

 

I should mention that in January 1970 UK wall clock time was 1 hour ahead of UTC. This was changed in October 1971, since then the UK has been on GMT (UTC+0) during winter months.

 

Regards, Alex

 

(venv)willmerae@ubuntu:~/src/trac$ PYTHONPATH=. python trac/util/tests/datefmt.py

................F.FF...................................................................................

======================================================================

FAIL: test_to_datetime (__main__.DateFormatTestCase)

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

Traceback (most recent call last):

  File "trac/util/tests/datefmt.py", line 716, in test_to_datetime

    self.assertEqual(datefmt.to_datetime(23), expected)

AssertionError: datetime.datetime(1970, 1, 1, 2, 0, 23, tzinfo=<LocalTimezone "GMT" 0:00:00>) != datetime.datetime(1970, 1, 1, 1, 0, 23, tzinfo=<LocalTimezone "GMT" 0:00:00>)

 

======================================================================

FAIL: test_to_datetime_microsecond_negative_timestamps (__main__.DateFormatTestCase)

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

Traceback (most recent call last):

  File "trac/util/tests/datefmt.py", line 734, in test_to_datetime_microsecond_negative_timestamps

    self.assertEqual(datefmt.to_datetime(-2345678912), expected)

AssertionError: datetime.datetime(1970, 1, 1, 1, 20, 54, 321088, tzinfo=<LocalTimezone "GMT" 0:00:00>) != datetime.datetime(1970, 1, 1, 0, 20, 54, 321088, tzinfo=<LocalTimezone "GMT" 0:00:00>)

 

======================================================================

FAIL: test_to_datetime_microsecond_timestamps (__main__.DateFormatTestCase)

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

Traceback (most recent call last):

  File "trac/util/tests/datefmt.py", line 723, in test_to_datetime_microsecond_timestamps

    self.assertEqual(datefmt.to_datetime(2345678912), expected)

AssertionError: datetime.datetime(1970, 1, 1, 2, 39, 5, 678912, tzinfo=<LocalTimezone "GMT" 0:00:00>) != datetime.datetime(1970, 1, 1, 1, 39, 5, 678912, tzinfo=<LocalTimezone "GMT" 0:00:00>)

 

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

Ran 103 tests in 0.355s

 

FAILED (failures=3)

 

(venv)willmerae@ubuntu:~/src/trac$ lsb_release --all

No LSB modules are available.

Distributor ID:    Ubuntu

Description:        Ubuntu 13.10

Release:               13.10

Codename:        saucy

(venv)willmerae@ubuntu:~/src/trac$ uname -a

Linux ubuntu 3.11.0-17-generic #31-Ubuntu SMP Mon Feb 3 21:52:43 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

(venv)willmerae@ubuntu:~/src/trac$ python --version

Python 2.7.5+

(venv)willmerae@ubuntu:~/src/trac$ python -c 'import pytz; print pytz.__version__'

2014.2

--

Alex Willmer | #define Developer

Application Services | CGI

2 Trinity Park, Birmingham, B37 7ES, UK

M: +44 7557 752744

al.wi...@cgi.com | cgi-group.co.uk

CGI IT UK Limited. A CGI Group Inc. Company

Registered Office: 250 Brook Drive, Green Park, Reading RG2 6UA, United Kingdom. Registered in England & Wales - Number 947968

CONFIDENTIALITY NOTICE: Proprietary/Confidential Information belonging to CGI Group Inc. and its affiliates may be contained in this message. If you are not a recipient indicated or intended in this message (or responsible for delivery of this message to such person), or you think for any reason that this message may have been addressed to you in error, you may not use or copy or deliver this message to anyone else. In such case, you should destroy this message and are asked to notify the sender by reply e-mail.

 

Jun Omae

unread,
Mar 26, 2014, 10:13:09 PM3/26/14
to trac...@googlegroups.com
Hi,

On Thu, Mar 27, 2014 at 1:03 AM, Willmer, Alex (PTS) <al.wi...@cgi.com> wrote:
> I’m not sure what to make of this, whether it’s a bug, fragile tests, and
> expected failure, or something else?
>
> Three unit tests fail in latest trunk (r12624 on Ubuntu 13.10/Python 2.7.5,
> set to the UK timezone. It appears that trac.util.to_datetime() returns a
> datetime object that is 1 hour ahead of that returned by
> datetime.fromtimestamp() when a timestamp is provided.
>
> I should mention that in January 1970 UK wall clock time was 1 hour ahead of
> UTC. This was changed in October 1971, since then the UK has been on GMT
> (UTC+0) during winter months.

Thanks for the reporting.

Reproduced with Trac 0.12-stable branch. It seems to be a defect.
Would you please create a new ticket for the issue at
http://trac.edgewall.org/newticket?

$ git status -sb
## 0.12-stable
$ TZ=Europe/London ~/venv/py24/bin/python setup.py test -s
trac.util.tests.datefmt.suite
...
FAILED (failures=3)
$ TZ=GMT ~/venv/py24/bin/python setup.py test -s trac.util.tests.datefmt.suite
...
OK
$ TZ=Europe/Berlin ~/venv/py24/bin/python setup.py test -s
trac.util.tests.datefmt.suite
...
OK

--
Jun Omae <jun...@gmail.com> (大前 潤)
Reply all
Reply to author
Forward
0 new messages