~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 08:40:35 UTC
  • mto: (1594.2.4 integration)
  • mto: This revision was merged to the branch mainline in revision 1596.
  • Revision ID: robertc@robertcollins.net-20060301084035-ce00abd11fe4da31
Change weave store to be a versioned store, using WeaveFiles which maintain integrity without needing explicit 'put' operations.

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)