~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-01-05 22:30:59 UTC
  • mto: (1534.1.4 integration)
  • mto: This revision was merged to the branch mainline in revision 1536.
  • Revision ID: robertc@robertcollins.net-20060105223059-a8b64f7b47cf12fb
 * bzrlib.osutils.safe_unicode now exists to provide parameter coercion
   for functions that need unicode strings. (Robert Collins)

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):
10
11
 
11
 
    def test_unknowns(self):
12
 
        b = Branch.initialize('.')
13
 
 
14
 
        self.build_tree(['hello.txt',
15
 
                         'hello.txt~'])
16
 
 
17
 
        self.assertEquals(list(b.unknowns()),
18
 
                          ['hello.txt'])
19
 
 
20
12
    def test_no_changes(self):
21
13
        from bzrlib.errors import PointlessCommit
22
14
        
23
 
        b = Branch.initialize('.')
 
15
        b = Branch.initialize(u'.')
24
16
 
25
17
        self.build_tree(['hello.txt'])
26
18
 
32
24
        b.working_tree().commit('commit pointless tree',
33
25
                 allow_pointless=True)
34
26
 
35
 
        b.add('hello.txt')
 
27
        b.working_tree().add('hello.txt')
36
28
        
37
29
        b.working_tree().commit('commit first added file',
38
30
                 allow_pointless=False)
50
42
 
51
43
    def test_rename_dirs(self):
52
44
        """Test renaming directories and the files within them."""
53
 
        b = Branch.initialize('.')
 
45
        b = Branch.initialize(u'.')
54
46
        self.build_tree(['dir/', 'dir/sub/', 'dir/sub/file'])
55
 
        b.add(['dir', 'dir/sub', 'dir/sub/file'])
 
47
        b.working_tree().add(['dir', 'dir/sub', 'dir/sub/file'])
56
48
 
57
49
        b.working_tree().commit('create initial state')
58
50
 
68
60
        self.check_inventory_shape(inv,
69
61
                                   ['dir', 'dir/sub', 'dir/sub/file'])
70
62
 
71
 
        b.rename_one('dir', 'newdir')
 
63
        b.working_tree().rename_one('dir', 'newdir')
72
64
 
73
65
        self.check_inventory_shape(b.working_tree().read_working_inventory(),
74
66
                                   ['newdir', 'newdir/sub', 'newdir/sub/file'])
75
67
 
76
 
        b.rename_one('newdir/sub', 'newdir/newsub')
 
68
        b.working_tree().rename_one('newdir/sub', 'newdir/newsub')
77
69
        self.check_inventory_shape(b.working_tree().read_working_inventory(),
78
70
                                   ['newdir', 'newdir/newsub',
79
71
                                    'newdir/newsub/file'])
85
77
        job: given a path (either relative to cwd or absolute), work out
86
78
        if it is inside a branch and return the path relative to the base.
87
79
        """
88
 
        from bzrlib.osutils import relpath
89
80
        import tempfile, shutil
90
81
        
91
82
        savedir = os.getcwdu()
92
83
        dtmp = tempfile.mkdtemp()
93
84
        # On Mac OSX, /tmp actually expands to /private/tmp
94
 
        dtmp = os.path.realpath(dtmp)
 
85
        dtmp = realpath(dtmp)
95
86
 
96
87
        def rp(p):
97
88
            return relpath(dtmp, p)
98
89
        
99
90
        try:
100
91
            # check paths inside dtmp while standing outside it
101
 
            self.assertEqual(rp(os.path.join(dtmp, 'foo')), 'foo')
 
92
            self.assertEqual(rp(pathjoin(dtmp, 'foo')), 'foo')
102
93
 
103
94
            # root = nothing
104
95
            self.assertEqual(rp(dtmp), '')
105
96
 
106
 
            self.assertRaises(NotBranchError,
 
97
            self.assertRaises(PathNotChild,
107
98
                              rp,
108
99
                              '/etc')
109
100
 
110
101
            # now some near-miss operations -- note that
111
102
            # os.path.commonprefix gets these wrong!
112
 
            self.assertRaises(NotBranchError,
 
103
            self.assertRaises(PathNotChild,
113
104
                              rp,
114
105
                              dtmp.rstrip('\\/') + '2')
115
106
 
116
 
            self.assertRaises(NotBranchError,
 
107
            self.assertRaises(PathNotChild,
117
108
                              rp,
118
109
                              dtmp.rstrip('\\/') + '2/foo')
119
110
 
121
112
            # directory, or nearby
122
113
            os.chdir(dtmp)
123
114
 
124
 
            FOO_BAR_QUUX = os.path.join('foo', 'bar', 'quux')
125
 
            self.assertEqual(rp('foo/bar/quux'), FOO_BAR_QUUX)
 
115
            self.assertEqual(rp('foo/bar/quux'), 'foo/bar/quux')
126
116
 
127
117
            self.assertEqual(rp('foo'), 'foo')
128
118
 
129
119
            self.assertEqual(rp('./foo'), 'foo')
130
120
 
131
 
            self.assertEqual(rp(os.path.abspath('foo')), 'foo')
 
121
            self.assertEqual(rp(abspath('foo')), 'foo')
132
122
 
133
 
            self.assertRaises(NotBranchError,
 
123
            self.assertRaises(PathNotChild,
134
124
                              rp, '../foo')
135
125
 
136
126
        finally: