17
17
"""Test Store implementation
19
19
from bzrlib.store import ImmutableStore
20
from bzrlib.selftest import TestCaseInTempDir
21
from bzrlib.selftest import TestCase, TestCaseInTempDir
21
22
from StringIO import StringIO
22
23
from bzrlib.errors import BzrError
24
25
class TestStore(TestCaseInTempDir):
25
27
def test_multiple_add(self):
26
28
"""Multiple add with same ID should raise a BzrError"""
27
29
store = ImmutableStore('.')
28
30
store.add(StringIO('goodbye'), '123123')
29
31
self.assertRaises(BzrError, store.add, StringIO('goodbye'), '123123')
33
def test_total_size(self):
34
store = ImmutableStore('.')
35
store.add(StringIO('goodbye'), '123123')
36
store.add(StringIO('goodbye2'), '123123.dsc')
37
# these get gzipped - content should be stable
38
self.assertEqual(store.total_size(), (2, 55))
41
class TestMemoryStore(TestCase):
44
return bzrlib.store.ImmutableMemoryStore()
46
def test_imports(self):
47
from bzrlib.store import ImmutableMemoryStore
49
def test_add_and_retrieve(self):
50
store = self.get_store()
51
store.add(StringIO('hello'), 'aa')
52
self.assertNotEqual(store['aa'], None)
53
self.assertEqual(store['aa'].read(), 'hello')
54
store.add(StringIO('hello world'), 'bb')
55
self.assertNotEqual(store['bb'], None)
56
self.assertEqual(store['bb'].read(), 'hello world')
58
def test_missing_is_absent(self):
59
store = self.get_store()
60
self.failIf('aa' in store)
62
def test_adding_fails_when_present(self):
63
store = self.get_store()
64
store.add(StringIO('hello'), 'aa')
65
self.assertRaises(bzrlib.store.StoreError,
66
store.add, StringIO('hello'), 'aa')
68
def test_total_size(self):
69
store = self.get_store()
70
store.add(StringIO('goodbye'), '123123')
71
store.add(StringIO('goodbye2'), '123123.dsc')
72
self.assertEqual(store.total_size(), (2, 15))