test_objects.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. # test_objects.py -- tests for objects.py
  2. # Copyright (C) 2007 James Westby <jw+debian@jameswestby.net>
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; version 2
  7. # of the License or (at your option) any later version of
  8. # the License.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  18. # MA 02110-1301, USA.
  19. """Tests for git base objects."""
  20. # TODO: Round-trip parse-serialize-parse and serialize-parse-serialize tests.
  21. import datetime
  22. import os
  23. import stat
  24. import unittest
  25. from dulwich.errors import (
  26. ObjectFormatException,
  27. )
  28. from dulwich.objects import (
  29. Blob,
  30. Tree,
  31. Commit,
  32. Tag,
  33. format_timezone,
  34. hex_to_sha,
  35. check_hexsha,
  36. check_identity,
  37. parse_timezone,
  38. parse_tree,
  39. _parse_tree_py,
  40. )
  41. from dulwich.tests import (
  42. TestSkipped,
  43. )
  44. a_sha = '6f670c0fb53f9463760b7295fbb814e965fb20c8'
  45. b_sha = '2969be3e8ee1c0222396a5611407e4769f14e54b'
  46. c_sha = '954a536f7819d40e6f637f849ee187dd10066349'
  47. tree_sha = '70c190eb48fa8bbb50ddc692a17b44cb781af7f6'
  48. tag_sha = '71033db03a03c6a36721efcf1968dd8f8e0cf023'
  49. class BlobReadTests(unittest.TestCase):
  50. """Test decompression of blobs"""
  51. def get_sha_file(self, obj, base, sha):
  52. return obj.from_file(os.path.join(os.path.dirname(__file__),
  53. 'data', base, sha))
  54. def get_blob(self, sha):
  55. """Return the blob named sha from the test data dir"""
  56. return self.get_sha_file(Blob, 'blobs', sha)
  57. def get_tree(self, sha):
  58. return self.get_sha_file(Tree, 'trees', sha)
  59. def get_tag(self, sha):
  60. return self.get_sha_file(Tag, 'tags', sha)
  61. def commit(self, sha):
  62. return self.get_sha_file(Commit, 'commits', sha)
  63. def test_decompress_simple_blob(self):
  64. b = self.get_blob(a_sha)
  65. self.assertEqual(b.data, 'test 1\n')
  66. self.assertEqual(b.sha().hexdigest(), a_sha)
  67. def test_hash(self):
  68. b = self.get_blob(a_sha)
  69. self.assertEqual(hash(b.id), hash(b))
  70. def test_parse_empty_blob_object(self):
  71. sha = 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'
  72. b = self.get_blob(sha)
  73. self.assertEqual(b.data, '')
  74. self.assertEqual(b.id, sha)
  75. self.assertEqual(b.sha().hexdigest(), sha)
  76. def test_create_blob_from_string(self):
  77. string = 'test 2\n'
  78. b = Blob.from_string(string)
  79. self.assertEqual(b.data, string)
  80. self.assertEqual(b.sha().hexdigest(), b_sha)
  81. def test_chunks(self):
  82. string = 'test 5\n'
  83. b = Blob.from_string(string)
  84. self.assertEqual([string], b.chunked)
  85. def test_set_chunks(self):
  86. b = Blob()
  87. b.chunked = ['te', 'st', ' 5\n']
  88. self.assertEqual('test 5\n', b.data)
  89. b.chunked = ['te', 'st', ' 6\n']
  90. self.assertEqual('test 6\n', b.as_raw_string())
  91. def test_parse_legacy_blob(self):
  92. string = 'test 3\n'
  93. b = self.get_blob(c_sha)
  94. self.assertEqual(b.data, string)
  95. self.assertEqual(b.sha().hexdigest(), c_sha)
  96. def test_eq(self):
  97. blob1 = self.get_blob(a_sha)
  98. blob2 = self.get_blob(a_sha)
  99. self.assertEqual(blob1, blob2)
  100. def test_read_tree_from_file(self):
  101. t = self.get_tree(tree_sha)
  102. self.assertEqual(t.entries()[0], (33188, 'a', a_sha))
  103. self.assertEqual(t.entries()[1], (33188, 'b', b_sha))
  104. def test_read_tag_from_file(self):
  105. t = self.get_tag(tag_sha)
  106. self.assertEqual(t.object, (Commit, '51b668fd5bf7061b7d6fa525f88803e6cfadaa51'))
  107. self.assertEqual(t.name,'signed')
  108. self.assertEqual(t.tagger,'Ali Sabil <ali.sabil@gmail.com>')
  109. self.assertEqual(t.tag_time, 1231203091)
  110. self.assertEqual(t.message, 'This is a signed tag\n-----BEGIN PGP SIGNATURE-----\nVersion: GnuPG v1.4.9 (GNU/Linux)\n\niEYEABECAAYFAkliqx8ACgkQqSMmLy9u/kcx5ACfakZ9NnPl02tOyYP6pkBoEkU1\n5EcAn0UFgokaSvS371Ym/4W9iJj6vh3h\n=ql7y\n-----END PGP SIGNATURE-----\n')
  111. def test_read_commit_from_file(self):
  112. sha = '60dacdc733de308bb77bb76ce0fb0f9b44c9769e'
  113. c = self.commit(sha)
  114. self.assertEqual(c.tree, tree_sha)
  115. self.assertEqual(c.parents, ['0d89f20333fbb1d2f3a94da77f4981373d8f4310'])
  116. self.assertEqual(c.author,
  117. 'James Westby <jw+debian@jameswestby.net>')
  118. self.assertEqual(c.committer,
  119. 'James Westby <jw+debian@jameswestby.net>')
  120. self.assertEqual(c.commit_time, 1174759230)
  121. self.assertEqual(c.commit_timezone, 0)
  122. self.assertEqual(c.author_timezone, 0)
  123. self.assertEqual(c.message, 'Test commit\n')
  124. def test_read_commit_no_parents(self):
  125. sha = '0d89f20333fbb1d2f3a94da77f4981373d8f4310'
  126. c = self.commit(sha)
  127. self.assertEqual(c.tree, '90182552c4a85a45ec2a835cadc3451bebdfe870')
  128. self.assertEqual(c.parents, [])
  129. self.assertEqual(c.author,
  130. 'James Westby <jw+debian@jameswestby.net>')
  131. self.assertEqual(c.committer,
  132. 'James Westby <jw+debian@jameswestby.net>')
  133. self.assertEqual(c.commit_time, 1174758034)
  134. self.assertEqual(c.commit_timezone, 0)
  135. self.assertEqual(c.author_timezone, 0)
  136. self.assertEqual(c.message, 'Test commit\n')
  137. def test_read_commit_two_parents(self):
  138. sha = '5dac377bdded4c9aeb8dff595f0faeebcc8498cc'
  139. c = self.commit(sha)
  140. self.assertEqual(c.tree, 'd80c186a03f423a81b39df39dc87fd269736ca86')
  141. self.assertEqual(c.parents, ['ab64bbdcc51b170d21588e5c5d391ee5c0c96dfd',
  142. '4cffe90e0a41ad3f5190079d7c8f036bde29cbe6'])
  143. self.assertEqual(c.author,
  144. 'James Westby <jw+debian@jameswestby.net>')
  145. self.assertEqual(c.committer,
  146. 'James Westby <jw+debian@jameswestby.net>')
  147. self.assertEqual(c.commit_time, 1174773719)
  148. self.assertEqual(c.commit_timezone, 0)
  149. self.assertEqual(c.author_timezone, 0)
  150. self.assertEqual(c.message, 'Merge ../b\n')
  151. class ShaFileCheckTests(unittest.TestCase):
  152. def assertCheckFails(self, obj, data):
  153. obj.set_raw_string(data)
  154. self.assertRaises(ObjectFormatException, obj.check)
  155. def assertCheckSucceeds(self, obj, data):
  156. obj.set_raw_string(data)
  157. try:
  158. obj.check()
  159. except ObjectFormatException, e:
  160. raise
  161. self.fail(e)
  162. class CommitSerializationTests(unittest.TestCase):
  163. def make_base(self):
  164. c = Commit()
  165. c.tree = 'd80c186a03f423a81b39df39dc87fd269736ca86'
  166. c.parents = ['ab64bbdcc51b170d21588e5c5d391ee5c0c96dfd', '4cffe90e0a41ad3f5190079d7c8f036bde29cbe6']
  167. c.author = 'James Westby <jw+debian@jameswestby.net>'
  168. c.committer = 'James Westby <jw+debian@jameswestby.net>'
  169. c.commit_time = 1174773719
  170. c.author_time = 1174773719
  171. c.commit_timezone = 0
  172. c.author_timezone = 0
  173. c.message = 'Merge ../b\n'
  174. return c
  175. def test_encoding(self):
  176. c = self.make_base()
  177. c.encoding = "iso8859-1"
  178. self.assertTrue("encoding iso8859-1\n" in c.as_raw_string())
  179. def test_short_timestamp(self):
  180. c = self.make_base()
  181. c.commit_time = 30
  182. c1 = Commit()
  183. c1.set_raw_string(c.as_raw_string())
  184. self.assertEquals(30, c1.commit_time)
  185. def test_raw_length(self):
  186. c = self.make_base()
  187. self.assertEquals(len(c.as_raw_string()), c.raw_length())
  188. def test_simple(self):
  189. c = self.make_base()
  190. self.assertEquals(c.id, '5dac377bdded4c9aeb8dff595f0faeebcc8498cc')
  191. self.assertEquals(
  192. 'tree d80c186a03f423a81b39df39dc87fd269736ca86\n'
  193. 'parent ab64bbdcc51b170d21588e5c5d391ee5c0c96dfd\n'
  194. 'parent 4cffe90e0a41ad3f5190079d7c8f036bde29cbe6\n'
  195. 'author James Westby <jw+debian@jameswestby.net> 1174773719 +0000\n'
  196. 'committer James Westby <jw+debian@jameswestby.net> 1174773719 +0000\n'
  197. '\n'
  198. 'Merge ../b\n', c.as_raw_string())
  199. def test_timezone(self):
  200. c = self.make_base()
  201. c.commit_timezone = 5 * 60
  202. self.assertTrue(" +0005\n" in c.as_raw_string())
  203. def test_neg_timezone(self):
  204. c = self.make_base()
  205. c.commit_timezone = -1 * 3600
  206. self.assertTrue(" -0100\n" in c.as_raw_string())
  207. default_committer = 'James Westby <jw+debian@jameswestby.net> 1174773719 +0000'
  208. class CommitParseTests(ShaFileCheckTests):
  209. def make_commit_text(self,
  210. tree='d80c186a03f423a81b39df39dc87fd269736ca86',
  211. parents=['ab64bbdcc51b170d21588e5c5d391ee5c0c96dfd',
  212. '4cffe90e0a41ad3f5190079d7c8f036bde29cbe6'],
  213. author=default_committer,
  214. committer=default_committer,
  215. encoding=None,
  216. message='Merge ../b\n',
  217. extra=None):
  218. lines = []
  219. if tree is not None:
  220. lines.append('tree %s' % tree)
  221. if parents is not None:
  222. lines.extend('parent %s' % p for p in parents)
  223. if author is not None:
  224. lines.append('author %s' % author)
  225. if committer is not None:
  226. lines.append('committer %s' % committer)
  227. if encoding is not None:
  228. lines.append('encoding %s' % encoding)
  229. if extra is not None:
  230. for name, value in sorted(extra.iteritems()):
  231. lines.append('%s %s' % (name, value))
  232. lines.append('')
  233. if message is not None:
  234. lines.append(message)
  235. return '\n'.join(lines)
  236. def test_simple(self):
  237. c = Commit.from_string(self.make_commit_text())
  238. self.assertEquals('Merge ../b\n', c.message)
  239. self.assertEquals('James Westby <jw+debian@jameswestby.net>', c.author)
  240. self.assertEquals('James Westby <jw+debian@jameswestby.net>',
  241. c.committer)
  242. self.assertEquals('d80c186a03f423a81b39df39dc87fd269736ca86', c.tree)
  243. self.assertEquals(['ab64bbdcc51b170d21588e5c5d391ee5c0c96dfd',
  244. '4cffe90e0a41ad3f5190079d7c8f036bde29cbe6'],
  245. c.parents)
  246. expected_time = datetime.datetime(2007, 3, 24, 15, 1, 59)
  247. self.assertEquals(expected_time,
  248. datetime.datetime.fromtimestamp(c.commit_time))
  249. self.assertEquals(0, c.commit_timezone)
  250. self.assertEquals(expected_time,
  251. datetime.datetime.fromtimestamp(c.author_time))
  252. self.assertEquals(0, c.author_timezone)
  253. self.assertEquals(None, c.encoding)
  254. def test_custom(self):
  255. c = Commit.from_string(self.make_commit_text(
  256. extra={'extra-field': 'data'}))
  257. self.assertEquals([('extra-field', 'data')], c.extra)
  258. def test_encoding(self):
  259. c = Commit.from_string(self.make_commit_text(encoding='UTF-8'))
  260. self.assertEquals('UTF-8', c.encoding)
  261. def test_check(self):
  262. self.assertCheckSucceeds(Commit(), self.make_commit_text())
  263. self.assertCheckSucceeds(Commit(), self.make_commit_text(parents=None))
  264. self.assertCheckSucceeds(Commit(),
  265. self.make_commit_text(encoding='UTF-8'))
  266. self.assertCheckFails(Commit(), self.make_commit_text(tree='xxx'))
  267. self.assertCheckFails(Commit(), self.make_commit_text(
  268. parents=[a_sha, 'xxx']))
  269. bad_committer = "some guy without an email address 1174773719 +0000"
  270. self.assertCheckFails(Commit(),
  271. self.make_commit_text(committer=bad_committer))
  272. self.assertCheckFails(Commit(),
  273. self.make_commit_text(author=bad_committer))
  274. self.assertCheckFails(Commit(), self.make_commit_text(author=None))
  275. self.assertCheckFails(Commit(), self.make_commit_text(committer=None))
  276. self.assertCheckFails(Commit(), self.make_commit_text(
  277. author=None, committer=None))
  278. class TreeTests(ShaFileCheckTests):
  279. def test_simple(self):
  280. myhexsha = "d80c186a03f423a81b39df39dc87fd269736ca86"
  281. x = Tree()
  282. x["myname"] = (0100755, myhexsha)
  283. self.assertEquals('100755 myname\0' + hex_to_sha(myhexsha),
  284. x.as_raw_string())
  285. def test_tree_dir_sort(self):
  286. x = Tree()
  287. x["a.c"] = (0100755, "d80c186a03f423a81b39df39dc87fd269736ca86")
  288. x["a"] = (stat.S_IFDIR, "d80c186a03f423a81b39df39dc87fd269736ca86")
  289. x["a/c"] = (stat.S_IFDIR, "d80c186a03f423a81b39df39dc87fd269736ca86")
  290. self.assertEquals(["a.c", "a", "a/c"], [p[0] for p in x.iteritems()])
  291. def _do_test_parse_tree(self, parse_tree):
  292. o = Tree.from_file(os.path.join(os.path.dirname(__file__), 'data',
  293. 'trees', tree_sha))
  294. self.assertEquals([('a', 0100644, a_sha), ('b', 0100644, b_sha)],
  295. list(parse_tree(o.as_raw_string())))
  296. def test_parse_tree(self):
  297. self._do_test_parse_tree(_parse_tree_py)
  298. def test_parse_tree_extension(self):
  299. if parse_tree is _parse_tree_py:
  300. raise TestSkipped('parse_tree extension not found')
  301. self._do_test_parse_tree(parse_tree)
  302. def test_check(self):
  303. t = Tree()
  304. sha = hex_to_sha(a_sha)
  305. # filenames
  306. self.assertCheckSucceeds(t, '100644 .a\0%s' % sha)
  307. self.assertCheckFails(t, '100644 \0%s' % sha)
  308. self.assertCheckFails(t, '100644 .\0%s' % sha)
  309. self.assertCheckFails(t, '100644 a/a\0%s' % sha)
  310. self.assertCheckFails(t, '100644 ..\0%s' % sha)
  311. # modes
  312. self.assertCheckSucceeds(t, '100644 a\0%s' % sha)
  313. self.assertCheckSucceeds(t, '100755 a\0%s' % sha)
  314. self.assertCheckSucceeds(t, '160000 a\0%s' % sha)
  315. # TODO more whitelisted modes
  316. self.assertCheckFails(t, '123456 a\0%s' % sha)
  317. self.assertCheckFails(t, '123abc a\0%s' % sha)
  318. # shas
  319. self.assertCheckFails(t, '100644 a\0%s' % ('x' * 5))
  320. self.assertCheckFails(t, '100644 a\0%s' % ('x' * 18 + '\0'))
  321. self.assertCheckFails(t, '100644 a\0%s\n100644 b\0%s' % ('x' * 21, sha))
  322. # ordering
  323. sha2 = hex_to_sha(b_sha)
  324. self.assertCheckSucceeds(t, '100644 a\0%s\n100644 b\0%s' % (sha, sha))
  325. self.assertCheckSucceeds(t, '100644 a\0%s\n100644 b\0%s' % (sha, sha2))
  326. self.assertCheckFails(t, '100644 a\0%s\n100755 a\0%s' % (sha, sha2))
  327. self.assertCheckFails(t, '100644 b\0%s\n100644 a\0%s' % (sha2, sha))
  328. class TagSerializeTests(unittest.TestCase):
  329. def test_serialize_simple(self):
  330. x = Tag()
  331. x.tagger = "Jelmer Vernooij <jelmer@samba.org>"
  332. x.name = "0.1"
  333. x.message = "Tag 0.1"
  334. x.object = (Blob, "d80c186a03f423a81b39df39dc87fd269736ca86")
  335. x.tag_time = 423423423
  336. x.tag_timezone = 0
  337. self.assertEquals("""object d80c186a03f423a81b39df39dc87fd269736ca86
  338. type blob
  339. tag 0.1
  340. tagger Jelmer Vernooij <jelmer@samba.org> 423423423 +0000
  341. Tag 0.1""", x.as_raw_string())
  342. default_tagger = ('Linus Torvalds <torvalds@woody.linux-foundation.org> '
  343. '1183319674 -0700')
  344. default_message = """Linux 2.6.22-rc7
  345. -----BEGIN PGP SIGNATURE-----
  346. Version: GnuPG v1.4.7 (GNU/Linux)
  347. iD8DBQBGiAaAF3YsRnbiHLsRAitMAKCiLboJkQECM/jpYsY3WPfvUgLXkACgg3ql
  348. OK2XeQOiEeXtT76rV4t2WR4=
  349. =ivrA
  350. -----END PGP SIGNATURE-----
  351. """
  352. class TagParseTests(ShaFileCheckTests):
  353. def make_tag_text(self,
  354. object_sha="a38d6181ff27824c79fc7df825164a212eff6a3f",
  355. object_type_name="commit",
  356. name="v2.6.22-rc7",
  357. tagger=default_tagger,
  358. message=default_message):
  359. lines = []
  360. if object_sha is not None:
  361. lines.append("object %s" % object_sha)
  362. if object_type_name is not None:
  363. lines.append("type %s" % object_type_name)
  364. if name is not None:
  365. lines.append("tag %s" % name)
  366. if tagger is not None:
  367. lines.append("tagger %s" % tagger)
  368. lines.append("")
  369. if message is not None:
  370. lines.append(message)
  371. return "\n".join(lines)
  372. def test_parse(self):
  373. x = Tag()
  374. x.set_raw_string(self.make_tag_text())
  375. self.assertEquals(
  376. "Linus Torvalds <torvalds@woody.linux-foundation.org>", x.tagger)
  377. self.assertEquals("v2.6.22-rc7", x.name)
  378. object_type, object_sha = x.object
  379. self.assertEquals("a38d6181ff27824c79fc7df825164a212eff6a3f",
  380. object_sha)
  381. self.assertEquals(Commit, object_type)
  382. self.assertEquals(datetime.datetime.fromtimestamp(x.tag_time),
  383. datetime.datetime(2007, 7, 1, 12, 54, 34))
  384. self.assertEquals(-25200, x.tag_timezone)
  385. def test_parse_no_tagger(self):
  386. x = Tag()
  387. x.set_raw_string(self.make_tag_text(tagger=None))
  388. self.assertEquals(None, x.tagger)
  389. self.assertEquals("v2.6.22-rc7", x.name)
  390. def test_check(self):
  391. self.assertCheckSucceeds(Tag(), self.make_tag_text())
  392. self.assertCheckFails(Tag(), self.make_tag_text(object_sha=None))
  393. self.assertCheckFails(Tag(), self.make_tag_text(object_type_name=None))
  394. self.assertCheckFails(Tag(), self.make_tag_text(name=None))
  395. self.assertCheckFails(Tag(), self.make_tag_text(name=''))
  396. self.assertCheckFails(Tag(), self.make_tag_text(
  397. object_type_name="foobar"))
  398. self.assertCheckFails(Tag(), self.make_tag_text(
  399. tagger="some guy without an email address 1183319674 -0700"))
  400. self.assertCheckFails(Tag(), self.make_tag_text(
  401. tagger=("Linus Torvalds <torvalds@woody.linux-foundation.org> "
  402. "Sun 7 Jul 2007 12:54:34 +0700")))
  403. self.assertCheckFails(Tag(), self.make_tag_text(object_sha="xxx"))
  404. class CheckTests(unittest.TestCase):
  405. def test_check_hexsha(self):
  406. check_hexsha(a_sha, "failed to check good sha")
  407. self.assertRaises(ObjectFormatException, check_hexsha, '1' * 39,
  408. 'sha too short')
  409. self.assertRaises(ObjectFormatException, check_hexsha, '1' * 41,
  410. 'sha too long')
  411. self.assertRaises(ObjectFormatException, check_hexsha, 'x' * 40,
  412. 'invalid characters')
  413. def test_check_identity(self):
  414. check_identity("Dave Borowitz <dborowitz@google.com>",
  415. "failed to check good identity")
  416. check_identity("<dborowitz@google.com>",
  417. "failed to check good identity")
  418. self.assertRaises(ObjectFormatException, check_identity,
  419. "Dave Borowitz", "no email")
  420. self.assertRaises(ObjectFormatException, check_identity,
  421. "Dave Borowitz <dborowitz", "incomplete email")
  422. self.assertRaises(ObjectFormatException, check_identity,
  423. "dborowitz@google.com>", "incomplete email")
  424. self.assertRaises(ObjectFormatException, check_identity,
  425. "Dave Borowitz <<dborowitz@google.com>", "typo")
  426. self.assertRaises(ObjectFormatException, check_identity,
  427. "Dave Borowitz <dborowitz@google.com>>", "typo")
  428. self.assertRaises(ObjectFormatException, check_identity,
  429. "Dave Borowitz <dborowitz@google.com>xxx",
  430. "trailing characters")
  431. class TimezoneTests(unittest.TestCase):
  432. def test_parse_timezone_utc(self):
  433. self.assertEquals(0, parse_timezone("+0000"))
  434. def test_generate_timezone_utc(self):
  435. self.assertEquals("+0000", format_timezone(0))
  436. def test_parse_timezone_cet(self):
  437. self.assertEquals(60 * 60, parse_timezone("+0100"))
  438. def test_format_timezone_cet(self):
  439. self.assertEquals("+0100", format_timezone(60 * 60))
  440. def test_format_timezone_pdt(self):
  441. self.assertEquals("-0400", format_timezone(-4 * 60 * 60))
  442. def test_parse_timezone_pdt(self):
  443. self.assertEquals(-4 * 60 * 60, parse_timezone("-0400"))
  444. def test_format_timezone_pdt_half(self):
  445. self.assertEquals("-0440", format_timezone(int(((-4 * 60) - 40) * 60)))
  446. def test_parse_timezone_pdt_half(self):
  447. self.assertEquals(((-4 * 60) - 40) * 60, parse_timezone("-0440"))