/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_whitebox.py

  • Committer: Michael Ellerman
  • Date: 2006-03-09 00:24:48 UTC
  • mto: (1610.1.8 bzr.mbp.integration)
  • mto: This revision was merged to the branch mainline in revision 1616.
  • Revision ID: michael@ellerman.id.au-20060309002448-70cce15e3d605130
Make the "ignore line" in the commit message editor the "right" width, so
that if you make your message that wide it won't wrap in bzr log output.
Just as a visual aid.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os
 
2
import unittest
 
3
 
 
4
from bzrlib.tests import TestCaseWithTransport, TestCase
 
5
from bzrlib.branch import ScratchBranch, Branch
 
6
from bzrlib.errors import PathNotChild
 
7
from bzrlib.osutils import relpath, pathjoin, abspath, realpath
 
8
 
 
9
 
 
10
class MoreTests(TestCaseWithTransport):
 
11
 
 
12
    def test_relpath(self):
 
13
        """test for branch path lookups
 
14
    
 
15
        bzrlib.osutils._relpath do a simple but subtle
 
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
        """
 
19
        import tempfile, shutil
 
20
        
 
21
        savedir = os.getcwdu()
 
22
        dtmp = tempfile.mkdtemp()
 
23
        # On Mac OSX, /tmp actually expands to /private/tmp
 
24
        dtmp = realpath(dtmp)
 
25
 
 
26
        def rp(p):
 
27
            return relpath(dtmp, p)
 
28
        
 
29
        try:
 
30
            # check paths inside dtmp while standing outside it
 
31
            self.assertEqual(rp(pathjoin(dtmp, 'foo')), 'foo')
 
32
 
 
33
            # root = nothing
 
34
            self.assertEqual(rp(dtmp), '')
 
35
 
 
36
            self.assertRaises(PathNotChild,
 
37
                              rp,
 
38
                              '/etc')
 
39
 
 
40
            # now some near-miss operations -- note that
 
41
            # os.path.commonprefix gets these wrong!
 
42
            self.assertRaises(PathNotChild,
 
43
                              rp,
 
44
                              dtmp.rstrip('\\/') + '2')
 
45
 
 
46
            self.assertRaises(PathNotChild,
 
47
                              rp,
 
48
                              dtmp.rstrip('\\/') + '2/foo')
 
49
 
 
50
            # now operations based on relpath of files in current
 
51
            # directory, or nearby
 
52
            os.chdir(dtmp)
 
53
 
 
54
            self.assertEqual(rp('foo/bar/quux'), 'foo/bar/quux')
 
55
 
 
56
            self.assertEqual(rp('foo'), 'foo')
 
57
 
 
58
            self.assertEqual(rp('./foo'), 'foo')
 
59
 
 
60
            self.assertEqual(rp(abspath('foo')), 'foo')
 
61
 
 
62
            self.assertRaises(PathNotChild,
 
63
                              rp, '../foo')
 
64
 
 
65
        finally:
 
66
            os.chdir(savedir)
 
67
            shutil.rmtree(dtmp)