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 bzrlib.store import ImmutableStore
21
from bzrlib.selftest import TestCase, TestCaseInTempDir
22
from StringIO import StringIO
23
from bzrlib.errors import BzrError
25
class TestStore(TestCaseInTempDir):
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')
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))
41
class TestMemoryStore(TestCase):
44
return bzrlib.store.ImmutableMemoryStore()
46
def test_imports(self):
47
from bzrlib.store import ImmutableMemoryStore
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')
58
def test_missing_is_absent(self):
59
store = self.get_store()
60
self.failIf('aa' in store)
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')
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))