~bzr-pqm/bzr/bzr.dev

974.1.44 by aaron.bentley at utoronto
Added test of double-add in ImmutableStore
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
"""
1185.1.41 by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid
19
20
from StringIO import StringIO
1185.1.46 by Robert Collins
Aarons branch --basis patch
21
import os
1185.1.41 by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid
22
1092.2.19 by Robert Collins
update with integration
23
from bzrlib.store import copy_all, ImmutableStore, RemoteStore
1092.2.1 by Robert Collins
minor refactors to store, create an ImmutableMemoryStore for testing or other such operations
24
from bzrlib.selftest import TestCase, TestCaseInTempDir
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
25
from bzrlib.errors import BzrError, UnlistableStore
1092.3.4 by Robert Collins
update symlink branch to integration
26
import bzrlib.store
974.1.44 by aaron.bentley at utoronto
Added test of double-add in ImmutableStore
27
1185.1.41 by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid
28
974.1.52 by aaron.bentley at utoronto
Merged mpool's latest changes (~0.0.7)
29
class TestStore(TestCaseInTempDir):
1092.2.1 by Robert Collins
minor refactors to store, create an ImmutableMemoryStore for testing or other such operations
30
974.1.44 by aaron.bentley at utoronto
Added test of double-add in ImmutableStore
31
    def test_multiple_add(self):
32
        """Multiple add with same ID should raise a BzrError"""
33
        store = ImmutableStore('.')
34
        store.add(StringIO('goodbye'), '123123')
35
        self.assertRaises(BzrError, store.add, StringIO('goodbye'), '123123')
36
1092.2.1 by Robert Collins
minor refactors to store, create an ImmutableMemoryStore for testing or other such operations
37
    def test_total_size(self):
38
        store = ImmutableStore('.')
39
        store.add(StringIO('goodbye'), '123123')
40
        store.add(StringIO('goodbye2'), '123123.dsc')
41
        # these get gzipped - content should be stable
42
        self.assertEqual(store.total_size(), (2, 55))
43
        
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
44
    def test_copy_all(self):
45
        """Test copying"""
46
        os.mkdir('a')
47
        store_a = ImmutableStore('a')
48
        store_a.add('foo', '1')
49
        os.mkdir('b')
50
        store_b = ImmutableStore('b')
51
        copy_all(store_a, store_b)
52
        self.assertEqual(store_a['1'].read(), 'foo')
53
        self.assertEqual(store_b['1'].read(), 'foo')
54
        store_c = RemoteStore('http://example.com/')
55
        self.assertRaises(UnlistableStore, copy_all, store_c, store_b)
1092.2.19 by Robert Collins
update with integration
56
1092.2.1 by Robert Collins
minor refactors to store, create an ImmutableMemoryStore for testing or other such operations
57
58
class TestMemoryStore(TestCase):
59
    
60
    def get_store(self):
61
        return bzrlib.store.ImmutableMemoryStore()
62
    
63
    def test_imports(self):
64
        from bzrlib.store import ImmutableMemoryStore
65
66
    def test_add_and_retrieve(self):
67
        store = self.get_store()
68
        store.add(StringIO('hello'), 'aa')
69
        self.assertNotEqual(store['aa'], None)
70
        self.assertEqual(store['aa'].read(), 'hello')
71
        store.add(StringIO('hello world'), 'bb')
72
        self.assertNotEqual(store['bb'], None)
73
        self.assertEqual(store['bb'].read(), 'hello world')
74
75
    def test_missing_is_absent(self):
76
        store = self.get_store()
77
        self.failIf('aa' in store)
78
79
    def test_adding_fails_when_present(self):
80
        store = self.get_store()
81
        store.add(StringIO('hello'), 'aa')
82
        self.assertRaises(bzrlib.store.StoreError,
83
                          store.add, StringIO('hello'), 'aa')
84
85
    def test_total_size(self):
86
        store = self.get_store()
87
        store.add(StringIO('goodbye'), '123123')
88
        store.add(StringIO('goodbye2'), '123123.dsc')
89
        self.assertEqual(store.total_size(), (2, 15))