test_archive.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # test_archive.py -- tests for archive
  2. # Copyright (C) 2015 Jelmer Vernooij <jelmer@jelmer.uk>
  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 archive support."""
  19. from io import BytesIO
  20. import sys
  21. import tarfile
  22. from dulwich.archive import tar_stream
  23. from dulwich.object_store import (
  24. MemoryObjectStore,
  25. )
  26. from dulwich.objects import (
  27. Blob,
  28. Tree,
  29. )
  30. from dulwich.tests import (
  31. TestCase,
  32. )
  33. from dulwich.tests.utils import (
  34. build_commit_graph,
  35. )
  36. class ArchiveTests(TestCase):
  37. def test_empty(self):
  38. if sys.version_info[:2] <= (2, 6):
  39. self.skipTest("archive creation known failing on Python2.6")
  40. store = MemoryObjectStore()
  41. c1, c2, c3 = build_commit_graph(store, [[1], [2, 1], [3, 1, 2]])
  42. tree = store[c3.tree]
  43. stream = b''.join(tar_stream(store, tree, 10))
  44. out = BytesIO(stream)
  45. tf = tarfile.TarFile(fileobj=out)
  46. self.addCleanup(tf.close)
  47. self.assertEqual([], tf.getnames())
  48. def test_simple(self):
  49. self.skipTest("known to fail on python2.6 and 3.4; needs debugging")
  50. store = MemoryObjectStore()
  51. b1 = Blob.from_string(b"somedata")
  52. store.add_object(b1)
  53. t1 = Tree()
  54. t1.add(b"somename", 0o100644, b1.id)
  55. store.add_object(t1)
  56. stream = b''.join(tar_stream(store, t1, 10))
  57. out = BytesIO(stream)
  58. tf = tarfile.TarFile(fileobj=out)
  59. self.addCleanup(tf.close)
  60. self.assertEqual(["somename"], tf.getnames())