test_patch.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # test_patch.py -- tests for patch.py
  2. # Copryight (C) 2010 Jelmer Vernooij <jelmer@samba.org>
  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) a later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  17. # MA 02110-1301, USA.
  18. """Tests for patch.py."""
  19. from cStringIO import StringIO
  20. from unittest import TestCase
  21. from dulwich.objects import (
  22. Commit,
  23. Tree,
  24. )
  25. from dulwich.patch import (
  26. write_commit_patch,
  27. )
  28. class WriteCommitPatchTests(TestCase):
  29. def test_simple(self):
  30. f = StringIO()
  31. c = Commit()
  32. c.committer = c.author = "Jelmer <jelmer@samba.org>"
  33. c.commit_time = c.author_time = 1271350201
  34. c.commit_timezone = c.author_timezone = 0
  35. c.message = "This is the first line\nAnd this is the second line.\n"
  36. c.tree = Tree().id
  37. write_commit_patch(f, c, "CONTENTS", (1, 1), version="custom")
  38. f.seek(0)
  39. lines = f.readlines()
  40. self.assertTrue(lines[0].startswith("From 0b0d34d1b5b596c928adc9a727a4b9e03d025298"))
  41. self.assertEquals(lines[1], "From: Jelmer <jelmer@samba.org>\n")
  42. self.assertTrue(lines[2].startswith("Date: "))
  43. self.assertEquals([
  44. "Subject: [PATCH 1/1] This is the first line\n",
  45. "And this is the second line.\n",
  46. "\n",
  47. "\n",
  48. "---\n",
  49. " 0 files changed\n",
  50. "\n",
  51. "CONTENTS-- \n",
  52. "custom\n"], lines[3:])