1 # test_index.py -- Tests for the git index cache
2 # Copyright (C) 2008 Jelmer Vernooij <jelmer@samba.org>
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 # or (at your option) any later version of the License.
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.
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,
20 from unittest import TestCase
22 from dulwich.index import (
28 class IndexTestCase(TestCase):
30 datadir = os.path.join(os.path.dirname(__file__), 'data/indexes')
32 def get_simple_index(self, name):
33 return Index(os.path.join(self.datadir, name))
36 class SimpleIndexTestcase(IndexTestCase):
39 self.assertEquals(1, len(self.get_simple_index("index")))
42 self.assertEquals(['bla'], list(self.get_simple_index("index")))
44 def test_getitem(self):
45 self.assertEquals( ((1230680220, 0), (1230680220, 0), 2050, 3761020, 33188, 1000, 1000, 0, '\xe6\x9d\xe2\x9b\xb2\xd1\xd6CK\x8b)\xaewZ\xd8\xc2\xe4\x8cS\x91', 3)
47 self.get_simple_index("index")["bla"])
50 class SimpleIndexWriterTestCase(IndexTestCase):
52 def test_simple_write(self):
53 entries = [('barbla', (1230680220, 0), (1230680220, 0), 2050, 3761020, 33188, 1000, 1000, 0, '\xe6\x9d\xe2\x9b\xb2\xd1\xd6CK\x8b)\xaewZ\xd8\xc2\xe4\x8cS\x91', 3)]
54 x = open('test-simple-write-index', 'w+')
56 write_index(x, entries)
59 x = open('test-simple-write-index', 'r')
61 self.assertEquals(entries, list(read_index(x)))