~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/branch_implementations/test_branch.py

  • Committer: John Arbash Meinel
  • Date: 2006-06-26 16:31:49 UTC
  • mfrom: (1813 +trunk)
  • mto: (1711.7.2 win32)
  • mto: This revision was merged to the branch mainline in revision 1822.
  • Revision ID: john@arbash-meinel.com-20060626163149-2213f2f2d895829d
[merge] bzr.dev 1813

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
2
2
 
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
19
19
import os
20
20
import sys
21
21
 
22
 
import bzrlib.branch
23
 
import bzrlib.bzrdir as bzrdir
 
22
from bzrlib import branch, bzrdir, errors, gpg, transactions, repository
24
23
from bzrlib.branch import Branch, needs_read_lock, needs_write_lock
25
 
from bzrlib.commit import commit
26
24
from bzrlib.delta import TreeDelta
27
 
import bzrlib.errors as errors
28
25
from bzrlib.errors import (FileExists,
29
26
                           NoSuchRevision,
30
27
                           NoSuchFile,
31
28
                           UninitializableFormat,
32
29
                           NotBranchError,
33
30
                           )
34
 
import bzrlib.gpg
35
31
from bzrlib.osutils import getcwd
36
32
from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
37
33
from bzrlib.tests.bzrdir_implementations.test_bzrdir import TestCaseWithBzrDir
38
34
from bzrlib.trace import mutter
39
 
import bzrlib.transactions as transactions
40
35
from bzrlib.transport import get_transport
41
36
from bzrlib.transport.http import HttpServer
42
37
from bzrlib.transport.memory import MemoryServer
193
188
        source = self.make_branch('source')
194
189
        target = source.bzrdir.sprout(self.get_url('target')).open_branch()
195
190
        self.assertEqual(source.bzrdir.root_transport.base, target.get_parent())
 
191
 
 
192
    def test_submit_branch(self):
 
193
        """Submit location can be queried and set"""
 
194
        branch = self.make_branch('branch')
 
195
        self.assertEqual(branch.get_submit_branch(), None)
 
196
        branch.set_submit_branch('sftp://example.com')
 
197
        self.assertEqual(branch.get_submit_branch(), 'sftp://example.com')
 
198
        branch.set_submit_branch('sftp://example.net')
 
199
        self.assertEqual(branch.get_submit_branch(), 'sftp://example.net')
196
200
        
197
201
    def test_record_initial_ghost_merge(self):
198
202
        """A pending merge with no revision present is still a merge."""
244
248
        branch = wt.branch
245
249
        wt.commit("base", allow_pointless=True, rev_id='A')
246
250
        from bzrlib.testament import Testament
247
 
        strategy = bzrlib.gpg.LoopbackGPGStrategy(None)
 
251
        strategy = gpg.LoopbackGPGStrategy(None)
248
252
        branch.repository.sign_revision('A', strategy)
249
253
        self.assertEqual(Testament.from_revision(branch.repository, 
250
254
                         'A').as_short_text(),
254
258
        wt = self.make_branch_and_tree('.')
255
259
        branch = wt.branch
256
260
        branch.repository.store_revision_signature(
257
 
            bzrlib.gpg.LoopbackGPGStrategy(None), 'FOO', 'A')
 
261
            gpg.LoopbackGPGStrategy(None), 'FOO', 'A')
258
262
        self.assertRaises(errors.NoSuchRevision,
259
263
                          branch.repository.has_signature_for_revision_id,
260
264
                          'A')
266
270
        wt = self.make_branch_and_tree('source')
267
271
        wt.commit('A', allow_pointless=True, rev_id='A')
268
272
        wt.branch.repository.sign_revision('A',
269
 
            bzrlib.gpg.LoopbackGPGStrategy(None))
 
273
            gpg.LoopbackGPGStrategy(None))
270
274
        #FIXME: clone should work to urls,
271
275
        # wt.clone should work to disks.
272
276
        self.build_tree(['target/'])
324
328
            return
325
329
        self.assertEqual(repo.bzrdir.root_transport.base,
326
330
                         child_branch.repository.bzrdir.root_transport.base)
327
 
        child_branch = bzrlib.branch.Branch.open(self.get_url('child'))
 
331
        child_branch = branch.Branch.open(self.get_url('child'))
328
332
        self.assertEqual(repo.bzrdir.root_transport.base,
329
333
                         child_branch.repository.bzrdir.root_transport.base)
330
334
 
343
347
 
344
348
    def test_get_commit_builder(self):
345
349
        self.assertIsInstance(self.make_branch(".").get_commit_builder([]), 
346
 
            bzrlib.repository.CommitBuilder)
 
350
            repository.CommitBuilder)
 
351
 
 
352
    def test_generate_revision_history(self):
 
353
        """Create a fake revision history easily."""
 
354
        tree = self.make_branch_and_tree('.')
 
355
        rev1 = tree.commit('foo')
 
356
        orig_history = tree.branch.revision_history()
 
357
        rev2 = tree.commit('bar', allow_pointless=True)
 
358
        tree.branch.generate_revision_history(rev1)
 
359
        self.assertEqual(orig_history, tree.branch.revision_history())
347
360
 
348
361
 
349
362
class ChrootedTests(TestCaseWithBranch):
370
383
        branch, relpath = Branch.open_containing(self.get_readonly_url('g/p/q'))
371
384
        self.assertEqual('g/p/q', relpath)
372
385
        
373
 
# TODO: rewrite this as a regular unittest, without relying on the displayed output        
374
 
#         >>> from bzrlib.commit import commit
375
 
#         >>> bzrlib.trace.silent = True
376
 
#         >>> br1 = ScratchBranch(files=['foo', 'bar'])
377
 
#         >>> br1.working_tree().add('foo')
378
 
#         >>> br1.working_tree().add('bar')
379
 
#         >>> commit(br1, "lala!", rev_id="REVISION-ID-1", verbose=False)
380
 
#         >>> br2 = ScratchBranch()
381
 
#         >>> br2.update_revisions(br1)
382
 
#         Added 2 texts.
383
 
#         Added 1 inventories.
384
 
#         Added 1 revisions.
385
 
#         >>> br2.revision_history()
386
 
#         [u'REVISION-ID-1']
387
 
#         >>> br2.update_revisions(br1)
388
 
#         Added 0 revisions.
389
 
#         >>> br1.text_store.total_size() == br2.text_store.total_size()
390
 
#         True
391
386
 
392
387
class InstrumentedTransaction(object):
393
388
 
544
539
        t = get_transport(self.get_url())
545
540
        readonly_t = get_transport(self.get_readonly_url())
546
541
        made_branch = self.make_branch('.')
547
 
        self.failUnless(isinstance(made_branch, bzrlib.branch.Branch))
 
542
        self.failUnless(isinstance(made_branch, branch.Branch))
548
543
 
549
544
        # find it via bzrdir opening:
550
545
        opened_control = bzrdir.BzrDir.open(readonly_t.base)
555
550
                        self.branch_format.__class__))
556
551
 
557
552
        # find it via Branch.open
558
 
        opened_branch = bzrlib.branch.Branch.open(readonly_t.base)
 
553
        opened_branch = branch.Branch.open(readonly_t.base)
559
554
        self.failUnless(isinstance(opened_branch, made_branch.__class__))
560
555
        self.assertEqual(made_branch._format.__class__,
561
556
                         opened_branch._format.__class__)
565
560
        except NotImplementedError:
566
561
            return
567
562
        self.assertEqual(self.branch_format,
568
 
                         bzrlib.branch.BranchFormat.find_format(opened_control))
 
563
                         branch.BranchFormat.find_format(opened_control))