17
17
"""Test Store implementation
19
from bzrlib.store import ImmutableStore
19
from bzrlib.transport.local import LocalTransport
20
from bzrlib.transport import NoSuchFile
21
from bzrlib.store.compressed_text import CompressedTextStore
20
22
from bzrlib.selftest import TestCaseInTempDir
21
23
from StringIO import StringIO
22
24
from bzrlib.errors import BzrError
24
class TestStore(TestCaseInTempDir):
26
def fill_store(store):
27
store.add(StringIO('hello'), 'a')
28
store.add(StringIO('other'), 'b')
29
store.add(StringIO('something'), 'c')
30
store.add(StringIO('goodbye'), '123123')
32
def check_equals(tester, store, files, values, ignore_missing=False):
33
files = store.get(files, ignore_missing=ignore_missing)
35
for f, v in zip(files, values):
38
tester.assert_(f is None)
40
tester.assertEquals(f.read(), v)
41
tester.assertEquals(count, len(values))
42
# We need to check to make sure there are no more
43
# files to be returned, I'm using a cheezy way
44
# Convert to a list, and there shouldn't be any left
45
tester.assertEquals(len(list(files)), 0)
47
def test_multiple_add(tester, store):
49
tester.assertRaises(BzrError, store.add, StringIO('goodbye'), '123123')
51
def test_get(tester, store):
54
check_equals(tester, store, ['a'], ['hello'])
55
check_equals(tester, store, ['b', 'c'], ['other', 'something'])
57
# Make sure that requesting a non-existing file fails
58
tester.assertRaises(NoSuchFile, check_equals, tester, store,
60
tester.assertRaises(NoSuchFile, check_equals, tester, store,
61
['a', 'd'], ['hello', None])
62
tester.assertRaises(NoSuchFile, check_equals, tester, store,
63
['d', 'a'], [None, 'hello'])
64
tester.assertRaises(NoSuchFile, check_equals, tester, store,
65
['d', 'd', 'd'], [None, None, None])
66
tester.assertRaises(NoSuchFile, check_equals, tester, store,
67
['a', 'd', 'b'], ['hello', None, 'other'])
69
def test_ignore_get(tester, store):
72
files = store.get(['d'], ignore_missing=True)
74
tester.assertEquals(len(files), 1)
75
tester.assert_(files[0] is None)
77
check_equals(tester, store, ['a', 'd'], ['hello', None],
79
check_equals(tester, store, ['d', 'a'], [None, 'hello'],
81
check_equals(tester, store, ['d', 'd'], [None, None],
83
check_equals(tester, store, ['a', 'd', 'b'], ['hello', None, 'other'],
85
check_equals(tester, store, ['a', 'd', 'b'], ['hello', None, 'other'],
87
check_equals(tester, store, ['b', 'd', 'c'], ['other', None, 'something'],
90
def get_compressed_store():
91
t = LocalTransport('.')
92
return CompressedTextStore(t)
94
class TestCompressedTextStore(TestCaseInTempDir):
25
95
def test_multiple_add(self):
26
96
"""Multiple add with same ID should raise a BzrError"""
27
store = ImmutableStore('.')
28
store.add(StringIO('goodbye'), '123123')
29
self.assertRaises(BzrError, store.add, StringIO('goodbye'), '123123')
97
store = get_compressed_store()
98
test_multiple_add(self, store)
101
store = get_compressed_store()
102
test_get(self, store)
104
def test_ignore_get(self):
105
store = get_compressed_store()
106
test_ignore_get(self, store)
110
TestCompressedTextStore,