/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/test_bzrdir.py

  • Committer: Robert Collins
  • Date: 2008-02-13 03:30:01 UTC
  • mfrom: (3221 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3224.
  • Revision ID: robertc@robertcollins.net-20080213033001-rw70ul0zb02ph856
Merge to fix conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
import os.path
23
23
from StringIO import StringIO
 
24
import subprocess
 
25
import sys
24
26
 
25
27
from bzrlib import (
26
28
    bzrdir,
29
31
    repository,
30
32
    symbol_versioning,
31
33
    urlutils,
 
34
    win32utils,
32
35
    workingtree,
33
36
    )
34
37
import bzrlib.branch
42
45
from bzrlib.tests import (
43
46
    TestCase,
44
47
    TestCaseWithTransport,
 
48
    TestSkipped,
45
49
    test_sftp_transport
46
50
    )
47
 
from bzrlib.tests.HttpServer import HttpServer
48
 
from bzrlib.tests.HTTPTestUtil import (
 
51
from bzrlib.tests.http_server import HttpServer
 
52
from bzrlib.tests.http_utils import (
49
53
    TestCaseWithTwoWebservers,
50
54
    HTTPServerRedirecting,
51
55
    )
505
509
                         local_branch_path(branch))
506
510
        self.assertEqual('', relpath)
507
511
 
 
512
    def test_open_tree_or_branch(self):
 
513
        def local_branch_path(branch):
 
514
             return os.path.realpath(
 
515
                urlutils.local_path_from_url(branch.base))
 
516
 
 
517
        self.make_branch_and_tree('topdir')
 
518
        tree, branch = bzrdir.BzrDir.open_tree_or_branch('topdir')
 
519
        self.assertEqual(os.path.realpath('topdir'),
 
520
                         os.path.realpath(tree.basedir))
 
521
        self.assertEqual(os.path.realpath('topdir'),
 
522
                         local_branch_path(branch))
 
523
        self.assertIs(tree.bzrdir, branch.bzrdir)
 
524
        # opening from non-local should not return the tree
 
525
        tree, branch = bzrdir.BzrDir.open_tree_or_branch(
 
526
            self.get_readonly_url('topdir'))
 
527
        self.assertEqual(None, tree)
 
528
        # without a tree:
 
529
        self.make_branch('topdir/foo')
 
530
        tree, branch = bzrdir.BzrDir.open_tree_or_branch('topdir/foo')
 
531
        self.assertIs(tree, None)
 
532
        self.assertEqual(os.path.realpath('topdir/foo'),
 
533
                         local_branch_path(branch))
 
534
 
508
535
    def test_open_from_transport(self):
509
536
        # transport pointing at bzrdir should give a bzrdir with root transport
510
537
        # set to the given transport
564
591
        self.failUnlessExists('repo/tree2/subtree')
565
592
        self.failIfExists('repo/tree2/subtree/file')
566
593
 
 
594
    def make_foo_bar_baz(self):
 
595
        foo = bzrdir.BzrDir.create_branch_convenience('foo').bzrdir
 
596
        bar = self.make_branch('foo/bar').bzrdir
 
597
        baz = self.make_branch('baz').bzrdir
 
598
        return foo, bar, baz
 
599
 
 
600
    def test_find_bzrdirs(self):
 
601
        foo, bar, baz = self.make_foo_bar_baz()
 
602
        transport = get_transport(self.get_url())
 
603
        self.assertEqualBzrdirs([baz, foo, bar],
 
604
                                bzrdir.BzrDir.find_bzrdirs(transport))
 
605
 
 
606
    def test_find_bzrdirs_list_current(self):
 
607
        def list_current(transport):
 
608
            return [s for s in transport.list_dir('') if s != 'baz']
 
609
 
 
610
        foo, bar, baz = self.make_foo_bar_baz()
 
611
        transport = get_transport(self.get_url())
 
612
        self.assertEqualBzrdirs([foo, bar],
 
613
                                bzrdir.BzrDir.find_bzrdirs(transport,
 
614
                                    list_current=list_current))
 
615
 
 
616
 
 
617
    def test_find_bzrdirs_evaluate(self):
 
618
        def evaluate(bzrdir):
 
619
            try:
 
620
                repo = bzrdir.open_repository()
 
621
            except NoRepositoryPresent:
 
622
                return True, bzrdir.root_transport.base
 
623
            else:
 
624
                return False, bzrdir.root_transport.base
 
625
 
 
626
        foo, bar, baz = self.make_foo_bar_baz()
 
627
        transport = get_transport(self.get_url())
 
628
        self.assertEqual([baz.root_transport.base, foo.root_transport.base],
 
629
                         list(bzrdir.BzrDir.find_bzrdirs(transport,
 
630
                                                         evaluate=evaluate)))
 
631
 
 
632
    def assertEqualBzrdirs(self, first, second):
 
633
        first = list(first)
 
634
        second = list(second)
 
635
        self.assertEqual(len(first), len(second))
 
636
        for x, y in zip(first, second):
 
637
            self.assertEqual(x.root_transport.base, y.root_transport.base)
 
638
 
 
639
    def test_find_branches(self):
 
640
        root = self.make_repository('', shared=True)
 
641
        foo, bar, baz = self.make_foo_bar_baz()
 
642
        qux = self.make_bzrdir('foo/qux')
 
643
        transport = get_transport(self.get_url())
 
644
        branches = bzrdir.BzrDir.find_branches(transport)
 
645
        self.assertEqual(baz.root_transport.base, branches[0].base)
 
646
        self.assertEqual(foo.root_transport.base, branches[1].base)
 
647
        self.assertEqual(bar.root_transport.base, branches[2].base)
 
648
 
 
649
        # ensure this works without a top-level repo
 
650
        branches = bzrdir.BzrDir.find_branches(transport.clone('foo'))
 
651
        self.assertEqual(foo.root_transport.base, branches[0].base)
 
652
        self.assertEqual(bar.root_transport.base, branches[1].base)
 
653
 
567
654
 
568
655
class TestMeta1DirFormat(TestCaseWithTransport):
569
656
    """Tests specific to the meta1 dir format."""
870
957
    """Tests redirections for pycurl implementation"""
871
958
 
872
959
    _qualifier = 'pycurl'
 
960
 
 
961
 
 
962
class TestDotBzrHidden(TestCaseWithTransport):
 
963
 
 
964
    ls = ['ls']
 
965
    if sys.platform == 'win32':
 
966
        ls = [os.environ['COMSPEC'], '/C', 'dir', '/B']
 
967
 
 
968
    def get_ls(self):
 
969
        f = subprocess.Popen(self.ls, stdout=subprocess.PIPE,
 
970
            stderr=subprocess.PIPE)
 
971
        out, err = f.communicate()
 
972
        self.assertEqual(0, f.returncode, 'Calling %s failed: %s'
 
973
                         % (self.ls, err))
 
974
        return out.splitlines()
 
975
 
 
976
    def test_dot_bzr_hidden(self):
 
977
        if sys.platform == 'win32' and not win32utils.has_win32file:
 
978
            raise TestSkipped('unable to make file hidden without pywin32 library')
 
979
        b = bzrdir.BzrDir.create('.')
 
980
        self.build_tree(['a'])
 
981
        self.assertEquals(['a'], self.get_ls())
 
982
 
 
983
    def test_dot_bzr_hidden_with_url(self):
 
984
        if sys.platform == 'win32' and not win32utils.has_win32file:
 
985
            raise TestSkipped('unable to make file hidden without pywin32 library')
 
986
        b = bzrdir.BzrDir.create(urlutils.local_path_to_url('.'))
 
987
        self.build_tree(['a'])
 
988
        self.assertEquals(['a'], self.get_ls())