~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/teststore.py

  • Committer: Robert Collins
  • Date: 2005-09-06 15:19:44 UTC
  • mto: (1092.3.1)
  • mto: This revision was merged to the branch mainline in revision 1397.
  • Revision ID: robertc@robertcollins.net-20050906151944-04320f095a2abc31
minor refactors to store, create an ImmutableMemoryStore for testing or other such operations

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Test Store implementation
18
18
"""
19
19
from bzrlib.store import ImmutableStore
20
 
from bzrlib.selftest import TestCaseInTempDir
 
20
import bzrlib.store
 
21
from bzrlib.selftest import TestCase, TestCaseInTempDir
21
22
from StringIO import StringIO
22
23
from bzrlib.errors import BzrError
23
24
 
24
25
class TestStore(TestCaseInTempDir):
 
26
 
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')
30
32
 
31
 
TEST_CLASSES = [
32
 
    TestStore,
33
 
    ]
 
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))
 
39
        
 
40
 
 
41
class TestMemoryStore(TestCase):
 
42
    
 
43
    def get_store(self):
 
44
        return bzrlib.store.ImmutableMemoryStore()
 
45
    
 
46
    def test_imports(self):
 
47
        from bzrlib.store import ImmutableMemoryStore
 
48
 
 
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')
 
57
 
 
58
    def test_missing_is_absent(self):
 
59
        store = self.get_store()
 
60
        self.failIf('aa' in store)
 
61
 
 
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')
 
67
 
 
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))