Merge upstream
[jelmer/dulwich-libgit2.git] / dulwich / tests / test_index.py
1 # test_index.py -- Tests for the git index cache
2 # Copyright (C) 2008 Jelmer Vernooij <jelmer@samba.org>
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 # or (at your option) any later version 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 from dulwich.index import Index, write_index
20 import os
21 from unittest import TestCase
22
23 class IndexTestCase(TestCase):
24
25     datadir = os.path.join(os.path.dirname(__file__), 'data/indexes')
26
27     def get_simple_index(self, name):
28         return Index(os.path.join(self.datadir, name))
29
30
31 class SimpleIndexTestcase(IndexTestCase):
32
33     def test_len(self):
34         self.assertEquals(1, len(self.get_simple_index("index")))
35
36     def test_iter(self):
37         self.assertEquals([
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)
39             ], 
40                 list(self.get_simple_index("index")))
41
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)
44             , 
45                 self.get_simple_index("index")["bla"])
46
47
48 class SimpleIndexWriterTestCase(IndexTestCase):
49
50     def test_simple_write(self):
51         x = open('test-simple-write-index', 'w+')
52         try:
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)])
54         finally:
55             x.close()
56
57