~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Martin Pool
  • Date: 2006-06-20 07:55:43 UTC
  • mfrom: (1798 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1799.
  • Revision ID: mbp@sourcefrog.net-20060620075543-b10f6575d4a4fa32
[merge] bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
import bzrlib.errors as errors
 
24
from bzrlib.delta import TreeDelta
27
25
from bzrlib.errors import (FileExists,
28
26
                           NoSuchRevision,
29
27
                           NoSuchFile,
30
28
                           UninitializableFormat,
31
29
                           NotBranchError,
32
30
                           )
33
 
import bzrlib.gpg
34
31
from bzrlib.osutils import getcwd
35
32
from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
36
33
from bzrlib.tests.bzrdir_implementations.test_bzrdir import TestCaseWithBzrDir
37
34
from bzrlib.trace import mutter
38
 
import bzrlib.transactions as transactions
39
35
from bzrlib.transport import get_transport
40
36
from bzrlib.transport.http import HttpServer
41
37
from bzrlib.transport.memory import MemoryServer
101
97
        tree = b2.repository.revision_tree('revision-1')
102
98
        self.assertEqual(tree.get_file_text('foo-id'), 'hello')
103
99
 
 
100
    def test_get_revision_delta(self):
 
101
        tree_a = self.make_branch_and_tree('a')
 
102
        self.build_tree(['a/foo'])
 
103
        tree_a.add('foo', 'file1')
 
104
        tree_a.commit('rev1', rev_id='rev1')
 
105
        self.build_tree(['a/vla'])
 
106
        tree_a.add('vla', 'file2')
 
107
        tree_a.commit('rev2', rev_id='rev2')
 
108
 
 
109
        delta = tree_a.branch.get_revision_delta(1)
 
110
        self.assertIsInstance(delta, TreeDelta)
 
111
        self.assertEqual([('foo', 'file1', 'file')], delta.added)
 
112
        delta = tree_a.branch.get_revision_delta(2)
 
113
        self.assertIsInstance(delta, TreeDelta)
 
114
        self.assertEqual([('vla', 'file2', 'file')], delta.added)
 
115
 
104
116
    def get_unbalanced_tree_pair(self):
105
117
        """Return two branches, a and b, with one file in a."""
106
118
        get_transport(self.get_url()).mkdir('a')
227
239
        branch = wt.branch
228
240
        wt.commit("base", allow_pointless=True, rev_id='A')
229
241
        from bzrlib.testament import Testament
230
 
        strategy = bzrlib.gpg.LoopbackGPGStrategy(None)
 
242
        strategy = gpg.LoopbackGPGStrategy(None)
231
243
        branch.repository.sign_revision('A', strategy)
232
244
        self.assertEqual(Testament.from_revision(branch.repository, 
233
245
                         'A').as_short_text(),
237
249
        wt = self.make_branch_and_tree('.')
238
250
        branch = wt.branch
239
251
        branch.repository.store_revision_signature(
240
 
            bzrlib.gpg.LoopbackGPGStrategy(None), 'FOO', 'A')
 
252
            gpg.LoopbackGPGStrategy(None), 'FOO', 'A')
241
253
        self.assertRaises(errors.NoSuchRevision,
242
254
                          branch.repository.has_signature_for_revision_id,
243
255
                          'A')
249
261
        wt = self.make_branch_and_tree('source')
250
262
        wt.commit('A', allow_pointless=True, rev_id='A')
251
263
        wt.branch.repository.sign_revision('A',
252
 
            bzrlib.gpg.LoopbackGPGStrategy(None))
 
264
            gpg.LoopbackGPGStrategy(None))
253
265
        #FIXME: clone should work to urls,
254
266
        # wt.clone should work to disks.
255
267
        self.build_tree(['target/'])
307
319
            return
308
320
        self.assertEqual(repo.bzrdir.root_transport.base,
309
321
                         child_branch.repository.bzrdir.root_transport.base)
310
 
        child_branch = bzrlib.branch.Branch.open(self.get_url('child'))
 
322
        child_branch = branch.Branch.open(self.get_url('child'))
311
323
        self.assertEqual(repo.bzrdir.root_transport.base,
312
324
                         child_branch.repository.bzrdir.root_transport.base)
313
325
 
316
328
        text = tree.branch._format.get_format_description()
317
329
        self.failUnless(len(text))
318
330
 
 
331
    def test_check_branch_report_results(self):
 
332
        """Checking a branch produces results which can be printed"""
 
333
        branch = self.make_branch('.')
 
334
        result = branch.check()
 
335
        # reports results through logging
 
336
        result.report_results(verbose=True)
 
337
        result.report_results(verbose=False)
 
338
 
 
339
    def test_get_commit_builder(self):
 
340
        self.assertIsInstance(self.make_branch(".").get_commit_builder([]), 
 
341
            repository.CommitBuilder)
 
342
 
319
343
 
320
344
class ChrootedTests(TestCaseWithBranch):
321
345
    """A support class that provides readonly urls outside the local namespace.
460
484
        self.assertEqual(None, self.get_branch().get_push_location())
461
485
 
462
486
    def test_get_push_location_exact(self):
463
 
        from bzrlib.config import (branches_config_filename,
 
487
        from bzrlib.config import (locations_config_filename,
464
488
                                   ensure_config_dir_exists)
465
489
        ensure_config_dir_exists()
466
 
        fn = branches_config_filename()
 
490
        fn = locations_config_filename()
467
491
        print >> open(fn, 'wt'), ("[%s]\n"
468
492
                                  "push_location=foo" %
469
493
                                  self.get_branch().base[:-1])
470
494
        self.assertEqual("foo", self.get_branch().get_push_location())
471
495
 
472
496
    def test_set_push_location(self):
473
 
        from bzrlib.config import (branches_config_filename,
 
497
        from bzrlib.config import (locations_config_filename,
474
498
                                   ensure_config_dir_exists)
475
499
        ensure_config_dir_exists()
476
 
        fn = branches_config_filename()
 
500
        fn = locations_config_filename()
477
501
        self.get_branch().set_push_location('foo')
478
502
        self.assertFileEqual("[%s]\n"
479
503
                             "push_location = foo" % self.get_branch().base[:-1],
497
521
        t = get_transport(self.get_url())
498
522
        readonly_t = get_transport(self.get_readonly_url())
499
523
        made_branch = self.make_branch('.')
500
 
        self.failUnless(isinstance(made_branch, bzrlib.branch.Branch))
 
524
        self.failUnless(isinstance(made_branch, branch.Branch))
501
525
 
502
526
        # find it via bzrdir opening:
503
527
        opened_control = bzrdir.BzrDir.open(readonly_t.base)
508
532
                        self.branch_format.__class__))
509
533
 
510
534
        # find it via Branch.open
511
 
        opened_branch = bzrlib.branch.Branch.open(readonly_t.base)
 
535
        opened_branch = branch.Branch.open(readonly_t.base)
512
536
        self.failUnless(isinstance(opened_branch, made_branch.__class__))
513
537
        self.assertEqual(made_branch._format.__class__,
514
538
                         opened_branch._format.__class__)
518
542
        except NotImplementedError:
519
543
            return
520
544
        self.assertEqual(self.branch_format,
521
 
                         bzrlib.branch.BranchFormat.find_format(opened_control))
 
545
                         branch.BranchFormat.find_format(opened_control))