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 |
from StringIO import StringIO |
1185.1.46
by Robert Collins
Aarons branch --basis patch |
20 |
import os |
1185.1.41
by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid |
21 |
|
1393.2.1
by John Arbash Meinel
Merged in split-storage-2 branch. Need to cleanup a little bit more still. |
22 |
from bzrlib.store import copy_all |
1185.11.1
by John Arbash Meinel
(broken) Transport work is merged in. Tests do not pass yet. |
23 |
from bzrlib.transport.local import LocalTransport |
24 |
from bzrlib.transport import NoSuchFile |
|
25 |
from bzrlib.store.compressed_text import CompressedTextStore |
|
1393.2.2
by John Arbash Meinel
Updated stores to use Transport |
26 |
from bzrlib.store.text import TextStore |
974.1.52
by aaron.bentley at utoronto
Merged mpool's latest changes (~0.0.7) |
27 |
from bzrlib.selftest import TestCaseInTempDir |
1185.10.1
by Aaron Bentley
Added --basis option to bzr branch |
28 |
from bzrlib.errors import BzrError, UnlistableStore |
974.1.44
by aaron.bentley at utoronto
Added test of double-add in ImmutableStore |
29 |
|
1185.1.41
by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid |
30 |
|
1185.11.1
by John Arbash Meinel
(broken) Transport work is merged in. Tests do not pass yet. |
31 |
def fill_store(store): |
32 |
store.add(StringIO('hello'), 'a') |
|
33 |
store.add(StringIO('other'), 'b') |
|
34 |
store.add(StringIO('something'), 'c') |
|
35 |
store.add(StringIO('goodbye'), '123123') |
|
36 |
||
1185.11.16
by John Arbash Meinel
Fixed teststore with correct parameter name. |
37 |
def check_equals(tester, store, files, values, permit_failure=False): |
38 |
files = store.get(files, permit_failure=permit_failure) |
|
1185.11.1
by John Arbash Meinel
(broken) Transport work is merged in. Tests do not pass yet. |
39 |
count = 0 |
40 |
for f, v in zip(files, values): |
|
41 |
count += 1 |
|
42 |
if v is None: |
|
43 |
tester.assert_(f is None) |
|
44 |
else: |
|
45 |
tester.assertEquals(f.read(), v) |
|
46 |
tester.assertEquals(count, len(values)) |
|
47 |
# We need to check to make sure there are no more
|
|
48 |
# files to be returned, I'm using a cheezy way
|
|
49 |
# Convert to a list, and there shouldn't be any left
|
|
50 |
tester.assertEquals(len(list(files)), 0) |
|
51 |
||
52 |
def test_multiple_add(tester, store): |
|
53 |
fill_store(store) |
|
54 |
tester.assertRaises(BzrError, store.add, StringIO('goodbye'), '123123') |
|
55 |
||
56 |
def test_get(tester, store): |
|
57 |
fill_store(store) |
|
58 |
||
59 |
check_equals(tester, store, ['a'], ['hello']) |
|
60 |
check_equals(tester, store, ['b', 'c'], ['other', 'something']) |
|
61 |
||
62 |
# Make sure that requesting a non-existing file fails
|
|
63 |
tester.assertRaises(NoSuchFile, check_equals, tester, store, |
|
64 |
['d'], [None]) |
|
65 |
tester.assertRaises(NoSuchFile, check_equals, tester, store, |
|
66 |
['a', 'd'], ['hello', None]) |
|
67 |
tester.assertRaises(NoSuchFile, check_equals, tester, store, |
|
68 |
['d', 'a'], [None, 'hello']) |
|
69 |
tester.assertRaises(NoSuchFile, check_equals, tester, store, |
|
70 |
['d', 'd', 'd'], [None, None, None]) |
|
71 |
tester.assertRaises(NoSuchFile, check_equals, tester, store, |
|
72 |
['a', 'd', 'b'], ['hello', None, 'other']) |
|
73 |
||
74 |
def test_ignore_get(tester, store): |
|
75 |
fill_store(store) |
|
76 |
||
1185.11.16
by John Arbash Meinel
Fixed teststore with correct parameter name. |
77 |
files = store.get(['d'], permit_failure=True) |
1185.11.1
by John Arbash Meinel
(broken) Transport work is merged in. Tests do not pass yet. |
78 |
files = list(files) |
79 |
tester.assertEquals(len(files), 1) |
|
80 |
tester.assert_(files[0] is None) |
|
81 |
||
82 |
check_equals(tester, store, ['a', 'd'], ['hello', None], |
|
1185.11.16
by John Arbash Meinel
Fixed teststore with correct parameter name. |
83 |
permit_failure=True) |
1185.11.1
by John Arbash Meinel
(broken) Transport work is merged in. Tests do not pass yet. |
84 |
check_equals(tester, store, ['d', 'a'], [None, 'hello'], |
1185.11.16
by John Arbash Meinel
Fixed teststore with correct parameter name. |
85 |
permit_failure=True) |
1185.11.1
by John Arbash Meinel
(broken) Transport work is merged in. Tests do not pass yet. |
86 |
check_equals(tester, store, ['d', 'd'], [None, None], |
1185.11.16
by John Arbash Meinel
Fixed teststore with correct parameter name. |
87 |
permit_failure=True) |
88 |
check_equals(tester, store, ['a', 'd', 'b'], ['hello', None, 'other'], |
|
89 |
permit_failure=True) |
|
90 |
check_equals(tester, store, ['a', 'd', 'b'], ['hello', None, 'other'], |
|
91 |
permit_failure=True) |
|
1185.11.1
by John Arbash Meinel
(broken) Transport work is merged in. Tests do not pass yet. |
92 |
check_equals(tester, store, ['b', 'd', 'c'], ['other', None, 'something'], |
1185.11.16
by John Arbash Meinel
Fixed teststore with correct parameter name. |
93 |
permit_failure=True) |
1185.11.1
by John Arbash Meinel
(broken) Transport work is merged in. Tests do not pass yet. |
94 |
|
1393.2.4
by John Arbash Meinel
All tests pass. |
95 |
def get_compressed_store(path='.'): |
96 |
t = LocalTransport(path) |
|
1185.11.1
by John Arbash Meinel
(broken) Transport work is merged in. Tests do not pass yet. |
97 |
return CompressedTextStore(t) |
98 |
||
1393.2.4
by John Arbash Meinel
All tests pass. |
99 |
def get_text_store(path='.'): |
100 |
t = LocalTransport(path) |
|
1393.2.2
by John Arbash Meinel
Updated stores to use Transport |
101 |
return TextStore(t) |
102 |
||
1185.11.1
by John Arbash Meinel
(broken) Transport work is merged in. Tests do not pass yet. |
103 |
class TestCompressedTextStore(TestCaseInTempDir): |
974.1.44
by aaron.bentley at utoronto
Added test of double-add in ImmutableStore |
104 |
def test_multiple_add(self): |
105 |
"""Multiple add with same ID should raise a BzrError"""
|
|
1185.11.1
by John Arbash Meinel
(broken) Transport work is merged in. Tests do not pass yet. |
106 |
store = get_compressed_store() |
107 |
test_multiple_add(self, store) |
|
108 |
||
109 |
def test_get(self): |
|
110 |
store = get_compressed_store() |
|
111 |
test_get(self, store) |
|
112 |
||
113 |
def test_ignore_get(self): |
|
114 |
store = get_compressed_store() |
|
115 |
test_ignore_get(self, store) |
|
116 |
||
974.1.44
by aaron.bentley at utoronto
Added test of double-add in ImmutableStore |
117 |
|
1185.10.1
by Aaron Bentley
Added --basis option to bzr branch |
118 |
def test_copy_all(self): |
119 |
"""Test copying"""
|
|
120 |
os.mkdir('a') |
|
1393.2.4
by John Arbash Meinel
All tests pass. |
121 |
store_a = get_text_store('a') |
1185.10.1
by Aaron Bentley
Added --basis option to bzr branch |
122 |
store_a.add('foo', '1') |
123 |
os.mkdir('b') |
|
1393.2.4
by John Arbash Meinel
All tests pass. |
124 |
store_b = get_text_store('b') |
1185.10.1
by Aaron Bentley
Added --basis option to bzr branch |
125 |
copy_all(store_a, store_b) |
126 |
self.assertEqual(store_a['1'].read(), 'foo') |
|
127 |
self.assertEqual(store_b['1'].read(), 'foo') |
|
1393.2.1
by John Arbash Meinel
Merged in split-storage-2 branch. Need to cleanup a little bit more still. |
128 |
# TODO: Switch the exception form UnlistableStore to
|
129 |
# or make Stores throw UnlistableStore if their
|
|
130 |
# Transport doesn't support listing
|
|
131 |
# store_c = RemoteStore('http://example.com/')
|
|
132 |
# self.assertRaises(UnlistableStore, copy_all, store_c, store_b)
|
|
133 |
||
1393.2.2
by John Arbash Meinel
Updated stores to use Transport |
134 |
class TestTextStore(TestCaseInTempDir): |
135 |
def test_multiple_add(self): |
|
136 |
"""Multiple add with same ID should raise a BzrError"""
|
|
137 |
store = get_text_store() |
|
138 |
test_multiple_add(self, store) |
|
139 |
||
140 |
def test_get(self): |
|
141 |
store = get_text_store() |
|
142 |
test_get(self, store) |
|
143 |
||
144 |
def test_ignore_get(self): |
|
145 |
store = get_text_store() |
|
146 |
test_ignore_get(self, store) |
|
147 |
||
148 |
||
149 |
def test_copy_all(self): |
|
150 |
"""Test copying"""
|
|
151 |
os.mkdir('a') |
|
1393.2.4
by John Arbash Meinel
All tests pass. |
152 |
store_a = get_text_store('a') |
1393.2.2
by John Arbash Meinel
Updated stores to use Transport |
153 |
store_a.add('foo', '1') |
154 |
os.mkdir('b') |
|
1393.2.4
by John Arbash Meinel
All tests pass. |
155 |
store_b = get_text_store('b') |
1393.2.2
by John Arbash Meinel
Updated stores to use Transport |
156 |
copy_all(store_a, store_b) |
157 |
self.assertEqual(store_a['1'].read(), 'foo') |
|
158 |
self.assertEqual(store_b['1'].read(), 'foo') |
|
159 |
# TODO: Switch the exception form UnlistableStore to
|
|
160 |
# or make Stores throw UnlistableStore if their
|
|
161 |
# Transport doesn't support listing
|
|
162 |
# store_c = RemoteStore('http://example.com/')
|
|
163 |
# self.assertRaises(UnlistableStore, copy_all, store_c, store_b)
|
|
164 |