1
# Copyright (C) 2005, 2006 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
from bzrlib.tests import TestCaseWithTransport, TestCase
24
from bzrlib.branch import Branch
25
from bzrlib.errors import PathNotChild
26
from bzrlib.osutils import relpath, pathjoin, abspath, realpath
29
class MoreTests(TestCaseWithTransport):
31
def test_relpath(self):
32
"""test for branch path lookups
34
bzrlib.osutils._relpath do a simple but subtle
35
job: given a path (either relative to cwd or absolute), work out
36
if it is inside a branch and return the path relative to the base.
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'])
34
b.rename_one('dir', 'newdir')
36
self.check_inventory_shape(b.inventory,
37
['newdir', 'newdir/sub', 'newdir/sub/file'])
39
b.rename_one('newdir/sub', 'newdir/newsub')
40
self.check_inventory_shape(b.inventory,
41
['newdir', 'newdir/newsub',
42
'newdir/newsub/file'])
47
class BranchPathTestCase(TestBase):
48
"""test for branch path lookups
50
Branch.relpath and bzrlib.branch._relpath do a simple but subtle
51
job: given a path (either relative to cwd or absolute), work out
52
if it is inside a branch and return the path relative to the base.
56
from bzrlib.branch import _relpath
57
import tempfile, shutil
40
59
savedir = os.getcwdu()
41
dtmp = osutils.mkdtemp()
42
# On Mac OSX, /tmp actually expands to /private/tmp
60
dtmp = tempfile.mkdtemp()
46
return relpath(dtmp, p)
63
return _relpath(dtmp, p)
49
66
# check paths inside dtmp while standing outside it
50
self.assertEqual(rp(pathjoin(dtmp, 'foo')), 'foo')
67
self.assertEqual(rp(os.path.join(dtmp, 'foo')), 'foo')
53
70
self.assertEqual(rp(dtmp), '')
55
self.assertRaises(PathNotChild,
72
self.assertRaises(NotBranchError,
59
76
# now some near-miss operations -- note that
60
77
# os.path.commonprefix gets these wrong!
61
self.assertRaises(PathNotChild,
78
self.assertRaises(NotBranchError,
63
80
dtmp.rstrip('\\/') + '2')
65
self.assertRaises(PathNotChild,
82
self.assertRaises(NotBranchError,
67
84
dtmp.rstrip('\\/') + '2/foo')