1
# Copyright (C) 2005 by Canonical Development Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Test Store implementation
19
from bzrlib.transport.local import LocalTransport
20
from bzrlib.transport import NoSuchFile
21
from bzrlib.store.compressed_text import CompressedTextStore
22
from bzrlib.selftest import TestCaseInTempDir
23
from StringIO import StringIO
24
from bzrlib.errors import BzrError
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):
95
def test_multiple_add(self):
96
"""Multiple add with same ID should raise a BzrError"""
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,