~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/teststore.py

  • Committer: Robert Collins
  • Date: 2005-10-16 01:51:59 UTC
  • mto: This revision was merged to the branch mainline in revision 1459.
  • Revision ID: robertc@lifelesslap.robertcollins.net-20051016015159-580cca34cb41e771
Pull up _check_id and _relpath from Text and CompressedText stores into TransportStore

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
"""Test Store implementation
18
 
"""
 
17
"""Test Store implementations."""
 
18
 
19
19
from cStringIO import StringIO
20
20
import os
21
21
 
 
22
from bzrlib.errors import BzrError, UnlistableStore
22
23
from bzrlib.store import copy_all
23
24
from bzrlib.transport.local import LocalTransport
24
25
from bzrlib.transport import NoSuchFile
25
26
from bzrlib.store.compressed_text import CompressedTextStore
26
27
from bzrlib.store.text import TextStore
27
28
from bzrlib.selftest import TestCase, TestCaseInTempDir
28
 
from bzrlib.errors import BzrError, UnlistableStore
29
 
import bzrlib.store
 
29
import bzrlib.store as store
 
30
import bzrlib.transport as transport
30
31
 
31
32
 
32
33
def fill_store(store):
35
36
    store.add(StringIO('something'), 'c')
36
37
    store.add(StringIO('goodbye'), '123123')
37
38
 
 
39
 
38
40
def check_equals(tester, store, files, values, permit_failure=False):
39
41
    files = store.get(files, permit_failure=permit_failure)
40
42
    count = 0
50
52
    # Convert to a list, and there shouldn't be any left
51
53
    tester.assertEquals(len(list(files)), 0)
52
54
 
 
55
 
53
56
def test_multiple_add(tester, store):
54
57
    fill_store(store)
55
58
    tester.assertRaises(BzrError, store.add, StringIO('goodbye'), '123123')
56
59
 
 
60
 
57
61
def test_get(tester, store):
58
62
    fill_store(store)
59
63
 
72
76
    tester.assertRaises(NoSuchFile, check_equals, tester, store,
73
77
            ['a', 'd', 'b'], ['hello', None, 'other'])
74
78
 
 
79
 
75
80
def test_ignore_get(tester, store):
76
81
    fill_store(store)
77
82
 
141
146
class TestMemoryStore(TestCase):
142
147
    
143
148
    def get_store(self):
144
 
        return bzrlib.store.ImmutableMemoryStore()
 
149
        return store.ImmutableMemoryStore()
145
150
    
146
151
    def test_imports(self):
147
152
        from bzrlib.store import ImmutableMemoryStore
160
165
        self.failIf('aa' in store)
161
166
 
162
167
    def test_adding_fails_when_present(self):
163
 
        store = self.get_store()
164
 
        store.add(StringIO('hello'), 'aa')
165
 
        self.assertRaises(bzrlib.store.StoreError,
166
 
                          store.add, StringIO('hello'), 'aa')
 
168
        my_store = self.get_store()
 
169
        my_store.add(StringIO('hello'), 'aa')
 
170
        self.assertRaises(store.StoreError,
 
171
                          my_store.add, StringIO('hello'), 'aa')
167
172
 
168
173
    def test_total_size(self):
169
174
        store = self.get_store()
206
211
        #       Transport doesn't support listing
207
212
        # store_c = RemoteStore('http://example.com/')
208
213
        # self.assertRaises(UnlistableStore, copy_all, store_c, store_b)
 
214
 
 
215
 
 
216
class MockTransport(transport.Transport):
 
217
    """A fake transport for testing with."""
 
218
 
 
219
    def __init__(self, url=None):
 
220
        if url is None:
 
221
            url = "http://example.com"
 
222
        super(MockTransport, self).__init__(url)
 
223
 
 
224
 
 
225
class TestMockTransport(TestCase):
 
226
 
 
227
    def test_isinstance(self):
 
228
        self.failUnless(isinstance(MockTransport(), transport.Transport))
 
229
 
 
230
 
 
231
class TestTransportStore(TestCase):
 
232
    
 
233
    def test__relpath_invalid(self):
 
234
        my_store = store.TransportStore(MockTransport())
 
235
        self.assertRaises(ValueError, my_store._relpath, '/foo')
 
236
        self.assertRaises(ValueError, my_store._relpath, 'foo/')
 
237