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,
19 from dulwich.index import Index, write_index
21 from unittest import TestCase
23 class IndexTestCase(TestCase):
25 datadir = os.path.join(os.path.dirname(__file__), 'data/indexes')
27 def get_simple_index(self, name):
28 return Index(os.path.join(self.datadir, name))
31 class SimpleIndexTestcase(IndexTestCase):
34 self.assertEquals(1, len(self.get_simple_index("index")))
38 ('bla', (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)
40 list(self.get_simple_index("index")))
42 def test_getitem(self):
43 self.assertEquals( ('bla', (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)
45 self.get_simple_index("index")["bla"])
48 class SimpleIndexWriterTestCase(IndexTestCase):
50 def test_simple_write(self):
51 x = open('test-simple-write-index', 'w+')
53 write_index(x, [('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)])