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