~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

  • Committer: Ian Clatworthy
  • Date: 2008-07-04 03:29:14 UTC
  • mfrom: (3015.3.59 check)
  • mto: This revision was merged to the branch mainline in revision 3521.
  • Revision ID: ian.clatworthy@canonical.com-20080704032914-ymz2feecr4qxe160
Fix check to understand split up .bzr format (Daniel Mark Watkins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
For interface contract tests, see tests/bzr_dir_implementations.
20
20
"""
21
21
 
 
22
import os
22
23
import os.path
23
24
from StringIO import StringIO
24
25
import subprocess
436
437
        if not self.vfs_transport_factory == MemoryServer:
437
438
            self.transport_readonly_server = HttpServer
438
439
 
 
440
    def local_branch_path(self, branch):
 
441
         return os.path.realpath(urlutils.local_path_from_url(branch.base))
 
442
 
439
443
    def test_open_containing(self):
440
444
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing,
441
445
                          self.get_readonly_url(''))
447
451
        branch, relpath = bzrdir.BzrDir.open_containing(self.get_readonly_url('g/p/q'))
448
452
        self.assertEqual('g/p/q', relpath)
449
453
 
 
454
    def test_open_containing_tree_branch_or_repository_empty(self):
 
455
        self.assertRaises(errors.NotBranchError,
 
456
            bzrdir.BzrDir.open_containing_tree_branch_or_repository,
 
457
            self.get_readonly_url(''))
 
458
 
 
459
    def test_open_containing_tree_branch_or_repository_all(self):
 
460
        self.make_branch_and_tree('topdir')
 
461
        tree, branch, repo, relpath = \
 
462
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
 
463
                'topdir/foo')
 
464
        self.assertEqual(os.path.realpath('topdir'),
 
465
                         os.path.realpath(tree.basedir))
 
466
        self.assertEqual(os.path.realpath('topdir'),
 
467
                         self.local_branch_path(branch))
 
468
        self.assertEqual(
 
469
            os.path.realpath(os.path.join('topdir', '.bzr', 'repository')),
 
470
            repo.bzrdir.transport.local_abspath('repository'))
 
471
        self.assertEqual(relpath, 'foo')
 
472
 
 
473
    def test_open_containing_tree_branch_or_repository_no_tree(self):
 
474
        self.make_branch('branch')
 
475
        tree, branch, repo, relpath = \
 
476
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
 
477
                'branch/foo')
 
478
        self.assertEqual(tree, None)
 
479
        self.assertEqual(os.path.realpath('branch'),
 
480
                         self.local_branch_path(branch))
 
481
        self.assertEqual(
 
482
            os.path.realpath(os.path.join('branch', '.bzr', 'repository')),
 
483
            repo.bzrdir.transport.local_abspath('repository'))
 
484
        self.assertEqual(relpath, 'foo')
 
485
 
 
486
    def test_open_containing_tree_branch_or_repository_repo(self):
 
487
        self.make_repository('repo')
 
488
        tree, branch, repo, relpath = \
 
489
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
 
490
                'repo')
 
491
        self.assertEqual(tree, None)
 
492
        self.assertEqual(branch, None)
 
493
        self.assertEqual(
 
494
            os.path.realpath(os.path.join('repo', '.bzr', 'repository')),
 
495
            repo.bzrdir.transport.local_abspath('repository'))
 
496
        self.assertEqual(relpath, '')
 
497
 
 
498
    def test_open_containing_tree_branch_or_repository_shared_repo(self):
 
499
        self.make_repository('shared', shared=True)
 
500
        bzrdir.BzrDir.create_branch_convenience('shared/branch',
 
501
                                                force_new_tree=False)
 
502
        tree, branch, repo, relpath = \
 
503
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
 
504
                'shared/branch')
 
505
        self.assertEqual(tree, None)
 
506
        self.assertEqual(os.path.realpath('shared/branch'),
 
507
                         self.local_branch_path(branch))
 
508
        self.assertEqual(
 
509
            os.path.realpath(os.path.join('shared', '.bzr', 'repository')),
 
510
            repo.bzrdir.transport.local_abspath('repository'))
 
511
        self.assertEqual(relpath, '')
 
512
 
 
513
    def test_open_containing_tree_branch_or_repository_branch_subdir(self):
 
514
        self.make_branch_and_tree('foo')
 
515
        self.build_tree(['foo/bar/'])
 
516
        tree, branch, repo, relpath = \
 
517
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
 
518
                'foo/bar')
 
519
        self.assertEqual(os.path.realpath('foo'),
 
520
                         os.path.realpath(tree.basedir))
 
521
        self.assertEqual(os.path.realpath('foo'),
 
522
                         self.local_branch_path(branch))
 
523
        self.assertEqual(
 
524
            os.path.realpath(os.path.join('foo', '.bzr', 'repository')),
 
525
            repo.bzrdir.transport.local_abspath('repository'))
 
526
        self.assertEqual(relpath, 'bar')
 
527
 
 
528
    def test_open_containing_tree_branch_or_repository_repo_subdir(self):
 
529
        self.make_repository('bar')
 
530
        self.build_tree(['bar/baz/'])
 
531
        tree, branch, repo, relpath = \
 
532
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
 
533
                'bar/baz')
 
534
        self.assertEqual(tree, None)
 
535
        self.assertEqual(branch, None)
 
536
        self.assertEqual(
 
537
            os.path.realpath(os.path.join('bar', '.bzr', 'repository')),
 
538
            repo.bzrdir.transport.local_abspath('repository'))
 
539
        self.assertEqual(relpath, 'baz')
 
540
 
450
541
    def test_open_containing_from_transport(self):
451
542
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing_from_transport,
452
543
                          get_transport(self.get_readonly_url('')))
461
552
        self.assertEqual('g/p/q', relpath)
462
553
 
463
554
    def test_open_containing_tree_or_branch(self):
464
 
        def local_branch_path(branch):
465
 
             return os.path.realpath(
466
 
                urlutils.local_path_from_url(branch.base))
467
 
 
468
555
        self.make_branch_and_tree('topdir')
469
556
        tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
470
557
            'topdir/foo')
471
558
        self.assertEqual(os.path.realpath('topdir'),
472
559
                         os.path.realpath(tree.basedir))
473
560
        self.assertEqual(os.path.realpath('topdir'),
474
 
                         local_branch_path(branch))
 
561
                         self.local_branch_path(branch))
475
562
        self.assertIs(tree.bzrdir, branch.bzrdir)
476
563
        self.assertEqual('foo', relpath)
477
564
        # opening from non-local should not return the tree
485
572
            'topdir/foo')
486
573
        self.assertIs(tree, None)
487
574
        self.assertEqual(os.path.realpath('topdir/foo'),
488
 
                         local_branch_path(branch))
 
575
                         self.local_branch_path(branch))
489
576
        self.assertEqual('', relpath)
490
577
 
491
578
    def test_open_tree_or_branch(self):
492
 
        def local_branch_path(branch):
493
 
             return os.path.realpath(
494
 
                urlutils.local_path_from_url(branch.base))
495
 
 
496
579
        self.make_branch_and_tree('topdir')
497
580
        tree, branch = bzrdir.BzrDir.open_tree_or_branch('topdir')
498
581
        self.assertEqual(os.path.realpath('topdir'),
499
582
                         os.path.realpath(tree.basedir))
500
583
        self.assertEqual(os.path.realpath('topdir'),
501
 
                         local_branch_path(branch))
 
584
                         self.local_branch_path(branch))
502
585
        self.assertIs(tree.bzrdir, branch.bzrdir)
503
586
        # opening from non-local should not return the tree
504
587
        tree, branch = bzrdir.BzrDir.open_tree_or_branch(
509
592
        tree, branch = bzrdir.BzrDir.open_tree_or_branch('topdir/foo')
510
593
        self.assertIs(tree, None)
511
594
        self.assertEqual(os.path.realpath('topdir/foo'),
512
 
                         local_branch_path(branch))
 
595
                         self.local_branch_path(branch))
513
596
 
514
597
    def test_open_from_transport(self):
515
598
        # transport pointing at bzrdir should give a bzrdir with root transport