14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
18
"""Tests for the behaviour of the Transaction concept in bzr."""
33
33
def __init__(self, message):
34
34
self._message = message
37
36
def __eq__(self, other):
40
39
return self._message == other._message
42
def transaction_finished(self):
46
42
class TestSymbols(TestCase):
60
56
self.transaction.register_clean("anobject")
62
58
def test_register_dirty_raises(self):
63
self.assertRaises(errors.ReadOnlyError,
59
self.assertRaises(errors.ReadOnlyError,
64
60
self.transaction.register_dirty,"anobject")
66
62
def test_map(self):
67
63
self.assertNotEqual(None, getattr(self.transaction, "map", None))
69
65
def test_add_and_get(self):
71
67
self.transaction.map.add_weave("id", weave)
74
70
def test_finish_returns(self):
75
71
self.transaction.finish()
77
def test_finish_does_not_tell_versioned_file_finished(self):
78
# read only transactions never write, so theres no
79
# need to inform versioned files about finishing
80
weave = DummyWeave('a weave')
81
self.transaction.finish()
82
self.assertFalse(weave.finished)
84
73
def test_zero_size_cache(self):
85
74
self.transaction.set_cache_size(0)
86
75
weave = DummyWeave('a weave')
99
88
# its not a weakref system
100
89
self.assertEqual(DummyWeave("another weave"),
101
90
self.transaction.map.find_weave("id"))
103
92
def test_small_cache(self):
104
93
self.transaction.set_cache_size(1)
105
94
# add an object, should not fall right out if there are no references
139
128
self.assertEqual(DummyWeave('a weave'),
140
129
self.transaction.map.find_weave("id"))
142
def test_writable(self):
143
self.assertFalse(self.transaction.writeable())
131
def test_precious_revision_history(self):
132
"""Disabled test until revision-history is a real object."""
133
print "Disabled: test_precious_revision_history"
135
self.transaction.set_cache_size(0)
137
self.transaction.map.add_revision_history(history)
138
self.assertEqual(history, self.transaction.map.find_revision_history())
140
# add an object, should not fall out even with no references.
141
self.transaction.register_clean(
142
self.transaction.map.find_revision_history(), precious=True)
143
self.assertEqual([], self.transaction.map.find_revision_history())
146
146
class TestPassThroughTransaction(TestCase):
151
151
def test_register_clean(self):
152
152
transaction = transactions.PassThroughTransaction()
153
153
transaction.register_clean("anobject")
155
155
def test_register_dirty(self):
156
156
transaction = transactions.PassThroughTransaction()
157
157
transaction.register_dirty("anobject")
159
159
def test_map(self):
160
160
transaction = transactions.PassThroughTransaction()
161
161
self.assertNotEqual(None, getattr(transaction, "map", None))
163
163
def test_add_and_get(self):
164
164
transaction = transactions.PassThroughTransaction()
165
165
weave = "a weave"
166
166
transaction.map.add_weave("id", weave)
167
167
self.assertEqual(None, transaction.map.find_weave("id"))
169
169
def test_finish_returns(self):
170
170
transaction = transactions.PassThroughTransaction()
171
171
transaction.finish()
173
def test_finish_tells_versioned_file_finished(self):
174
# pass through transactions allow writes so they
175
# need to inform versioned files about finishing
176
weave = DummyWeave('a weave')
177
transaction = transactions.PassThroughTransaction()
178
transaction.register_dirty(weave)
180
self.assertTrue(weave.finished)
182
173
def test_cache_is_ignored(self):
183
174
transaction = transactions.PassThroughTransaction()
184
175
transaction.set_cache_size(100)
186
177
transaction.map.add_weave("id", weave)
187
178
self.assertEqual(None, transaction.map.find_weave("id"))
189
def test_writable(self):
190
transaction = transactions.PassThroughTransaction()
191
self.assertTrue(transaction.writeable())
194
181
class TestWriteTransaction(TestCase):
200
187
def test_register_clean(self):
201
188
self.transaction.register_clean("anobject")
203
190
def test_register_dirty(self):
204
191
self.transaction.register_dirty("anobject")
206
193
def test_map(self):
207
194
self.assertNotEqual(None, getattr(self.transaction, "map", None))
209
196
def test_add_and_get(self):
210
197
weave = "a weave"
211
198
self.transaction.map.add_weave("id", weave)
212
199
self.assertEqual(weave, self.transaction.map.find_weave("id"))
214
201
def test_finish_returns(self):
215
202
self.transaction.finish()
217
def test_finish_tells_versioned_file_finished(self):
218
# write transactions allow writes so they
219
# need to inform versioned files about finishing
220
weave = DummyWeave('a weave')
221
self.transaction.register_dirty(weave)
222
self.transaction.finish()
223
self.assertTrue(weave.finished)
225
204
def test_zero_size_cache(self):
226
205
self.transaction.set_cache_size(0)
227
206
# add an object, should fall right out if there are no references
251
230
self.transaction.register_dirty(self.transaction.map.find_weave("id"))
252
231
self.assertNotEqual(None, self.transaction.map.find_weave("id"))
254
233
def test_clean_to_dirty(self):
255
234
# a clean object may become dirty.
256
235
weave = DummyWeave('A weave')