test_pack.py 2.2 KB

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