test_fastexport.py 2.5 KB

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