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

  • Committer: Martin Pool
  • Date: 2005-07-04 07:34:19 UTC
  • Revision ID: mbp@sourcefrog.net-20050704073419-44eb753d5556a4d0
- rename control file to pending-merges

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/python
 
2
 
 
3
import os
 
4
import unittest
 
5
 
 
6
from bzrlib.selftest import InTempDir, TestBase
 
7
from bzrlib.branch import ScratchBranch, Branch
 
8
from bzrlib.errors import NotBranchError, NotVersionedError
 
9
 
 
10
 
 
11
class Unknowns(InTempDir):
 
12
    def runTest(self):
 
13
        b = Branch('.', init=True)
 
14
 
 
15
        self.build_tree(['hello.txt',
 
16
                         'hello.txt~'])
 
17
 
 
18
        self.assertEquals(list(b.unknowns()),
 
19
                          ['hello.txt'])
 
20
 
 
21
 
 
22
 
 
23
class ValidateRevisionId(TestBase):
 
24
    def runTest(self):
 
25
        from bzrlib.revision import validate_revision_id
 
26
        validate_revision_id('mbp@sourcefrog.net-20050311061123-96a255005c7c9dbe')
 
27
        
 
28
        self.assertRaises(ValueError,
 
29
                          validate_revision_id,
 
30
                          ' asdkjas')
 
31
 
 
32
 
 
33
        self.assertRaises(ValueError,
 
34
                          validate_revision_id,
 
35
                          'mbp@sourcefrog.net-20050311061123-96a255005c7c9dbe\n')
 
36
 
 
37
 
 
38
        self.assertRaises(ValueError,
 
39
                          validate_revision_id,
 
40
                          ' mbp@sourcefrog.net-20050311061123-96a255005c7c9dbe')
 
41
 
 
42
        self.assertRaises(ValueError,
 
43
                          validate_revision_id,
 
44
                          'Martin Pool <mbp@sourcefrog.net>-20050311061123-96a255005c7c9dbe')
 
45
 
 
46
 
 
47
 
 
48
class Revert(InTempDir):
 
49
    """Test selected-file revert"""
 
50
    def runTest(self):
 
51
        b = Branch('.', init=True)
 
52
 
 
53
        self.build_tree(['hello.txt'])
 
54
        file('hello.txt', 'w').write('initial hello')
 
55
 
 
56
        self.assertRaises(NotVersionedError,
 
57
                          b.revert, ['hello.txt'])
 
58
        
 
59
        b.add(['hello.txt'])
 
60
        b.commit('create initial hello.txt')
 
61
 
 
62
        self.check_file_contents('hello.txt', 'initial hello')
 
63
        file('hello.txt', 'w').write('new hello')
 
64
        self.check_file_contents('hello.txt', 'new hello')
 
65
 
 
66
        # revert file modified since last revision
 
67
        b.revert(['hello.txt'])
 
68
        self.check_file_contents('hello.txt', 'initial hello')
 
69
        self.check_file_contents('hello.txt~', 'new hello')
 
70
 
 
71
        # reverting again clobbers the backup
 
72
        b.revert(['hello.txt'])
 
73
        self.check_file_contents('hello.txt', 'initial hello')
 
74
        self.check_file_contents('hello.txt~', 'initial hello')
 
75
 
 
76
 
 
77
 
 
78
class RenameDirs(InTempDir):
 
79
    """Test renaming directories and the files within them."""
 
80
    def runTest(self):
 
81
        b = Branch('.', init=True)
 
82
        self.build_tree(['dir/', 'dir/sub/', 'dir/sub/file'])
 
83
        b.add(['dir', 'dir/sub', 'dir/sub/file'])
 
84
 
 
85
        b.commit('create initial state')
 
86
 
 
87
        # TODO: lift out to a test helper that checks the shape of
 
88
        # an inventory
 
89
        
 
90
        revid = b.revision_history()[0]
 
91
        self.log('first revision_id is {%s}' % revid)
 
92
        
 
93
        inv = b.get_revision_inventory(revid)
 
94
        self.log('contents of inventory: %r' % inv.entries())
 
95
 
 
96
        self.check_inventory_shape(inv,
 
97
                                   ['dir', 'dir/sub', 'dir/sub/file'])
 
98
 
 
99
        b.rename_one('dir', 'newdir')
 
100
 
 
101
        self.check_inventory_shape(b.inventory,
 
102
                                   ['newdir', 'newdir/sub', 'newdir/sub/file'])
 
103
 
 
104
        b.rename_one('newdir/sub', 'newdir/newsub')
 
105
        self.check_inventory_shape(b.inventory,
 
106
                                   ['newdir', 'newdir/newsub',
 
107
                                    'newdir/newsub/file'])
 
108
 
 
109
        
 
110
 
 
111
 
 
112
class BranchPathTestCase(TestBase):
 
113
    """test for branch path lookups
 
114
 
 
115
    Branch.relpath and bzrlib.branch._relpath do a simple but subtle
 
116
    job: given a path (either relative to cwd or absolute), work out
 
117
    if it is inside a branch and return the path relative to the base.
 
118
    """
 
119
 
 
120
    def runTest(self):
 
121
        from bzrlib.branch import _relpath
 
122
        import tempfile, shutil
 
123
        
 
124
        savedir = os.getcwdu()
 
125
        dtmp = tempfile.mkdtemp()
 
126
 
 
127
        def rp(p):
 
128
            return _relpath(dtmp, p)
 
129
        
 
130
        try:
 
131
            # check paths inside dtmp while standing outside it
 
132
            self.assertEqual(rp(os.path.join(dtmp, 'foo')), 'foo')
 
133
 
 
134
            # root = nothing
 
135
            self.assertEqual(rp(dtmp), '')
 
136
 
 
137
            self.assertRaises(NotBranchError,
 
138
                              rp,
 
139
                              '/etc')
 
140
 
 
141
            # now some near-miss operations -- note that
 
142
            # os.path.commonprefix gets these wrong!
 
143
            self.assertRaises(NotBranchError,
 
144
                              rp,
 
145
                              dtmp.rstrip('\\/') + '2')
 
146
 
 
147
            self.assertRaises(NotBranchError,
 
148
                              rp,
 
149
                              dtmp.rstrip('\\/') + '2/foo')
 
150
 
 
151
            # now operations based on relpath of files in current
 
152
            # directory, or nearby
 
153
            os.chdir(dtmp)
 
154
 
 
155
            self.assertEqual(rp('foo/bar/quux'), 'foo/bar/quux')
 
156
 
 
157
            self.assertEqual(rp('foo'), 'foo')
 
158
 
 
159
            self.assertEqual(rp('./foo'), 'foo')
 
160
 
 
161
            self.assertEqual(rp(os.path.abspath('foo')), 'foo')
 
162
 
 
163
            self.assertRaises(NotBranchError,
 
164
                              rp, '../foo')
 
165
 
 
166
        finally:
 
167
            os.chdir(savedir)
 
168
            shutil.rmtree(dtmp)