/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transactions.py

  • Committer: John Arbash Meinel
  • Date: 2006-04-25 15:05:42 UTC
  • mfrom: (1185.85.85 bzr-encoding)
  • mto: This revision was merged to the branch mainline in revision 1752.
  • Revision ID: john@arbash-meinel.com-20060425150542-c7b518dca9928691
[merge] the old bzr-encoding changes, reparenting them on bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2009, 2011 Canonical Ltd
 
1
# Copyright (C) 2005 by Canonical Ltd
2
2
#   Authors: Robert Collins <robert.collins@canonical.com>
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
13
13
#
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
17
17
 
18
18
"""Tests for the behaviour of the Transaction concept in bzr."""
19
19
 
20
 
# import breezy specific imports here
21
 
import breezy.errors as errors
22
 
from breezy.tests import TestCase
23
 
import breezy.transactions as transactions
 
20
# import system imports here
 
21
import os
 
22
import sys
 
23
 
 
24
#import bzrlib specific imports here
 
25
import bzrlib.errors as errors
 
26
from bzrlib.tests import TestCase, TestCaseInTempDir
 
27
import bzrlib.transactions as transactions
24
28
 
25
29
 
26
30
class DummyWeave(object):
35
39
            return False
36
40
        return self._message == other._message
37
41
 
38
 
    def __hash__(self):
39
 
        return hash((type(self), self._message))
40
 
 
41
42
    def transaction_finished(self):
42
43
        self.finished = True
43
44
 
45
46
class TestSymbols(TestCase):
46
47
 
47
48
    def test_public_symbols(self):
48
 
        from breezy.transactions import ReadOnlyTransaction  # noqa: F401
49
 
        from breezy.transactions import PassThroughTransaction  # noqa: F401
 
49
        from bzrlib.transactions import ReadOnlyTransaction
 
50
        from bzrlib.transactions import PassThroughTransaction
50
51
 
51
52
 
52
53
class TestReadOnlyTransaction(TestCase):
59
60
        self.transaction.register_clean("anobject")
60
61
 
61
62
    def test_register_dirty_raises(self):
62
 
        self.assertRaises(errors.ReadOnlyError,
63
 
                          self.transaction.register_dirty, "anobject")
64
 
 
 
63
        self.assertRaises(errors.ReadOnlyError, 
 
64
                          self.transaction.register_dirty,"anobject")
 
65
    
65
66
    def test_map(self):
66
67
        self.assertNotEqual(None, getattr(self.transaction, "map", None))
67
 
 
 
68
    
68
69
    def test_add_and_get(self):
69
70
        weave = "a weave"
70
71
        self.transaction.map.add_weave("id", weave)
98
99
        # its not a weakref system
99
100
        self.assertEqual(DummyWeave("another weave"),
100
101
                         self.transaction.map.find_weave("id"))
101
 
 
 
102
        
102
103
    def test_small_cache(self):
103
104
        self.transaction.set_cache_size(1)
104
105
        # add an object, should not fall right out if there are no references
105
 
        # sys.getrefcounts(foo)
 
106
        #sys.getrefcounts(foo)
106
107
        self.transaction.map.add_weave("id", DummyWeave("a weave"))
107
108
        self.transaction.register_clean(self.transaction.map.find_weave("id"))
108
109
        self.assertEqual(DummyWeave("a weave"),
138
139
        self.assertEqual(DummyWeave('a weave'),
139
140
                         self.transaction.map.find_weave("id"))
140
141
 
 
142
    def test_precious_revision_history(self):
 
143
        """Disabled test until revision-history is a real object."""
 
144
        print "Disabled: test_precious_revision_history"
 
145
        return
 
146
        self.transaction.set_cache_size(0)
 
147
        history = []
 
148
        self.transaction.map.add_revision_history(history)
 
149
        self.assertEqual(history, self.transaction.map.find_revision_history())
 
150
        history = None
 
151
        # add an object, should not fall out even with no references.
 
152
        self.transaction.register_clean(
 
153
            self.transaction.map.find_revision_history(), precious=True)
 
154
        self.assertEqual([], self.transaction.map.find_revision_history())
 
155
 
141
156
    def test_writable(self):
142
157
        self.assertFalse(self.transaction.writeable())
143
158
 
150
165
    def test_register_clean(self):
151
166
        transaction = transactions.PassThroughTransaction()
152
167
        transaction.register_clean("anobject")
153
 
 
 
168
    
154
169
    def test_register_dirty(self):
155
170
        transaction = transactions.PassThroughTransaction()
156
171
        transaction.register_dirty("anobject")
157
 
 
 
172
    
158
173
    def test_map(self):
159
174
        transaction = transactions.PassThroughTransaction()
160
175
        self.assertNotEqual(None, getattr(transaction, "map", None))
161
 
 
 
176
    
162
177
    def test_add_and_get(self):
163
178
        transaction = transactions.PassThroughTransaction()
164
179
        weave = "a weave"
165
180
        transaction.map.add_weave("id", weave)
166
181
        self.assertEqual(None, transaction.map.find_weave("id"))
167
 
 
 
182
        
168
183
    def test_finish_returns(self):
169
184
        transaction = transactions.PassThroughTransaction()
170
185
        transaction.finish()
188
203
    def test_writable(self):
189
204
        transaction = transactions.PassThroughTransaction()
190
205
        self.assertTrue(transaction.writeable())
191
 
 
 
206
        
192
207
 
193
208
class TestWriteTransaction(TestCase):
194
209
 
198
213
 
199
214
    def test_register_clean(self):
200
215
        self.transaction.register_clean("anobject")
201
 
 
 
216
    
202
217
    def test_register_dirty(self):
203
218
        self.transaction.register_dirty("anobject")
204
 
 
 
219
    
205
220
    def test_map(self):
206
221
        self.assertNotEqual(None, getattr(self.transaction, "map", None))
207
 
 
 
222
    
208
223
    def test_add_and_get(self):
209
224
        weave = "a weave"
210
225
        self.transaction.map.add_weave("id", weave)
211
226
        self.assertEqual(weave, self.transaction.map.find_weave("id"))
212
 
 
 
227
        
213
228
    def test_finish_returns(self):
214
229
        self.transaction.finish()
215
230
 
249
264
        weave = None
250
265
        self.transaction.register_dirty(self.transaction.map.find_weave("id"))
251
266
        self.assertNotEqual(None, self.transaction.map.find_weave("id"))
252
 
 
 
267
    
253
268
    def test_clean_to_dirty(self):
254
269
        # a clean object may become dirty.
255
270
        weave = DummyWeave('A weave')
262
277
    def test_small_cache(self):
263
278
        self.transaction.set_cache_size(1)
264
279
        # add an object, should not fall right out if there are no references
265
 
        # sys.getrefcounts(foo)
 
280
        #sys.getrefcounts(foo)
266
281
        self.transaction.map.add_weave("id", DummyWeave("a weave"))
267
282
        self.transaction.register_clean(self.transaction.map.find_weave("id"))
268
283
        self.assertEqual(DummyWeave("a weave"),