3
from bzrlib.branch import ScratchBranch
4
from bzrlib.errors import NotBranchError
5
from unittest import TestCase
8
class BranchPathTestCase(TestCase):
9
"""test for branch path lookups
11
Branch.relpath and bzrlib.branch._relpath do a simple but subtle
12
job: given a path (either relative to cwd or absolute), work out
13
if it is inside a branch and return the path relative to the base.
17
from bzrlib.branch import _relpath
18
import tempfile, shutil
20
savedir = os.getcwdu()
21
dtmp = tempfile.mkdtemp()
24
return _relpath(dtmp, p)
27
# check paths inside dtmp while standing outside it
28
self.assertEqual(rp(os.path.join(dtmp, 'foo')), 'foo')
31
self.assertEqual(rp(dtmp), '')
33
self.assertRaises(NotBranchError,
37
# now some near-miss operations -- note that
38
# os.path.commonprefix gets these wrong!
39
self.assertRaises(NotBranchError,
41
dtmp.rstrip('\\/') + '2')
43
self.assertRaises(NotBranchError,
45
dtmp.rstrip('\\/') + '2/foo')
47
# now operations based on relpath of files in current
48
# directory, or nearby
51
self.assertEqual(rp('foo/bar/quux'), 'foo/bar/quux')
53
self.assertEqual(rp('foo'), 'foo')
55
self.assertEqual(rp('./foo'), 'foo')
57
self.assertEqual(rp(os.path.abspath('foo')), 'foo')
59
self.assertRaises(NotBranchError,
67
if __name__ == '__main__':