~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/teststore.py

fixme note for bzr status

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Test Store implementation
18
18
"""
19
 
from bzrlib.transport.local import LocalTransport
20
 
from bzrlib.transport import NoSuchFile
21
 
from bzrlib.store.compressed_text import CompressedTextStore
 
19
from bzrlib.store import ImmutableStore
22
20
from bzrlib.selftest import TestCaseInTempDir
23
21
from StringIO import StringIO
24
22
from bzrlib.errors import BzrError
25
23
 
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')
31
 
 
32
 
def check_equals(tester, store, files, values, ignore_missing=False):
33
 
    files = store.get(files, ignore_missing=ignore_missing)
34
 
    count = 0
35
 
    for f, v in zip(files, values):
36
 
        count += 1
37
 
        if v is None:
38
 
            tester.assert_(f is None)
39
 
        else:
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)
46
 
 
47
 
def test_multiple_add(tester, store):
48
 
    fill_store(store)
49
 
    tester.assertRaises(BzrError, store.add, StringIO('goodbye'), '123123')
50
 
 
51
 
def test_get(tester, store):
52
 
    fill_store(store)
53
 
 
54
 
    check_equals(tester, store, ['a'], ['hello'])
55
 
    check_equals(tester, store, ['b', 'c'], ['other', 'something'])
56
 
 
57
 
    # Make sure that requesting a non-existing file fails
58
 
    tester.assertRaises(NoSuchFile, check_equals, tester, store,
59
 
            ['d'], [None])
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'])
68
 
 
69
 
def test_ignore_get(tester, store):
70
 
    fill_store(store)
71
 
 
72
 
    files = store.get(['d'], ignore_missing=True)
73
 
    files = list(files)
74
 
    tester.assertEquals(len(files), 1)
75
 
    tester.assert_(files[0] is None)
76
 
 
77
 
    check_equals(tester, store, ['a', 'd'], ['hello', None],
78
 
            ignore_missing=True)
79
 
    check_equals(tester, store, ['d', 'a'], [None, 'hello'],
80
 
            ignore_missing=True)
81
 
    check_equals(tester, store, ['d', 'd'], [None, None],
82
 
            ignore_missing=True)
83
 
    check_equals(tester, store, ['a', 'd', 'b'], ['hello', None, 'other'],
84
 
            ignore_missing=True)
85
 
    check_equals(tester, store, ['a', 'd', 'b'], ['hello', None, 'other'],
86
 
            ignore_missing=True)
87
 
    check_equals(tester, store, ['b', 'd', 'c'], ['other', None, 'something'],
88
 
            ignore_missing=True)
89
 
 
90
 
def get_compressed_store():
91
 
    t = LocalTransport('.')
92
 
    return CompressedTextStore(t)
93
 
 
94
 
class TestCompressedTextStore(TestCaseInTempDir):
 
24
class TestStore(TestCaseInTempDir):
95
25
    def test_multiple_add(self):
96
26
        """Multiple add with same ID should raise a BzrError"""
97
 
        store = get_compressed_store()
98
 
        test_multiple_add(self, store)
99
 
 
100
 
    def test_get(self):
101
 
        store = get_compressed_store()
102
 
        test_get(self, store)
103
 
 
104
 
    def test_ignore_get(self):
105
 
        store = get_compressed_store()
106
 
        test_ignore_get(self, store)
107
 
 
 
27
        store = ImmutableStore('.')
 
28
        store.add(StringIO('goodbye'), '123123')
 
29
        self.assertRaises(BzrError, store.add, StringIO('goodbye'), '123123')
108
30
 
109
31
TEST_CLASSES = [
110
 
    TestCompressedTextStore,
 
32
    TestStore,
111
33
    ]