~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_whitebox.py

  • Committer: Martin Pool
  • Date: 2006-01-06 01:13:05 UTC
  • mfrom: (1534.1.4 integration)
  • Revision ID: mbp@sourcefrog.net-20060106011305-3772285d84b5cbb4
[merge] robertc

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
from bzrlib.tests import TestCaseInTempDir, TestCase
5
5
from bzrlib.branch import ScratchBranch, Branch
6
 
from bzrlib.errors import NotBranchError
 
6
from bzrlib.errors import PathNotChild
 
7
from bzrlib.osutils import relpath, pathjoin, abspath, realpath
7
8
 
8
9
 
9
10
class TestBranch(TestCaseInTempDir):
76
77
        job: given a path (either relative to cwd or absolute), work out
77
78
        if it is inside a branch and return the path relative to the base.
78
79
        """
79
 
        from bzrlib.osutils import relpath
80
80
        import tempfile, shutil
81
81
        
82
82
        savedir = os.getcwdu()
83
83
        dtmp = tempfile.mkdtemp()
84
84
        # On Mac OSX, /tmp actually expands to /private/tmp
85
 
        dtmp = os.path.realpath(dtmp)
 
85
        dtmp = realpath(dtmp)
86
86
 
87
87
        def rp(p):
88
88
            return relpath(dtmp, p)
89
89
        
90
90
        try:
91
91
            # check paths inside dtmp while standing outside it
92
 
            self.assertEqual(rp(os.path.join(dtmp, 'foo')), 'foo')
 
92
            self.assertEqual(rp(pathjoin(dtmp, 'foo')), 'foo')
93
93
 
94
94
            # root = nothing
95
95
            self.assertEqual(rp(dtmp), '')
96
96
 
97
 
            self.assertRaises(NotBranchError,
 
97
            self.assertRaises(PathNotChild,
98
98
                              rp,
99
99
                              '/etc')
100
100
 
101
101
            # now some near-miss operations -- note that
102
102
            # os.path.commonprefix gets these wrong!
103
 
            self.assertRaises(NotBranchError,
 
103
            self.assertRaises(PathNotChild,
104
104
                              rp,
105
105
                              dtmp.rstrip('\\/') + '2')
106
106
 
107
 
            self.assertRaises(NotBranchError,
 
107
            self.assertRaises(PathNotChild,
108
108
                              rp,
109
109
                              dtmp.rstrip('\\/') + '2/foo')
110
110
 
112
112
            # directory, or nearby
113
113
            os.chdir(dtmp)
114
114
 
115
 
            FOO_BAR_QUUX = os.path.join('foo', 'bar', 'quux')
116
 
            self.assertEqual(rp('foo/bar/quux'), FOO_BAR_QUUX)
 
115
            self.assertEqual(rp('foo/bar/quux'), 'foo/bar/quux')
117
116
 
118
117
            self.assertEqual(rp('foo'), 'foo')
119
118
 
120
119
            self.assertEqual(rp('./foo'), 'foo')
121
120
 
122
 
            self.assertEqual(rp(os.path.abspath('foo')), 'foo')
 
121
            self.assertEqual(rp(abspath('foo')), 'foo')
123
122
 
124
 
            self.assertRaises(NotBranchError,
 
123
            self.assertRaises(PathNotChild,
125
124
                              rp, '../foo')
126
125
 
127
126
        finally: