/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/branch_implementations/test_branch.py

  • Committer: Aaron Bentley
  • Date: 2006-06-23 15:27:25 UTC
  • mfrom: (1806 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1807.
  • Revision ID: abentley@panoramicfeedback.com-20060623152725-61519496365d39fc
Merge bzr.dev

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
244
239
        branch = wt.branch
245
240
        wt.commit("base", allow_pointless=True, rev_id='A')
246
241
        from bzrlib.testament import Testament
247
 
        strategy = bzrlib.gpg.LoopbackGPGStrategy(None)
 
242
        strategy = gpg.LoopbackGPGStrategy(None)
248
243
        branch.repository.sign_revision('A', strategy)
249
244
        self.assertEqual(Testament.from_revision(branch.repository, 
250
245
                         'A').as_short_text(),
254
249
        wt = self.make_branch_and_tree('.')
255
250
        branch = wt.branch
256
251
        branch.repository.store_revision_signature(
257
 
            bzrlib.gpg.LoopbackGPGStrategy(None), 'FOO', 'A')
 
252
            gpg.LoopbackGPGStrategy(None), 'FOO', 'A')
258
253
        self.assertRaises(errors.NoSuchRevision,
259
254
                          branch.repository.has_signature_for_revision_id,
260
255
                          'A')
266
261
        wt = self.make_branch_and_tree('source')
267
262
        wt.commit('A', allow_pointless=True, rev_id='A')
268
263
        wt.branch.repository.sign_revision('A',
269
 
            bzrlib.gpg.LoopbackGPGStrategy(None))
 
264
            gpg.LoopbackGPGStrategy(None))
270
265
        #FIXME: clone should work to urls,
271
266
        # wt.clone should work to disks.
272
267
        self.build_tree(['target/'])
324
319
            return
325
320
        self.assertEqual(repo.bzrdir.root_transport.base,
326
321
                         child_branch.repository.bzrdir.root_transport.base)
327
 
        child_branch = bzrlib.branch.Branch.open(self.get_url('child'))
 
322
        child_branch = branch.Branch.open(self.get_url('child'))
328
323
        self.assertEqual(repo.bzrdir.root_transport.base,
329
324
                         child_branch.repository.bzrdir.root_transport.base)
330
325
 
343
338
 
344
339
    def test_get_commit_builder(self):
345
340
        self.assertIsInstance(self.make_branch(".").get_commit_builder([]), 
346
 
            bzrlib.repository.CommitBuilder)
 
341
            repository.CommitBuilder)
 
342
 
 
343
    def test_generate_revision_history(self):
 
344
        """Create a fake revision history easily."""
 
345
        tree = self.make_branch_and_tree('.')
 
346
        rev1 = tree.commit('foo')
 
347
        orig_history = tree.branch.revision_history()
 
348
        rev2 = tree.commit('bar', allow_pointless=True)
 
349
        tree.branch.generate_revision_history(rev1)
 
350
        self.assertEqual(orig_history, tree.branch.revision_history())
347
351
 
348
352
 
349
353
class ChrootedTests(TestCaseWithBranch):
370
374
        branch, relpath = Branch.open_containing(self.get_readonly_url('g/p/q'))
371
375
        self.assertEqual('g/p/q', relpath)
372
376
        
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
377
 
392
378
class InstrumentedTransaction(object):
393
379
 
507
493
        self.assertEqual(None, self.get_branch().get_push_location())
508
494
 
509
495
    def test_get_push_location_exact(self):
510
 
        from bzrlib.config import (branches_config_filename,
 
496
        from bzrlib.config import (locations_config_filename,
511
497
                                   ensure_config_dir_exists)
512
498
        ensure_config_dir_exists()
513
 
        fn = branches_config_filename()
 
499
        fn = locations_config_filename()
514
500
        print >> open(fn, 'wt'), ("[%s]\n"
515
501
                                  "push_location=foo" %
516
502
                                  self.get_branch().base[:-1])
517
503
        self.assertEqual("foo", self.get_branch().get_push_location())
518
504
 
519
505
    def test_set_push_location(self):
520
 
        from bzrlib.config import (branches_config_filename,
 
506
        from bzrlib.config import (locations_config_filename,
521
507
                                   ensure_config_dir_exists)
522
508
        ensure_config_dir_exists()
523
 
        fn = branches_config_filename()
 
509
        fn = locations_config_filename()
524
510
        self.get_branch().set_push_location('foo')
525
511
        self.assertFileEqual("[%s]\n"
526
512
                             "push_location = foo" % self.get_branch().base[:-1],
544
530
        t = get_transport(self.get_url())
545
531
        readonly_t = get_transport(self.get_readonly_url())
546
532
        made_branch = self.make_branch('.')
547
 
        self.failUnless(isinstance(made_branch, bzrlib.branch.Branch))
 
533
        self.failUnless(isinstance(made_branch, branch.Branch))
548
534
 
549
535
        # find it via bzrdir opening:
550
536
        opened_control = bzrdir.BzrDir.open(readonly_t.base)
555
541
                        self.branch_format.__class__))
556
542
 
557
543
        # find it via Branch.open
558
 
        opened_branch = bzrlib.branch.Branch.open(readonly_t.base)
 
544
        opened_branch = branch.Branch.open(readonly_t.base)
559
545
        self.failUnless(isinstance(opened_branch, made_branch.__class__))
560
546
        self.assertEqual(made_branch._format.__class__,
561
547
                         opened_branch._format.__class__)
565
551
        except NotImplementedError:
566
552
            return
567
553
        self.assertEqual(self.branch_format,
568
 
                         bzrlib.branch.BranchFormat.find_format(opened_control))
 
554
                         branch.BranchFormat.find_format(opened_control))