1 # test_object_store.py -- tests for object_store.py
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 """Tests for the object store interface."""
23 from unittest import TestCase
25 from dulwich.objects import (
28 from dulwich.object_store import (
37 testobject.data = "yummy data"
40 class SpecificDiskObjectStoreTests(TestCase):
42 def test_pack_dir(self):
43 o = DiskObjectStore("foo")
44 self.assertEquals(os.path.join("foo", "pack"), o.pack_dir)
46 def test_empty_packs(self):
47 o = DiskObjectStore("foo")
48 self.assertEquals([], o.packs)
52 class ObjectStoreTests(object):
55 self.assertEquals([], list(self.store))
57 def test_get_nonexistant(self):
58 self.assertRaises(KeyError, self.store.__getitem__, "a" * 40)
60 def test_contains_nonexistant(self):
61 self.assertFalse(self.store.__contains__("a" * 40))
63 def test_add_objects_empty(self):
64 self.store.add_objects([])
66 def test_add_commit(self):
67 # TODO: Argh, no way to construct Git commit objects without
68 # access to a serialized form.
69 self.store.add_objects([])
71 def test_add_object(self):
72 self.store.add_object(testobject)
73 self.assertEquals(set([testobject.id]), set(self.store))
74 self.assertTrue(self.store.__contains__(testobject.id))
75 r = self.store[testobject.id]
76 self.assertEquals(r, testobject)
78 def test_add_objects(self):
79 data = [(testobject, "mypath")]
80 self.store.add_objects(data)
81 self.assertEquals(set([testobject.id]), set(self.store))
82 self.assertTrue(self.store.__contains__(testobject.id))
83 r = self.store[testobject.id]
84 self.assertEquals(r, testobject)
87 class MemoryObjectStoreTests(ObjectStoreTests,TestCase):
91 self.store = MemoryObjectStore()
94 class DiskObjectStoreTests(ObjectStoreTests,TestCase):
98 if os.path.exists("foo"):
100 os.makedirs(os.path.join("foo", "pack"))
101 self.store = DiskObjectStore("foo")