6
from bzrlib.selftest import InTempDir, TestBase
7
from bzrlib.branch import ScratchBranch, Branch
8
from bzrlib.errors import NotBranchError
11
class RenameDirs(InTempDir):
12
"""Test renaming directories and the files within them."""
14
from bzrlib.commit import commit
16
b = Branch('.', init=True)
17
self.build_tree(['dir/', 'dir/sub/', 'dir/sub/file'])
18
b.add(['dir', 'dir/sub', 'dir/sub/file'])
20
b.commit('create initial state')
22
# TODO: lift out to a test helper that checks the shape of
25
revid = b.revision_history()[0]
26
self.log('first revision_id is {%s}' % revid)
28
inv = b.get_revision_inventory(revid)
29
self.log('contents of inventory: %r' % inv.entries())
31
self.check_inventory_shape(inv,
32
['dir', 'dir/sub', 'dir/sub/file'])
37
class BranchPathTestCase(TestBase):
38
"""test for branch path lookups
40
Branch.relpath and bzrlib.branch._relpath do a simple but subtle
41
job: given a path (either relative to cwd or absolute), work out
42
if it is inside a branch and return the path relative to the base.
46
from bzrlib.branch import _relpath
47
import tempfile, shutil
49
savedir = os.getcwdu()
50
dtmp = tempfile.mkdtemp()
53
return _relpath(dtmp, p)
56
# check paths inside dtmp while standing outside it
57
self.assertEqual(rp(os.path.join(dtmp, 'foo')), 'foo')
60
self.assertEqual(rp(dtmp), '')
62
self.assertRaises(NotBranchError,
66
# now some near-miss operations -- note that
67
# os.path.commonprefix gets these wrong!
68
self.assertRaises(NotBranchError,
70
dtmp.rstrip('\\/') + '2')
72
self.assertRaises(NotBranchError,
74
dtmp.rstrip('\\/') + '2/foo')
76
# now operations based on relpath of files in current
77
# directory, or nearby
80
self.assertEqual(rp('foo/bar/quux'), 'foo/bar/quux')
82
self.assertEqual(rp('foo'), 'foo')
84
self.assertEqual(rp('./foo'), 'foo')
86
self.assertEqual(rp(os.path.abspath('foo')), 'foo')
88
self.assertRaises(NotBranchError,