test_fastexport.py 2.3 KB

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