2
0

test_fastexport.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # test_fastexport.py -- Fast export/import functionality
  2. # Copyright (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) 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. from cStringIO import StringIO
  20. import stat
  21. from unittest import TestCase
  22. from dulwich.fastexport import (
  23. FastExporter,
  24. )
  25. from dulwich.object_store import (
  26. MemoryObjectStore,
  27. )
  28. from dulwich.objects import (
  29. Blob,
  30. Commit,
  31. Tree,
  32. )
  33. class FastExporterTests(TestCase):
  34. def setUp(self):
  35. super(FastExporterTests, self).setUp()
  36. self.store = MemoryObjectStore()
  37. self.stream = StringIO()
  38. self.fastexporter = FastExporter(self.stream, self.store)
  39. def test_export_blob(self):
  40. b = Blob()
  41. b.data = "fooBAR"
  42. self.assertEquals(1, self.fastexporter.export_blob(b))
  43. self.assertEquals('blob\nmark :1\ndata 6\nfooBAR\n',
  44. self.stream.getvalue())
  45. def test_export_commit(self):
  46. b = Blob()
  47. b.data = "FOO"
  48. t = Tree()
  49. t.add(stat.S_IFREG | 0644, "foo", b.id)
  50. c = Commit()
  51. c.committer = c.author = "Jelmer <jelmer@host>"
  52. c.author_time = c.commit_time = 1271345553.47
  53. c.author_timezone = c.commit_timezone = 0
  54. c.message = "msg"
  55. c.tree = t.id
  56. self.store.add_objects([(b, None), (t, None), (c, None)])
  57. self.assertEquals(2,
  58. self.fastexporter.export_commit(c, "refs/heads/master"))
  59. self.assertEquals("""blob
  60. mark :1
  61. data 3
  62. FOO
  63. commit refs/heads/master
  64. mark :2
  65. author Jelmer <jelmer@host> 1271345553.47 +0000
  66. committer Jelmer <jelmer@host> 1271345553.47 +0000
  67. data 3
  68. msg
  69. M 100644 :1 foo
  70. """, self.stream.getvalue())