1
# Copyright (C) 2005 by Canonical Development Ltd
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.
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.
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
17
"""Test Store implementation
19
from cStringIO import StringIO
21
from bzrlib.store import ImmutableStore
22
from bzrlib.selftest import TestCase, TestCaseInTempDir
23
from bzrlib.errors import BzrError
27
class TestStore(TestCaseInTempDir):
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')
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))
43
class TestMemoryStore(TestCase):
46
return bzrlib.store.ImmutableMemoryStore()
48
def test_imports(self):
49
from bzrlib.store import ImmutableMemoryStore
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')
60
def test_missing_is_absent(self):
61
store = self.get_store()
62
self.failIf('aa' in store)
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')
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))