Merge lp:~james-w/udd/storm-fixes into lp:udd

Proposed by James Westby on 2012-04-04
Status: Merged
Approved by: Jonathan Lange on 2012-04-04
Approved revision: 569
Merged at revision: 568
Proposed branch: lp:~james-w/udd/storm-fixes
Merge into: lp:udd
Diff against target: 93 lines (+48/-2)
4 files modified
selftest.py (+1/-0)
udd/icommon.py (+5/-2)
udd/tests/test_history_database.py (+33/-0)
udd/tests/test_status_database.py (+9/-0)
To merge this branch: bzr merge lp:~james-w/udd/storm-fixes
Reviewer Review Type Date Requested Status
Jonathan Lange (community) 2012-04-04 Approve on 2012-04-04
Review via email: mp+100838@code.launchpad.net

Commit Message

Ensure that storm is returning datetime objects for timestamps.

Description of the Change

Hi,

This adds a couple more storm compatibility fixes related to datetimes.

We have to manually coerce the unicode return type to a datetime for some
reason, and while doing so we have to be careful about dealing with
data inserted by sqlite3 that doesn't have any microseconds.

Thanks,

James

To post a comment you must log in.
Jonathan Lange (jml) wrote :

I like. Thanks for tracking this down.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'selftest.py'
2--- selftest.py 2012-03-23 16:56:38 +0000
3+++ selftest.py 2012-04-04 17:18:33 +0000
4@@ -47,6 +47,7 @@
5 'udd.tests.test_email_failures',
6 'udd.tests.test_graph_failures',
7 'udd.tests.test_helpers',
8+ 'udd.tests.test_history_database',
9 'udd.tests.test_icommon',
10 'udd.tests.test_idb',
11 'udd.tests.test_import_list',
12
13=== modified file 'udd/icommon.py'
14--- udd/icommon.py 2012-03-23 16:56:38 +0000
15+++ udd/icommon.py 2012-04-04 17:18:33 +0000
16@@ -838,7 +838,10 @@
17
18
19 def make_datetime(strified):
20- return datetime.strptime(strified, "%Y-%m-%d %H:%M:%S.%f")
21+ fmt = "%Y-%m-%d %H:%M:%S"
22+ if "." in strified:
23+ fmt += ".%f"
24+ return datetime.strptime(strified, fmt)
25
26
27 class CommitDatabase(object):
28@@ -1151,7 +1154,7 @@
29 with Cursor(self.conn) as c:
30 rows = c.execute("select * from %s"
31 % table)
32- return [(r[0], r[1], r[2]) for r in rows]
33+ return [(make_datetime(r[0]), r[1], r[2]) for r in rows]
34
35 def get_main_counts(self):
36 return self._get_counts(self.MAIN_FAILED_TABLE)
37
38=== added file 'udd/tests/test_history_database.py'
39--- udd/tests/test_history_database.py 1970-01-01 00:00:00 +0000
40+++ udd/tests/test_history_database.py 2012-04-04 17:18:33 +0000
41@@ -0,0 +1,33 @@
42+from datetime import datetime
43+
44+from bzrlib import tests
45+
46+from udd import icommon, idb
47+
48+
49+class TestHistoryDb(tests.TestCase):
50+
51+ def setUp(self):
52+ super(TestHistoryDb, self).setUp()
53+ self.db = icommon.HistoryDatabase(*idb.get_memory_db_connection())
54+
55+
56+class GetMainCountsTests(TestHistoryDb):
57+
58+ def test_returns_queued(self):
59+ self.db.set_main_counts(2, 3)
60+ counts = self.db.get_main_counts()
61+ self.assertEqual(1, len(counts))
62+ self.assertEqual(2, counts[0][1])
63+
64+ def test_returns_failed(self):
65+ self.db.set_main_counts(2, 3)
66+ counts = self.db.get_main_counts()
67+ self.assertEqual(1, len(counts))
68+ self.assertEqual(3, counts[0][2])
69+
70+ def test_returns_datetimes(self):
71+ self.db.set_main_counts(1, 2)
72+ counts = self.db.get_main_counts()
73+ self.assertEqual(1, len(counts))
74+ self.assertIsInstance(counts[0][0], datetime)
75
76=== modified file 'udd/tests/test_status_database.py'
77--- udd/tests/test_status_database.py 2012-03-23 16:56:38 +0000
78+++ udd/tests/test_status_database.py 2012-04-04 17:18:33 +0000
79@@ -99,6 +99,15 @@
80 self.db.add_import_jobs(['foo'], now)
81 self.assertEqual(now, self.db.last_import_time())
82
83+ def test_last_import_time_sqlite(self):
84+ # if the last import time was inserted by sqlite3 then it has a
85+ # different format from the one that storm would insert. Check
86+ # that the migration is handled ok.
87+ now = datetime.datetime.utcnow()
88+ self.db.conn.execute('INSERT into %s values (?)' % self.db.IMPORT_TABLE,
89+ (now.strftime("%Y-%m-%d %H:%M:%S"),))
90+ self.assertEqual(now.replace(microsecond=0), self.db.last_import_time())
91+
92
93 class TestRetry(TestStatusDb):
94

Subscribers

People subscribed via source and target branches