~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/teststore.py

  • Committer: Martin Pool
  • Date: 2005-08-25 05:58:05 UTC
  • mfrom: (974.1.36)
  • Revision ID: mbp@sourcefrog.net-20050825055805-8c892bc3c2d75131
- merge aaron's merge improvements:

  * When merging, pull in all missing revisions from the source
    branch. 

  * Detect common ancestors by looking at the whole ancestry graph, 
    rather than just mainline history.

  Some changes to reconcile this with parallel updates to the test and
  trace code.

aaron.bentley@utoronto.ca-20050823052551-f3401a8b57d9126f

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 bzrlib.store import ImmutableStore
20
 
import bzrlib.store
21
 
from bzrlib.selftest import TestCase, TestCaseInTempDir
22
 
from StringIO import StringIO
23
 
from bzrlib.errors import BzrError
24
 
 
25
 
class TestStore(TestCaseInTempDir):
26
 
 
27
 
    def test_multiple_add(self):
28
 
        """Multiple add with same ID should raise a BzrError"""
29
 
        store = ImmutableStore('.')
30
 
        store.add(StringIO('goodbye'), '123123')
31
 
        self.assertRaises(BzrError, store.add, StringIO('goodbye'), '123123')
32
 
 
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))