3
from bzrlib.branch import ScratchBranch
4
from bzrlib.errors import NotBranchError
5
from unittest import TestCase
8
def Reporter(TestResult):
9
def startTest(self, test):
10
super(Reporter, self).startTest(test)
13
def stopTest(self, test):
16
class BranchPathTestCase(TestCase):
17
"""test for branch path lookups
19
Branch.relpath and bzrlib.branch._relpath do a simple but subtle
20
job: given a path (either relative to cwd or absolute), work out
21
if it is inside a branch and return the path relative to the base.
25
from bzrlib.branch import _relpath
26
import tempfile, shutil
28
savedir = os.getcwdu()
29
dtmp = tempfile.mkdtemp()
32
return _relpath(dtmp, p)
35
# check paths inside dtmp while standing outside it
36
self.assertEqual(rp(os.path.join(dtmp, 'foo')), 'foo')
39
self.assertEqual(rp(dtmp), '')
41
self.assertRaises(NotBranchError,
45
# now some near-miss operations -- note that
46
# os.path.commonprefix gets these wrong!
47
self.assertRaises(NotBranchError,
49
dtmp.rstrip('\\/') + '2')
51
self.assertRaises(NotBranchError,
53
dtmp.rstrip('\\/') + '2/foo')
55
# now operations based on relpath of files in current
56
# directory, or nearby
59
self.assertEqual(rp('foo/bar/quux'), 'foo/bar/quux')
61
self.assertEqual(rp('foo'), 'foo')
63
self.assertEqual(rp('./foo'), 'foo')
65
self.assertEqual(rp(os.path.abspath('foo')), 'foo')
67
self.assertRaises(NotBranchError,
76
if __name__ == '__main__':