4
from bzrlib.tests import TestCaseWithTransport, TestCase
5
from bzrlib.branch import ScratchBranch, Branch
6
from bzrlib.errors import PathNotChild
7
from bzrlib.osutils import relpath, pathjoin, abspath, realpath
10
class MoreTests(TestCaseWithTransport):
12
def test_relpath(self):
13
"""test for branch path lookups
15
bzrlib.osutils._relpath do a simple but subtle
16
job: given a path (either relative to cwd or absolute), work out
17
if it is inside a branch and return the path relative to the base.
20
from bzrlib.osutils import rmtree
22
savedir = os.getcwdu()
23
dtmp = tempfile.mkdtemp()
24
# On Mac OSX, /tmp actually expands to /private/tmp
28
return relpath(dtmp, p)
31
# check paths inside dtmp while standing outside it
32
self.assertEqual(rp(pathjoin(dtmp, 'foo')), 'foo')
35
self.assertEqual(rp(dtmp), '')
37
self.assertRaises(PathNotChild,
41
# now some near-miss operations -- note that
42
# os.path.commonprefix gets these wrong!
43
self.assertRaises(PathNotChild,
45
dtmp.rstrip('\\/') + '2')
47
self.assertRaises(PathNotChild,
49
dtmp.rstrip('\\/') + '2/foo')
51
# now operations based on relpath of files in current
52
# directory, or nearby
55
self.assertEqual(rp('foo/bar/quux'), 'foo/bar/quux')
57
self.assertEqual(rp('foo'), 'foo')
59
self.assertEqual(rp('./foo'), 'foo')
61
self.assertEqual(rp(abspath('foo')), 'foo')
63
self.assertRaises(PathNotChild,