/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/whitebox.py

  • Committer: Martin Pool
  • Date: 2005-05-31 03:03:54 UTC
  • Revision ID: mbp@sourcefrog.net-20050531030354-561dbe9ec2862d46
doc

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