/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/selftest/teststore.py

  • Committer: Robert Collins
  • Date: 2005-09-28 05:25:54 UTC
  • mfrom: (1185.1.42)
  • mto: (1092.2.18)
  • mto: This revision was merged to the branch mainline in revision 1397.
  • Revision ID: robertc@robertcollins.net-20050928052554-beb985505f77ea6a
update symlink branch to integration

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005 by Canonical Development Ltd
 
2
 
 
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.
 
7
 
 
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.
 
12
 
 
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
 
16
 
 
17
"""Test Store implementation
 
18
"""
 
19
from cStringIO import StringIO
 
20
 
 
21
from bzrlib.store import ImmutableStore
 
22
from bzrlib.selftest import TestCase, TestCaseInTempDir
 
23
from bzrlib.errors import BzrError
 
24
import bzrlib.store
 
25
 
 
26
 
 
27
class TestStore(TestCaseInTempDir):
 
28
 
 
29
    def test_multiple_add(self):
 
30
        """Multiple add with same ID should raise a BzrError"""
 
31
        store = ImmutableStore('.')
 
32
        store.add(StringIO('goodbye'), '123123')
 
33
        self.assertRaises(BzrError, store.add, StringIO('goodbye'), '123123')
 
34
 
 
35
    def test_total_size(self):
 
36
        store = ImmutableStore('.')
 
37
        store.add(StringIO('goodbye'), '123123')
 
38
        store.add(StringIO('goodbye2'), '123123.dsc')
 
39
        # these get gzipped - content should be stable
 
40
        self.assertEqual(store.total_size(), (2, 55))
 
41
        
 
42
 
 
43
class TestMemoryStore(TestCase):
 
44
    
 
45
    def get_store(self):
 
46
        return bzrlib.store.ImmutableMemoryStore()
 
47
    
 
48
    def test_imports(self):
 
49
        from bzrlib.store import ImmutableMemoryStore
 
50
 
 
51
    def test_add_and_retrieve(self):
 
52
        store = self.get_store()
 
53
        store.add(StringIO('hello'), 'aa')
 
54
        self.assertNotEqual(store['aa'], None)
 
55
        self.assertEqual(store['aa'].read(), 'hello')
 
56
        store.add(StringIO('hello world'), 'bb')
 
57
        self.assertNotEqual(store['bb'], None)
 
58
        self.assertEqual(store['bb'].read(), 'hello world')
 
59
 
 
60
    def test_missing_is_absent(self):
 
61
        store = self.get_store()
 
62
        self.failIf('aa' in store)
 
63
 
 
64
    def test_adding_fails_when_present(self):
 
65
        store = self.get_store()
 
66
        store.add(StringIO('hello'), 'aa')
 
67
        self.assertRaises(bzrlib.store.StoreError,
 
68
                          store.add, StringIO('hello'), 'aa')
 
69
 
 
70
    def test_total_size(self):
 
71
        store = self.get_store()
 
72
        store.add(StringIO('goodbye'), '123123')
 
73
        store.add(StringIO('goodbye2'), '123123.dsc')
 
74
        self.assertEqual(store.total_size(), (2, 15))