test_pack.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # test_pack.py -- Compatibility tests for git packs.
  2. # Copyright (C) 2010 Google, Inc.
  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. """Compatibility tests for git packs."""
  20. import binascii
  21. import os
  22. import shutil
  23. import tempfile
  24. from dulwich.pack import (
  25. write_pack,
  26. )
  27. from dulwich.tests.test_pack import (
  28. pack1_sha,
  29. PackTests,
  30. )
  31. from dulwich.tests.compat.utils import (
  32. require_git_version,
  33. run_git_or_fail,
  34. )
  35. class TestPack(PackTests):
  36. """Compatibility tests for reading and writing pack files."""
  37. def setUp(self):
  38. require_git_version((1, 5, 0))
  39. PackTests.setUp(self)
  40. self._tempdir = tempfile.mkdtemp()
  41. def tearDown(self):
  42. shutil.rmtree(self._tempdir)
  43. PackTests.tearDown(self)
  44. def test_copy(self):
  45. origpack = self.get_pack(pack1_sha)
  46. self.assertSucceeds(origpack.index.check)
  47. pack_path = os.path.join(self._tempdir, "Elch")
  48. write_pack(pack_path, [(x, "") for x in origpack.iterobjects()],
  49. len(origpack))
  50. output = run_git_or_fail(['verify-pack', '-v', pack_path])
  51. pack_shas = set()
  52. for line in output.splitlines():
  53. sha = line[:40]
  54. try:
  55. binascii.unhexlify(sha)
  56. except TypeError:
  57. continue # non-sha line
  58. pack_shas.add(sha)
  59. orig_shas = set(o.id for o in origpack.iterobjects())
  60. self.assertEquals(orig_shas, pack_shas)