~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testbranch.py

[merge] from robert and fix up tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
import os
18
 
from bzrlib.branch import Branch
 
18
 
 
19
from bzrlib.branch import Branch, needs_read_lock, needs_write_lock
19
20
from bzrlib.clone import copy_branch
20
21
from bzrlib.commit import commit
21
22
import bzrlib.errors as errors
22
23
from bzrlib.errors import NoSuchRevision, UnlistableBranch, NotBranchError
23
 
from bzrlib.selftest import TestCaseInTempDir
 
24
import bzrlib.gpg
 
25
from bzrlib.selftest import TestCase, TestCaseInTempDir
 
26
from bzrlib.selftest.HTTPTestUtil import TestCaseWithWebserver
24
27
from bzrlib.trace import mutter
25
28
import bzrlib.transactions as transactions
26
 
from bzrlib.selftest.HTTPTestUtil import TestCaseWithWebserver
27
29
 
28
30
# TODO: Make a branch using basis branch, and check that it 
29
31
# doesn't request any files that could have been avoided, by 
142
144
        # list should be cleared when we do a commit
143
145
        self.assertEquals(b.pending_merges(), [])
144
146
 
 
147
    def test_sign_existing_revision(self):
 
148
        branch = Branch.initialize('.')
 
149
        branch.commit("base", allow_pointless=True, rev_id='A')
 
150
        from bzrlib.testament import Testament
 
151
        branch.sign_revision('A', bzrlib.gpg.LoopbackGPGStrategy(None))
 
152
        self.assertEqual(Testament.from_revision(branch, 'A').as_short_text(),
 
153
                         branch.revision_store.get('A', 'sig').read())
 
154
 
 
155
    def test_store_signature(self):
 
156
        branch = Branch.initialize('.')
 
157
        branch.store_revision_signature(bzrlib.gpg.LoopbackGPGStrategy(None),
 
158
                                        'FOO', 'A')
 
159
        self.assertEqual('FOO', branch.revision_store.get('A', 'sig').read())
 
160
 
145
161
 
146
162
class TestRemote(TestCaseWithWebserver):
147
163
 
151
167
        self.assertRaises(NotBranchError, Branch.open_containing,
152
168
                          self.get_remote_url('g/p/q'))
153
169
        b = Branch.initialize('.')
154
 
        Branch.open_containing(self.get_remote_url(''))
155
 
        Branch.open_containing(self.get_remote_url('g/p/q'))
 
170
        branch, relpath = Branch.open_containing(self.get_remote_url(''))
 
171
        self.assertEqual('', relpath)
 
172
        branch, relpath = Branch.open_containing(self.get_remote_url('g/p/q'))
 
173
        self.assertEqual('g/p/q', relpath)
156
174
        
157
175
# TODO: rewrite this as a regular unittest, without relying on the displayed output        
158
176
#         >>> from bzrlib.commit import commit
182
200
        self.calls = []
183
201
 
184
202
 
 
203
class TestDecorator(object):
 
204
 
 
205
    def __init__(self):
 
206
        self._calls = []
 
207
 
 
208
    def lock_read(self):
 
209
        self._calls.append('lr')
 
210
 
 
211
    def lock_write(self):
 
212
        self._calls.append('lw')
 
213
 
 
214
    def unlock(self):
 
215
        self._calls.append('ul')
 
216
 
 
217
    @needs_read_lock
 
218
    def do_with_read(self):
 
219
        return 1
 
220
 
 
221
    @needs_read_lock
 
222
    def except_with_read(self):
 
223
        raise RuntimeError
 
224
 
 
225
    @needs_write_lock
 
226
    def do_with_write(self):
 
227
        return 2
 
228
 
 
229
    @needs_write_lock
 
230
    def except_with_write(self):
 
231
        raise RuntimeError
 
232
 
 
233
 
 
234
class TestDecorators(TestCase):
 
235
 
 
236
    def test_needs_read_lock(self):
 
237
        branch = TestDecorator()
 
238
        self.assertEqual(1, branch.do_with_read())
 
239
        self.assertEqual(['lr', 'ul'], branch._calls)
 
240
 
 
241
    def test_excepts_in_read_lock(self):
 
242
        branch = TestDecorator()
 
243
        self.assertRaises(RuntimeError, branch.except_with_read)
 
244
        self.assertEqual(['lr', 'ul'], branch._calls)
 
245
 
 
246
    def test_needs_write_lock(self):
 
247
        branch = TestDecorator()
 
248
        self.assertEqual(2, branch.do_with_write())
 
249
        self.assertEqual(['lw', 'ul'], branch._calls)
 
250
 
 
251
    def test_excepts_in_write_lock(self):
 
252
        branch = TestDecorator()
 
253
        self.assertRaises(RuntimeError, branch.except_with_write)
 
254
        self.assertEqual(['lw', 'ul'], branch._calls)
 
255
 
 
256
 
185
257
class TestBranchTransaction(TestCaseInTempDir):
186
258
 
187
259
    def setUp(self):