~bzr-pqm/bzr/bzr.dev

768 by Martin Pool
- start some tests for directory renames
1
import os
2
import unittest
3
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
4
from bzrlib.tests import TestCaseWithTransport, TestCase
768 by Martin Pool
- start some tests for directory renames
5
from bzrlib.branch import ScratchBranch, Branch
1185.31.42 by John Arbash Meinel
Updated whitebox text for new PathNotChild exception
6
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)
7
from bzrlib.osutils import relpath, pathjoin, abspath, realpath
778 by Martin Pool
- simple revert of text files
8
9
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
10
class MoreTests(TestCaseWithTransport):
771 by Martin Pool
- more tests of directory renames
11
1102 by Martin Pool
- merge test refactoring from robertc
12
    def test_relpath(self):
13
        """test for branch path lookups
14
    
1457.1.2 by Robert Collins
move branch._relpath into osutils as relpath
15
        bzrlib.osutils._relpath do a simple but subtle
1102 by Martin Pool
- merge test refactoring from robertc
16
        job: given a path (either relative to cwd or absolute), work out
17
        if it is inside a branch and return the path relative to the base.
18
        """
1692.7.6 by Martin Pool
[patch] force deletion of trees containing readonly files (alexander)
19
        import tempfile
20
        from bzrlib.osutils import rmtree
601 by Martin Pool
- whitebox tests for branch path handling
21
        
22
        savedir = os.getcwdu()
23
        dtmp = tempfile.mkdtemp()
907.1.7 by John Arbash Meinel
Fixed test failure on Mac OSX.
24
        # 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)
25
        dtmp = realpath(dtmp)
601 by Martin Pool
- whitebox tests for branch path handling
26
27
        def rp(p):
1457.1.2 by Robert Collins
move branch._relpath into osutils as relpath
28
            return relpath(dtmp, p)
601 by Martin Pool
- whitebox tests for branch path handling
29
        
30
        try:
31
            # check paths inside dtmp while standing outside it
1185.31.33 by John Arbash Meinel
A couple more path.join statements needed changing.
32
            self.assertEqual(rp(pathjoin(dtmp, 'foo')), 'foo')
601 by Martin Pool
- whitebox tests for branch path handling
33
34
            # root = nothing
35
            self.assertEqual(rp(dtmp), '')
36
1185.31.42 by John Arbash Meinel
Updated whitebox text for new PathNotChild exception
37
            self.assertRaises(PathNotChild,
601 by Martin Pool
- whitebox tests for branch path handling
38
                              rp,
39
                              '/etc')
40
41
            # now some near-miss operations -- note that
42
            # os.path.commonprefix gets these wrong!
1185.31.42 by John Arbash Meinel
Updated whitebox text for new PathNotChild exception
43
            self.assertRaises(PathNotChild,
601 by Martin Pool
- whitebox tests for branch path handling
44
                              rp,
45
                              dtmp.rstrip('\\/') + '2')
46
1185.31.42 by John Arbash Meinel
Updated whitebox text for new PathNotChild exception
47
            self.assertRaises(PathNotChild,
601 by Martin Pool
- whitebox tests for branch path handling
48
                              rp,
49
                              dtmp.rstrip('\\/') + '2/foo')
50
51
            # now operations based on relpath of files in current
52
            # directory, or nearby
53
            os.chdir(dtmp)
54
1185.31.33 by John Arbash Meinel
A couple more path.join statements needed changing.
55
            self.assertEqual(rp('foo/bar/quux'), 'foo/bar/quux')
601 by Martin Pool
- whitebox tests for branch path handling
56
57
            self.assertEqual(rp('foo'), 'foo')
58
59
            self.assertEqual(rp('./foo'), 'foo')
60
1185.31.37 by John Arbash Meinel
Switched os.path.abspath and os.path.realpath to osutils.* (still passes on cygwin)
61
            self.assertEqual(rp(abspath('foo')), 'foo')
601 by Martin Pool
- whitebox tests for branch path handling
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, '../foo')
65
66
        finally:
67
            os.chdir(savedir)
1692.7.6 by Martin Pool
[patch] force deletion of trees containing readonly files (alexander)
68
            rmtree(dtmp)