Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Add tests. Fixes Issue #65 #72

Merged
merged 3 commits into from
May 28, 2014
Merged

Add tests. Fixes Issue #65 #72

merged 3 commits into from
May 28, 2014

Conversation

Callek
Copy link
Contributor

@Callek Callek commented May 27, 2014

No description provided.

@Callek
Copy link
Contributor Author

Callek commented May 27, 2014

(ooo whops, travis failed since this is dependant on PR 55)

@djmitche
Copy link
Contributor

Even with #55 applied, I get

======================================================================
FAIL: relengapi.tests.test_db.test_UTCDateTime_converts_standard
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/dustin/code/relengapi/t/relengapi/sandbox/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/dustin/code/relengapi/t/relengapi/base/relengapi/testing.py", line 90, in __call__
    wrapped(**kwargs)
  File "/home/dustin/code/relengapi/t/relengapi/base/relengapi/tests/test_db.py", line 96, in test_UTCDateTime_converts_standard
    eq_(standard.strftime('%Y-%m-%d %H:%M:%S %Z%z'), '2011-06-27 02:00:00 PST-0800')
AssertionError: '2011-06-27 02:00:00 LMT-0753' != '2011-06-27 02:00:00 PST-0800'
-------------------- >> begin captured logging << --------------------
relengapi.blueprints.docs: WARNING: docs have not been built
--------------------- >> end captured logging << ---------------------

@Callek
Copy link
Contributor Author

Callek commented May 28, 2014

@dustin --- so:

any idea why datetime.datetime(2011, 6, 27, 2, 0, 0, tzinfo=pytz.timezone("US/Pacific")).strftime('%Y-%m-%d %H:%M:%S %Z%z') returns LMT-0753 for you?

e.g. what ver of pytz do you have? since I'm not getting same behavior

That issue sounds like: https://bugs.launchpad.net/pytz/+bug/310606 (which I found from searching ala: http://code.davidjanes.com/blog/2008/12/22/pytz-utcoffset/

@djmitche
Copy link
Contributor

(sandbox)dustin@euclid ~/code/relengapi/t/relengapi [master] $ python
Python 2.7.6 (default, May  5 2014, 17:49:58) 
[GCC 4.7.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pytz
>>> import datetime
>>> datetime.datetime(2011, 6, 27, 2, 0, 0, tzinfo=pytz.timezone("US/Pacific")).strftime('%Y-%m-%d %H:%M:%S %Z%z')
'2011-06-27 02:00:00 LMT-0753'
>>> print pytz.__version__
2014.3
>>> pytz.timezone("US/Pacific")
<DstTzInfo 'US/Pacific' LMT-1 day, 16:07:00 STD>

Indeed, it does sound like the error you've identified.

(sandbox)dustin@euclid ~/code/relengapi/t/relengapi [master] $ pip install -U pytz
Requirement already up-to-date: pytz in ./sandbox/lib/python2.7/site-packages
Cleaning up...

so, that's the latest, and certainly after something released in 2010.

@djmitche
Copy link
Contributor

try rebasing onto master now that #55 is merged, and let's see what happens in travis..

@djmitche
Copy link
Contributor

I thought maybe this would be due to a different zoneinfo installed on my (Gentoo) system. But from an strace, it looks like pytz ships its own zoneinfo:

(sandbox)dustin@euclid ~/code/relengapi/t/relengapi [master] $ strace -eopen python -c 'import pytz; print `pytz.timezone("US/Pacific")`'
...
open("/home/dustin/code/relengapi/t/relengapi/sandbox/lib/python2.7/site-packages/pytz/zoneinfo/US/Pacific", O_RDONLY) = 3
<DstTzInfo 'US/Pacific' LMT-1 day, 16:07:00 STD>
+++ exited with 0 +++

Adding a print to the pytz function that loads that data, I see

US/Pacific [(-28378, False, 'LMT'), (-25200, True, 'PDT'), (-28800, False, 'PST'), (-25200, True, 'PWT'), (-25200, True, 'PPT')]

so, indeed, it looks like it's selecting the first one of those. The code basically builds a table of transitions from one offset to another, and the LMT offset spans from 1901 to 1918.

@Callek
Copy link
Contributor Author

Callek commented May 28, 2014

Looks like this is a regression in pytz. I'm loathe to require an old pytz though, what-do-you-say here?

(relengapi)[jwood@cruncher.srv.releng.scl3 base]$ python
Python 2.7.3 (default, Apr 10 2013, 09:39:41)
[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pytz
>>> import datetime
>>> datetime.datetime(2011, 6, 27, 2, 0, 0, tzinfo=pytz.timezone("US/Pacific")).strftime('%Y-%m-%d %H:%M:%S %Z%z')
'2011-06-27 02:00:00 PST-0800'
>>> print pytz.__version__
2014.1
>>> pytz.timezone("US/Pacific")
<DstTzInfo 'US/Pacific' PST-1 day, 16:00:00 STD>
>>>
(relengapi)[jwood@cruncher.srv.releng.scl3 base]$ pip install -U pytz
....
(relengapi)[jwood@cruncher.srv.releng.scl3 base]$ python
Python 2.7.3 (default, Apr 10 2013, 09:39:41)
[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> pytz.timezone("US/Pacific")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'pytz' is not defined
>>> import pytz
>>> pytz.timezone("US/Pacific")
<DstTzInfo 'US/Pacific' LMT-1 day, 16:07:00 STD>
>>> pytz.__version__
'2014.3'

@djmitche
Copy link
Contributor

If it's broken, we shouldn't use it. Can you update the upstream ticket to indicate that this is (re-?)broken in 2014.3, and just require pytz==2014.1 in relengapi?

If you add a comment on that requirement, and indicate that relengapi's tests will fail for broken versions of pytz, then someone in the future will feel comfortable upgrading pytz if the tests pass. Yay test!

@petemoore
Copy link
Member

Tests rule :D

@Callek
Copy link
Contributor Author

Callek commented May 28, 2014

Filed: https://bugs.launchpad.net/pytz/+bug/1324158 for the pytz issue

now = datetime.datetime.now().replace(tzinfo=pytz.timezone("US/Pacific"))
session.add(DevTable(date=now))
session.commit()
instance = session.query(DevTable).all()[0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instance = session.query(DevTable).one() might be nicer here

@petemoore
Copy link
Member

Don't forget Dustin's comment: "and indicate that relengapi's tests will fail for broken versions of pytz" - I think this part is still missing. At the moment people might not realise we have a test for it.

@moz-v2v-gh moz-v2v-gh merged commit f6a5db0 into mozilla:master May 28, 2014
moz-v2v-gh pushed a commit that referenced this pull request May 28, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants