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.
19
import tempfile, shutil
21
savedir = os.getcwdu()
22
dtmp = tempfile.mkdtemp()
23
# On Mac OSX, /tmp actually expands to /private/tmp
27
return relpath(dtmp, p)
30
# check paths inside dtmp while standing outside it
31
self.assertEqual(rp(pathjoin(dtmp, 'foo')), 'foo')
34
self.assertEqual(rp(dtmp), '')
36
self.assertRaises(PathNotChild,
40
# now some near-miss operations -- note that
41
# os.path.commonprefix gets these wrong!
42
self.assertRaises(PathNotChild,
44
dtmp.rstrip('\\/') + '2')
46
self.assertRaises(PathNotChild,
48
dtmp.rstrip('\\/') + '2/foo')
50
# now operations based on relpath of files in current
51
# directory, or nearby
54
self.assertEqual(rp('foo/bar/quux'), 'foo/bar/quux')
56
self.assertEqual(rp('foo'), 'foo')
58
self.assertEqual(rp('./foo'), 'foo')
60
self.assertEqual(rp(abspath('foo')), 'foo')
62
self.assertRaises(PathNotChild,