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
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.
79
from bzrlib.osutils import relpath
80
80
import tempfile, shutil
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)
88
88
return relpath(dtmp, p)
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')
95
95
self.assertEqual(rp(dtmp), '')
97
self.assertRaises(NotBranchError,
97
self.assertRaises(PathNotChild,
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,
105
105
dtmp.rstrip('\\/') + '2')
107
self.assertRaises(NotBranchError,
107
self.assertRaises(PathNotChild,
109
109
dtmp.rstrip('\\/') + '2/foo')
112
112
# directory, or nearby
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')
118
117
self.assertEqual(rp('foo'), 'foo')
120
119
self.assertEqual(rp('./foo'), 'foo')
122
self.assertEqual(rp(os.path.abspath('foo')), 'foo')
121
self.assertEqual(rp(abspath('foo')), 'foo')
124
self.assertRaises(NotBranchError,
123
self.assertRaises(PathNotChild,