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 |
"""
|
|
1092.3.4
by Robert Collins
update symlink branch to integration |
19 |
from cStringIO import StringIO |
1185.1.41
by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid |
20 |
|
974.1.44
by aaron.bentley at utoronto
Added test of double-add in ImmutableStore |
21 |
from bzrlib.store import ImmutableStore |
1092.2.1
by Robert Collins
minor refactors to store, create an ImmutableMemoryStore for testing or other such operations |
22 |
from bzrlib.selftest import TestCase, TestCaseInTempDir |
974.1.44
by aaron.bentley at utoronto
Added test of double-add in ImmutableStore |
23 |
from bzrlib.errors import BzrError |
1092.3.4
by Robert Collins
update symlink branch to integration |
24 |
import bzrlib.store |
974.1.44
by aaron.bentley at utoronto
Added test of double-add in ImmutableStore |
25 |
|
1185.1.41
by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid |
26 |
|
974.1.52
by aaron.bentley at utoronto
Merged mpool's latest changes (~0.0.7) |
27 |
class TestStore(TestCaseInTempDir): |
1092.2.1
by Robert Collins
minor refactors to store, create an ImmutableMemoryStore for testing or other such operations |
28 |
|
974.1.44
by aaron.bentley at utoronto
Added test of double-add in ImmutableStore |
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 |
||
1092.2.1
by Robert Collins
minor refactors to store, create an ImmutableMemoryStore for testing or other such operations |
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)) |