Merge lp:~canonical-platform-qa/autopilot/fix_vuild_for_x_incl_datetime into lp:autopilot

Proposed by Christopher Lee
Status: Merged
Approved by: Max Brustkern
Approved revision: 575
Merged at revision: 573
Proposed branch: lp:~canonical-platform-qa/autopilot/fix_vuild_for_x_incl_datetime
Merge into: lp:autopilot
Diff against target: 125 lines (+14/-37)
5 files modified
autopilot/application/_launcher.py (+2/-0)
autopilot/introspection/types.py (+7/-30)
autopilot/tests/unit/test_platform.py (+2/-2)
debian/control (+1/-0)
docs/otto.py (+2/-5)
To merge this branch: bzr merge lp:~canonical-platform-qa/autopilot/fix_vuild_for_x_incl_datetime
Reviewer Review Type Date Requested Status
Max Brustkern (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+279844@code.launchpad.net

Commit message

Fix build issues on Xenial. Incl. simplifying DateTime.

Description of the change

Fix build issues on Xenial. Incl. simplifying DateTime.

To post a comment you must log in.
Revision history for this message
Stuart Bishop (stub) wrote :

Looks good to me. There is no need to use the pytz specific localize or normalize methods here.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Max Brustkern (nuclearbob) wrote :

LGTM. I'm glad to see the sphinx fixes aren't super complicated.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'autopilot/application/_launcher.py'
--- autopilot/application/_launcher.py 2015-11-18 21:36:10 +0000
+++ autopilot/application/_launcher.py 2015-12-08 04:20:49 +0000
@@ -22,6 +22,8 @@
22import fixtures22import fixtures
23from gi.repository import GLib23from gi.repository import GLib
24try:24try:
25 from gi import require_version
26 require_version('UbuntuAppLaunch', '2')
25 from gi.repository import UbuntuAppLaunch27 from gi.repository import UbuntuAppLaunch
26except ImportError:28except ImportError:
27 # Note: the renamed package is not in Trusty.29 # Note: the renamed package is not in Trusty.
2830
=== modified file 'autopilot/introspection/types.py'
--- autopilot/introspection/types.py 2014-10-22 20:43:01 +0000
+++ autopilot/introspection/types.py 2015-12-08 04:20:49 +0000
@@ -37,8 +37,9 @@
3737
38"""38"""
3939
40import pytz
40from datetime import datetime, time, timedelta41from datetime import datetime, time, timedelta
41from dateutil.tz import gettz, tzutc42from dateutil.tz import gettz
4243
43import dbus44import dbus
44import logging45import logging
@@ -650,39 +651,15 @@
650 super(DateTime, self).__init__(*args, **kwargs)651 super(DateTime, self).__init__(*args, **kwargs)
651 # Using timedelta in this manner is a workaround so that we can support652 # Using timedelta in this manner is a workaround so that we can support
652 # timestamps larger than the 32bit time_t limit on 32bit hardware.653 # timestamps larger than the 32bit time_t limit on 32bit hardware.
653 # We then apply another workaround where timedelta doesn't apply654 # We then apply the timezone information to this to get the correct
654 # daylight savings, so we need to work out the offsets for the655 # datetime.
655 # localtime manually and apply them to give us the correct local time.
656 #656 #
657 # Note. self[0] is a UTC timestamp657 # Note. self[0] is a UTC timestamp
658 EPOCH = datetime(1970, 1, 1, tzinfo=tzutc())658 utc = pytz.timezone('UTC')
659 EPOCH = datetime(1970, 1, 1, tzinfo=utc)
659 utc_dt = EPOCH + timedelta(seconds=self[0])660 utc_dt = EPOCH + timedelta(seconds=self[0])
660661
661 local_tzinfo = gettz()662 self._cached_dt = utc_dt.astimezone(gettz())
662
663 # Get the localtimes timezone offset (known as standard offset) by
664 # subtracting its dst offset (if any) from its utc offset.
665 # We apply this to the utc datetime object to get datetime object in
666 # localtime.
667 # (We will check (once we have a local datetime) if the time is in dst
668 # and make that adjustment then.)
669 utc_offset = local_tzinfo.utcoffset(utc_dt)
670 dst_offset = local_tzinfo.dst(utc_dt)
671 standard_offset = utc_offset - dst_offset
672
673 # Create a local timezone aware datetime object from the utc_dt
674 # (i.e. attaching a timezone to it) and apply the standard offset to
675 # give us the local time.
676 local_dt = utc_dt.replace(tzinfo=local_tzinfo) + standard_offset
677
678 # If the new local time is firmly in std time then the standard offset
679 # will be 0 (i.e. timedelta(0)).
680 # If the delta isn't 0 then we need to use the timezone information to
681 # apply the dst delta to the local time.
682 if standard_offset != timedelta(0):
683 local_dt = local_dt + local_tzinfo.dst(local_dt)
684
685 self._cached_dt = local_dt
686663
687 @property664 @property
688 def year(self):665 def year(self):
689666
=== modified file 'autopilot/tests/unit/test_platform.py'
--- autopilot/tests/unit/test_platform.py 2014-07-23 03:37:24 +0000
+++ autopilot/tests/unit/test_platform.py 2015-12-08 04:20:49 +0000
@@ -39,7 +39,7 @@
39 @patch('autopilot.platform._PlatformDetector')39 @patch('autopilot.platform._PlatformDetector')
40 def test_model_creates_platform_detector(self, mock_detector):40 def test_model_creates_platform_detector(self, mock_detector):
41 platform.model()41 platform.model()
42 mock_detector.create.assert_called_once()42 mock_detector.create.assert_called_once_with()
4343
44 @patch('autopilot.platform._PlatformDetector._cached_detector')44 @patch('autopilot.platform._PlatformDetector._cached_detector')
45 def test_model_returns_correct_value(self, mock_detector):45 def test_model_returns_correct_value(self, mock_detector):
@@ -49,7 +49,7 @@
49 @patch('autopilot.platform._PlatformDetector')49 @patch('autopilot.platform._PlatformDetector')
50 def test_image_codename_creates_platform_detector(self, mock_detector):50 def test_image_codename_creates_platform_detector(self, mock_detector):
51 platform.image_codename()51 platform.image_codename()
52 mock_detector.create.assert_called_once()52 mock_detector.create.assert_called_once_with()
5353
54 @patch('autopilot.platform._PlatformDetector._cached_detector')54 @patch('autopilot.platform._PlatformDetector._cached_detector')
55 def test_image_codename_returns_correct_value(self, mock_detector):55 def test_image_codename_returns_correct_value(self, mock_detector):
5656
=== modified file 'debian/control'
--- debian/control 2015-07-22 23:29:11 +0000
+++ debian/control 2015-12-08 04:20:49 +0000
@@ -30,6 +30,7 @@
30 python3-subunit,30 python3-subunit,
31 python3-testscenarios,31 python3-testscenarios,
32 python3-testtools,32 python3-testtools,
33 python3-tz,
33 python3-xlib (>=0.14+20091101-1ubuntu3),34 python3-xlib (>=0.14+20091101-1ubuntu3),
34 sphinx-common,35 sphinx-common,
35 texlive-latex-extra,36 texlive-latex-extra,
3637
=== modified file 'docs/otto.py'
--- docs/otto.py 2013-07-25 05:47:36 +0000
+++ docs/otto.py 2015-12-08 04:20:49 +0000
@@ -56,12 +56,9 @@
56 self.content, self.lineno, self.content_offset,56 self.content, self.lineno, self.content_offset,
57 self.block_text, self.state, self.state_machine)57 self.block_text, self.state, self.state_machine)
58 image_container = nodes.container()58 image_container = nodes.container()
59 image_container.children.append(nodes.image(uri='/images/otto-64.png'))59 image_container.append(nodes.image(uri='/images/otto-64.png'))
60 image_container['classes'] = ['otto-image-container']60 image_container['classes'] = ['otto-image-container']
61 outer_container = nodes.container()61 outer_container = nodes.container()
62 outer_container.children.extend(62 outer_container.extend([image_container] + ad)
63 [image_container]
64 + ad
65 )
66 outer_container['classes'] = ['otto-says-container']63 outer_container['classes'] = ['otto-says-container']
67 return [outer_container]64 return [outer_container]

Subscribers

People subscribed via source and target branches