From: Dave Borowitz Date: Fri, 9 Apr 2010 22:39:12 +0000 (+0200) Subject: Use datetime.utcfromtimestamp() in tests. X-Git-Tag: dulwich-0.6.0~50 X-Git-Url: http://git.samba.org/samba.git/?p=jelmer%2Fdulwich-libgit2.git;a=commitdiff_plain;h=c7c54e8b4386c016e09d186006a40c9cc9c6335a Use datetime.utcfromtimestamp() in tests. datetime.fromtimestamp() has the confusing behavior of treating the timestamp as a UTC time and then converting to local time, but not setting the tzinfo member. As a result, the function returns different values depending on the local timezone, which makes it hard to write a test that passes everywhere. The output of datetime.utcfromtimestamp() is stable across all timezones, which is all we really need for tests. (Returning sensible datetime objects from the Commit/Tag API would require substantially more work, but that is not fixed in this change.) Tested in both US-Pacific and US-Eastern. --- diff --git a/dulwich/tests/test_objects.py b/dulwich/tests/test_objects.py index 37f8fb2..a209a7d 100644 --- a/dulwich/tests/test_objects.py +++ b/dulwich/tests/test_objects.py @@ -288,12 +288,12 @@ class CommitParseTests(ShaFileCheckTests): self.assertEquals(['ab64bbdcc51b170d21588e5c5d391ee5c0c96dfd', '4cffe90e0a41ad3f5190079d7c8f036bde29cbe6'], c.parents) - expected_time = datetime.datetime(2007, 3, 24, 23, 1, 59).replace(tzinfo=None) + expected_time = datetime.datetime(2007, 3, 24, 22, 1, 59) self.assertEquals(expected_time, - datetime.datetime.fromtimestamp(c.commit_time)) + datetime.datetime.utcfromtimestamp(c.commit_time)) self.assertEquals(0, c.commit_timezone) self.assertEquals(expected_time, - datetime.datetime.fromtimestamp(c.author_time)) + datetime.datetime.utcfromtimestamp(c.author_time)) self.assertEquals(0, c.author_timezone) self.assertEquals(None, c.encoding) @@ -455,8 +455,8 @@ class TagParseTests(ShaFileCheckTests): self.assertEquals("a38d6181ff27824c79fc7df825164a212eff6a3f", object_sha) self.assertEquals(Commit, object_type) - self.assertEquals(datetime.datetime.fromtimestamp(x.tag_time), - datetime.datetime(2007, 7, 1, 21, 54, 34, 0).replace(tzinfo=None)) + self.assertEquals(datetime.datetime.utcfromtimestamp(x.tag_time), + datetime.datetime(2007, 7, 1, 19, 54, 34)) self.assertEquals(-25200, x.tag_timezone) def test_parse_no_tagger(self):