~bzr-pqm/bzr/bzr.dev

1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
1
# Copyright (C) 2005, 2006 by Canonical Ltd
2
#
1740.6.1 by Martin Pool
Remove Scratch objects used by doctests
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.
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
7
#
1740.6.1 by Martin Pool
Remove Scratch objects used by doctests
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.
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
12
#
1740.6.1 by Martin Pool
Remove Scratch objects used by doctests
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
768 by Martin Pool
- start some tests for directory renames
17
import os
18
import unittest
19
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
20
from bzrlib.tests import TestCaseWithTransport, TestCase
1740.6.1 by Martin Pool
Remove Scratch objects used by doctests
21
from bzrlib.branch import Branch
1185.31.42 by John Arbash Meinel
Updated whitebox text for new PathNotChild exception
22
from bzrlib.errors import PathNotChild
1185.31.37 by John Arbash Meinel
Switched os.path.abspath and os.path.realpath to osutils.* (still passes on cygwin)
23
from bzrlib.osutils import relpath, pathjoin, abspath, realpath
778 by Martin Pool
- simple revert of text files
24
25
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
26
class MoreTests(TestCaseWithTransport):
771 by Martin Pool
- more tests of directory renames
27
1102 by Martin Pool
- merge test refactoring from robertc
28
    def test_relpath(self):
29
        """test for branch path lookups
30
    
1457.1.2 by Robert Collins
move branch._relpath into osutils as relpath
31
        bzrlib.osutils._relpath do a simple but subtle
1102 by Martin Pool
- merge test refactoring from robertc
32
        job: given a path (either relative to cwd or absolute), work out
33
        if it is inside a branch and return the path relative to the base.
34
        """
1692.7.6 by Martin Pool
[patch] force deletion of trees containing readonly files (alexander)
35
        import tempfile
36
        from bzrlib.osutils import rmtree
601 by Martin Pool
- whitebox tests for branch path handling
37
        
38
        savedir = os.getcwdu()
39
        dtmp = tempfile.mkdtemp()
907.1.7 by John Arbash Meinel
Fixed test failure on Mac OSX.
40
        # On Mac OSX, /tmp actually expands to /private/tmp
1185.31.37 by John Arbash Meinel
Switched os.path.abspath and os.path.realpath to osutils.* (still passes on cygwin)
41
        dtmp = realpath(dtmp)
601 by Martin Pool
- whitebox tests for branch path handling
42
43
        def rp(p):
1457.1.2 by Robert Collins
move branch._relpath into osutils as relpath
44
            return relpath(dtmp, p)
601 by Martin Pool
- whitebox tests for branch path handling
45
        
46
        try:
47
            # check paths inside dtmp while standing outside it
1185.31.33 by John Arbash Meinel
A couple more path.join statements needed changing.
48
            self.assertEqual(rp(pathjoin(dtmp, 'foo')), 'foo')
601 by Martin Pool
- whitebox tests for branch path handling
49
50
            # root = nothing
51
            self.assertEqual(rp(dtmp), '')
52
1185.31.42 by John Arbash Meinel
Updated whitebox text for new PathNotChild exception
53
            self.assertRaises(PathNotChild,
601 by Martin Pool
- whitebox tests for branch path handling
54
                              rp,
55
                              '/etc')
56
57
            # now some near-miss operations -- note that
58
            # os.path.commonprefix gets these wrong!
1185.31.42 by John Arbash Meinel
Updated whitebox text for new PathNotChild exception
59
            self.assertRaises(PathNotChild,
601 by Martin Pool
- whitebox tests for branch path handling
60
                              rp,
61
                              dtmp.rstrip('\\/') + '2')
62
1185.31.42 by John Arbash Meinel
Updated whitebox text for new PathNotChild exception
63
            self.assertRaises(PathNotChild,
601 by Martin Pool
- whitebox tests for branch path handling
64
                              rp,
65
                              dtmp.rstrip('\\/') + '2/foo')
66
67
            # now operations based on relpath of files in current
68
            # directory, or nearby
69
            os.chdir(dtmp)
70
1185.31.33 by John Arbash Meinel
A couple more path.join statements needed changing.
71
            self.assertEqual(rp('foo/bar/quux'), 'foo/bar/quux')
601 by Martin Pool
- whitebox tests for branch path handling
72
73
            self.assertEqual(rp('foo'), 'foo')
74
75
            self.assertEqual(rp('./foo'), 'foo')
76
1185.31.37 by John Arbash Meinel
Switched os.path.abspath and os.path.realpath to osutils.* (still passes on cygwin)
77
            self.assertEqual(rp(abspath('foo')), 'foo')
601 by Martin Pool
- whitebox tests for branch path handling
78
1185.31.42 by John Arbash Meinel
Updated whitebox text for new PathNotChild exception
79
            self.assertRaises(PathNotChild,
601 by Martin Pool
- whitebox tests for branch path handling
80
                              rp, '../foo')
81
82
        finally:
83
            os.chdir(savedir)
1692.7.6 by Martin Pool
[patch] force deletion of trees containing readonly files (alexander)
84
            rmtree(dtmp)