~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_whitebox.py

Merge from integration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import os
2
2
import unittest
3
3
 
4
 
from bzrlib.selftest import TestCaseInTempDir, TestCase
 
4
from bzrlib.tests import TestCaseInTempDir, TestCase
5
5
from bzrlib.branch import ScratchBranch, Branch
6
 
from bzrlib.errors import NotBranchError
 
6
from bzrlib.errors import PathNotChild
 
7
from bzrlib.osutils import relpath, pathjoin, abspath, realpath
7
8
 
8
9
 
9
10
class TestBranch(TestCaseInTempDir):
11
12
    def test_no_changes(self):
12
13
        from bzrlib.errors import PointlessCommit
13
14
        
14
 
        b = Branch.initialize('.')
 
15
        b = Branch.initialize(u'.')
15
16
 
16
17
        self.build_tree(['hello.txt'])
17
18
 
41
42
 
42
43
    def test_rename_dirs(self):
43
44
        """Test renaming directories and the files within them."""
44
 
        b = Branch.initialize('.')
 
45
        b = Branch.initialize(u'.')
45
46
        self.build_tree(['dir/', 'dir/sub/', 'dir/sub/file'])
46
47
        b.working_tree().add(['dir', 'dir/sub', 'dir/sub/file'])
47
48
 
76
77
        job: given a path (either relative to cwd or absolute), work out
77
78
        if it is inside a branch and return the path relative to the base.
78
79
        """
79
 
        from bzrlib.osutils import relpath
80
80
        import tempfile, shutil
81
81
        
82
82
        savedir = os.getcwdu()
83
83
        dtmp = tempfile.mkdtemp()
84
84
        # On Mac OSX, /tmp actually expands to /private/tmp
85
 
        dtmp = os.path.realpath(dtmp)
 
85
        dtmp = realpath(dtmp)
86
86
 
87
87
        def rp(p):
88
88
            return relpath(dtmp, p)
89
89
        
90
90
        try:
91
91
            # check paths inside dtmp while standing outside it
92
 
            self.assertEqual(rp(os.path.join(dtmp, 'foo')), 'foo')
 
92
            self.assertEqual(rp(pathjoin(dtmp, 'foo')), 'foo')
93
93
 
94
94
            # root = nothing
95
95
            self.assertEqual(rp(dtmp), '')
96
96
 
97
 
            self.assertRaises(NotBranchError,
 
97
            self.assertRaises(PathNotChild,
98
98
                              rp,
99
99
                              '/etc')
100
100
 
101
101
            # now some near-miss operations -- note that
102
102
            # os.path.commonprefix gets these wrong!
103
 
            self.assertRaises(NotBranchError,
 
103
            self.assertRaises(PathNotChild,
104
104
                              rp,
105
105
                              dtmp.rstrip('\\/') + '2')
106
106
 
107
 
            self.assertRaises(NotBranchError,
 
107
            self.assertRaises(PathNotChild,
108
108
                              rp,
109
109
                              dtmp.rstrip('\\/') + '2/foo')
110
110
 
112
112
            # directory, or nearby
113
113
            os.chdir(dtmp)
114
114
 
115
 
            FOO_BAR_QUUX = os.path.join('foo', 'bar', 'quux')
116
 
            self.assertEqual(rp('foo/bar/quux'), FOO_BAR_QUUX)
 
115
            self.assertEqual(rp('foo/bar/quux'), 'foo/bar/quux')
117
116
 
118
117
            self.assertEqual(rp('foo'), 'foo')
119
118
 
120
119
            self.assertEqual(rp('./foo'), 'foo')
121
120
 
122
 
            self.assertEqual(rp(os.path.abspath('foo')), 'foo')
 
121
            self.assertEqual(rp(abspath('foo')), 'foo')
123
122
 
124
 
            self.assertRaises(NotBranchError,
 
123
            self.assertRaises(PathNotChild,
125
124
                              rp, '../foo')
126
125
 
127
126
        finally: