~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_whitebox.py

  • Committer: Robert Collins
  • Date: 2006-03-01 03:26:23 UTC
  • mto: (1594.2.4 integration)
  • mto: This revision was merged to the branch mainline in revision 1596.
  • Revision ID: robertc@robertcollins.net-20060301032623-9d3c073e102f2239
Move WeaveStore down into bzrlib.store.versioned.weave.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /usr/bin/python
2
 
 
3
 
from bzrlib.branch import ScratchBranch
4
 
from bzrlib.errors import NotBranchError
5
 
from unittest import TestCase
6
 
import os, unittest
7
 
 
8
 
class BranchPathTestCase(TestCase):
9
 
    """test for branch path lookups
10
 
 
11
 
    Branch.relpath and bzrlib.branch._relpath do a simple but subtle
12
 
    job: given a path (either relative to cwd or absolute), work out
13
 
    if it is inside a branch and return the path relative to the base.
14
 
    """
 
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
15
14
    
16
 
    def runTest(self):
17
 
        from bzrlib.branch import _relpath
 
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
        """
18
19
        import tempfile, shutil
19
20
        
20
21
        savedir = os.getcwdu()
21
22
        dtmp = tempfile.mkdtemp()
 
23
        # On Mac OSX, /tmp actually expands to /private/tmp
 
24
        dtmp = realpath(dtmp)
22
25
 
23
26
        def rp(p):
24
 
            return _relpath(dtmp, p)
 
27
            return relpath(dtmp, p)
25
28
        
26
29
        try:
27
30
            # check paths inside dtmp while standing outside it
28
 
            self.assertEqual(rp(os.path.join(dtmp, 'foo')), 'foo')
 
31
            self.assertEqual(rp(pathjoin(dtmp, 'foo')), 'foo')
29
32
 
30
33
            # root = nothing
31
34
            self.assertEqual(rp(dtmp), '')
32
35
 
33
 
            self.assertRaises(NotBranchError,
 
36
            self.assertRaises(PathNotChild,
34
37
                              rp,
35
38
                              '/etc')
36
39
 
37
40
            # now some near-miss operations -- note that
38
41
            # os.path.commonprefix gets these wrong!
39
 
            self.assertRaises(NotBranchError,
 
42
            self.assertRaises(PathNotChild,
40
43
                              rp,
41
44
                              dtmp.rstrip('\\/') + '2')
42
45
 
43
 
            self.assertRaises(NotBranchError,
 
46
            self.assertRaises(PathNotChild,
44
47
                              rp,
45
48
                              dtmp.rstrip('\\/') + '2/foo')
46
49
 
54
57
 
55
58
            self.assertEqual(rp('./foo'), 'foo')
56
59
 
57
 
            self.assertEqual(rp(os.path.abspath('foo')), 'foo')
 
60
            self.assertEqual(rp(abspath('foo')), 'foo')
58
61
 
59
 
            self.assertRaises(NotBranchError,
 
62
            self.assertRaises(PathNotChild,
60
63
                              rp, '../foo')
61
64
 
62
65
        finally:
63
66
            os.chdir(savedir)
64
67
            shutil.rmtree(dtmp)
65
 
 
66
 
                              
67
 
if __name__ == '__main__':
68
 
    unittest.main()
69