Merge lp:~veebers/autopilot/fix-datetime-tests-1324441 into lp:~autopilot/autopilot/temp-dev

Proposed by Christopher Lee
Status: Merged
Approved by: Christopher Lee
Approved revision: 525
Merged at revision: 523
Proposed branch: lp:~veebers/autopilot/fix-datetime-tests-1324441
Merge into: lp:~autopilot/autopilot/temp-dev
Diff against target: 62 lines (+27/-10)
1 file modified
autopilot/tests/unit/test_types.py (+27/-10)
To merge this branch: bzr merge lp:~veebers/autopilot/fix-datetime-tests-1324441
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Thomi Richards (community) Approve
Max Brustkern (community) Approve
Review via email: mp+222270@code.launchpad.net

Commit message

Patch previously failing DateTime tests to use UTC TZ (due to DateTime change to using local TZ)

Description of the change

Recent changes to the DateTime type meant that some tests were broken as they assumed comparison to the UTC timezone (instead of the local TZ that it now is).

Fixed by patching the affected tests to use UTC timezone. (cleaner than my original fix).

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Max Brustkern (nuclearbob) wrote :

Looks good to me. If I were doing it, I'd use fixtures.EnvironmentVariable instead of using our specific functionality, but as long as we continue supporting that there's no particular reason to prefer it.

review: Approve
522. By Christopher Lee

Update use of patch_environment to use fixtures.EnvironmentVariable

Revision history for this message
Christopher Lee (veebers) wrote :

Ah, thank you for pointing that out. I had missed the move to fixtures.EnvironmentVariable *blush*.
I have updated to use it as you've suggested.

523. By Christopher Lee

Merge dev-trunk w/ conflict fixes.

524. By Christopher Lee

Remove un-needed use of AutopilotTestCase

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
525. By Christopher Lee

Separate out 2 unit tests. Better solution for datetime test fix.

Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

LGTM

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'autopilot/tests/unit/test_types.py'
2--- autopilot/tests/unit/test_types.py 2014-05-30 09:43:51 +0000
3+++ autopilot/tests/unit/test_types.py 2014-06-10 23:30:37 +0000
4@@ -308,13 +308,25 @@
5 def test_datetime_has_properties(self):
6 dt = DateTime(1377209927)
7
8- self.assertThat(dt.timestamp, Equals(1377209927))
9- self.assertThat(dt.year, Equals(2013))
10- self.assertThat(dt.month, Equals(8))
11- self.assertThat(dt.day, Equals(22))
12- self.assertThat(dt.hour, Equals(22))
13- self.assertThat(dt.minute, Equals(18))
14- self.assertThat(dt.second, Equals(47))
15+ self.assertTrue(hasattr(dt, 'timestamp'))
16+ self.assertTrue(hasattr(dt, 'year'))
17+ self.assertTrue(hasattr(dt, 'month'))
18+ self.assertTrue(hasattr(dt, 'day'))
19+ self.assertTrue(hasattr(dt, 'hour'))
20+ self.assertTrue(hasattr(dt, 'minute'))
21+ self.assertTrue(hasattr(dt, 'second'))
22+
23+ def test_datetime_properties_have_correct_values(self):
24+ dt = DateTime(1377209927)
25+ dt_with_tz = datetime.fromtimestamp(1377209927)
26+
27+ self.assertThat(dt.timestamp, Equals(dt_with_tz.timestamp()))
28+ self.assertThat(dt.year, Equals(dt_with_tz.year))
29+ self.assertThat(dt.month, Equals(dt_with_tz.month))
30+ self.assertThat(dt.day, Equals(dt_with_tz.day))
31+ self.assertThat(dt.hour, Equals(dt_with_tz.hour))
32+ self.assertThat(dt.minute, Equals(dt_with_tz.minute))
33+ self.assertThat(dt.second, Equals(dt_with_tz.second))
34
35 def test_equality_with_datetime(self):
36 dt1 = DateTime(1377209927)
37@@ -329,9 +341,10 @@
38 self.assertThat(dt1, Equals(dt2))
39
40 def test_equality_with_datetime_timestamp(self):
41+ # DateTime no longer assumes UTC and uses local TZ.
42 dt1 = DateTime(1377209927)
43- dt2 = datetime.utcfromtimestamp(1377209927)
44- dt3 = datetime.utcfromtimestamp(1377209928)
45+ dt2 = datetime.fromtimestamp(1377209927)
46+ dt3 = datetime.fromtimestamp(1377209928)
47
48 self.assertThat(dt1, Equals(dt2))
49 self.assertThat(dt1, NotEquals(dt3))
50@@ -342,8 +355,12 @@
51 self.assertThat(dt1.datetime, IsInstance(datetime))
52
53 def test_repr(self):
54+ expected = repr_type(
55+ u"DateTime({:%Y-%m-%d %H:%M:%S})".format(
56+ datetime.fromtimestamp(1377209927)
57+ )
58+ )
59 dt = DateTime(1377209927)
60- expected = repr_type('DateTime(2013-08-22 22:18:47)')
61 observed = repr(dt)
62 self.assertEqual(expected, observed)
63

Subscribers

People subscribed via source and target branches