/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.211.9 by James Westby
Add some basic pack handling code.
1
# test_pack.py -- Tests for the handling of git packs.
2
# Copyright (C) 2007 James Westby <jw+debian@jameswestby.net>
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.
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
19
import os
20
import unittest
21
22
from git.pack import (PackIndex,
23
                      PackData,
24
                      )
25
26
pack1_sha = 'bc63ddad95e7321ee734ea11a7a62d314e0d7481'
27
28
a_sha = '6f670c0fb53f9463760b7295fbb814e965fb20c8'
29
tree_sha = 'b2a2766a2879c209ab1176e7e778b81ae422eeaa'
30
commit_sha = 'f18faa16531ac570a3fdc8c7ca16682548dafd12'
31
32
class PackTests(unittest.TestCase):
33
  """Base class for testing packs"""
34
35
  datadir = os.path.join(os.path.dirname(__file__), 'data/packs')
36
37
  def get_pack_index(self, sha):
38
    """Returns a PackIndex from the datadir with the given sha"""
39
    return PackIndex(os.path.join(self.datadir, 'pack-%s.idx' % sha))
40
41
  def get_pack_data(self, sha):
42
    """Returns a PackData object from the datadir with the given sha"""
43
    return PackData(os.path.join(self.datadir, 'pack-%s.pack' % sha))
44
45
46
class PackIndexTests(PackTests):
47
  """Class that tests the index of packfiles"""
48
49
  def test_object_index(self):
50
    """Tests that the correct object offset is returned from the index."""
51
    p = self.get_pack_index(pack1_sha)
52
    self.assertEqual(p.object_index(pack1_sha), None)
53
    self.assertEqual(p.object_index(a_sha), 178)
54
    self.assertEqual(p.object_index(tree_sha), 138)
55
    self.assertEqual(p.object_index(commit_sha), 12)
56
57
58
class TestPackData(PackTests):
59
  """Tests getting the data from the packfile."""
60
61
  def test_create_pack(self):
62
    p = self.get_pack_data(pack1_sha)
63
64
  def test_get_object_at(self):
65
    """Tests random access for non-delta objects"""
66
    p = self.get_pack_data(pack1_sha)
67
    idx = self.get_pack_index(pack1_sha)
68
    obj = p.get_object_at(idx.object_index(a_sha))
69
    self.assertEqual(obj._type, 'blob')
70
    self.assertEqual(obj.sha().hexdigest(), a_sha)
71
    obj = p.get_object_at(idx.object_index(tree_sha))
72
    self.assertEqual(obj._type, 'tree')
73
    self.assertEqual(obj.sha().hexdigest(), tree_sha)
74
    obj = p.get_object_at(idx.object_index(commit_sha))
75
    self.assertEqual(obj._type, 'commit')
76
    self.assertEqual(obj.sha().hexdigest(), commit_sha)
77