~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/whitebox.py

  • Committer: Martin Pool
  • Date: 2005-09-06 07:39:09 UTC
  • Revision ID: mbp@sourcefrog.net-20050906073909-234eb078dfff15d9
- improved check for branch version

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
import os
4
4
import unittest
5
5
 
6
 
from bzrlib.selftest import InTempDir, TestBase
 
6
from bzrlib.selftest import TestCaseInTempDir, TestCase
7
7
from bzrlib.branch import ScratchBranch, Branch
8
8
from bzrlib.errors import NotBranchError, NotVersionedError
9
9
 
10
10
 
11
 
class Unknowns(InTempDir):
12
 
    def runTest(self):
 
11
class TestBranch(TestCaseInTempDir):
 
12
 
 
13
    def test_unknowns(self):
13
14
        b = Branch('.', init=True)
14
15
 
15
16
        self.build_tree(['hello.txt',
18
19
        self.assertEquals(list(b.unknowns()),
19
20
                          ['hello.txt'])
20
21
 
21
 
 
22
 
 
23
 
class NoChanges(InTempDir):
24
 
    def runTest(self):
 
22
    def test_no_changes(self):
25
23
        from bzrlib.errors import PointlessCommit
26
24
        
27
25
        b = Branch('.', init=True)
55
53
        
56
54
 
57
55
 
58
 
class ValidateRevisionId(TestBase):
59
 
    def runTest(self):
 
56
class TestRevisionId(TestCase):
 
57
    
 
58
    def test_validate_revision_id(self):
60
59
        from bzrlib.revision import validate_revision_id
61
60
        validate_revision_id('mbp@sourcefrog.net-20050311061123-96a255005c7c9dbe')
62
 
        
63
61
        self.assertRaises(ValueError,
64
62
                          validate_revision_id,
65
63
                          ' asdkjas')
66
 
 
67
 
 
68
64
        self.assertRaises(ValueError,
69
65
                          validate_revision_id,
70
66
                          'mbp@sourcefrog.net-20050311061123-96a255005c7c9dbe\n')
71
 
 
72
 
 
73
67
        self.assertRaises(ValueError,
74
68
                          validate_revision_id,
75
69
                          ' mbp@sourcefrog.net-20050311061123-96a255005c7c9dbe')
76
 
 
77
70
        self.assertRaises(ValueError,
78
71
                          validate_revision_id,
79
72
                          'Martin Pool <mbp@sourcefrog.net>-20050311061123-96a255005c7c9dbe')
80
73
 
81
74
 
 
75
class PendingMerges(TestCaseInTempDir):
82
76
 
83
 
class PendingMerges(InTempDir):
84
 
    """Tracking pending-merged revisions."""
85
 
    def runTest(self):
 
77
    def test_pending_merges(self):
 
78
        """Tracking pending-merged revisions."""
86
79
        b = Branch('.', init=True)
87
80
 
88
81
        self.assertEquals(b.pending_merges(), [])
89
 
        
90
 
        b.add_pending_merge('foo@azkhazan-123123-abcabc')
91
 
        
92
 
        self.assertEquals(b.pending_merges(), ['foo@azkhazan-123123-abcabc'])
93
 
    
94
 
        b.add_pending_merge('foo@azkhazan-123123-abcabc')
95
 
        
96
 
        self.assertEquals(b.pending_merges(), ['foo@azkhazan-123123-abcabc'])
97
 
 
 
82
        b.add_pending_merge('foo@azkhazan-123123-abcabc')
 
83
        self.assertEquals(b.pending_merges(), ['foo@azkhazan-123123-abcabc'])
 
84
        b.add_pending_merge('foo@azkhazan-123123-abcabc')
 
85
        self.assertEquals(b.pending_merges(), ['foo@azkhazan-123123-abcabc'])
98
86
        b.add_pending_merge('wibble@fofof--20050401--1928390812')
99
87
        self.assertEquals(b.pending_merges(),
100
88
                          ['foo@azkhazan-123123-abcabc',
101
89
                           'wibble@fofof--20050401--1928390812'])
102
 
 
103
90
        b.commit("commit from base with two merges")
104
 
 
105
91
        rev = b.get_revision(b.revision_history()[0])
106
92
        self.assertEquals(len(rev.parents), 2)
107
93
        self.assertEquals(rev.parents[0].revision_id,
108
94
                          'foo@azkhazan-123123-abcabc')
109
95
        self.assertEquals(rev.parents[1].revision_id,
110
96
                           'wibble@fofof--20050401--1928390812')
111
 
 
112
97
        # list should be cleared when we do a commit
113
98
        self.assertEquals(b.pending_merges(), [])
114
99
        
115
 
        
116
 
        
117
 
 
118
 
class Revert(InTempDir):
119
 
    """Test selected-file revert"""
120
 
    def runTest(self):
 
100
    def test_revert(self):
 
101
        """Test selected-file revert"""
121
102
        b = Branch('.', init=True)
122
103
 
123
104
        self.build_tree(['hello.txt'])
143
124
        self.check_file_contents('hello.txt', 'initial hello')
144
125
        self.check_file_contents('hello.txt~', 'initial hello')
145
126
 
146
 
 
147
 
 
148
 
class RenameDirs(InTempDir):
149
 
    """Test renaming directories and the files within them."""
150
 
    def runTest(self):
 
127
    def test_rename_dirs(self):
 
128
        """Test renaming directories and the files within them."""
151
129
        b = Branch('.', init=True)
152
130
        self.build_tree(['dir/', 'dir/sub/', 'dir/sub/file'])
153
131
        b.add(['dir', 'dir/sub', 'dir/sub/file'])
176
154
                                   ['newdir', 'newdir/newsub',
177
155
                                    'newdir/newsub/file'])
178
156
 
179
 
        
180
 
 
181
 
 
182
 
class BranchPathTestCase(TestBase):
183
 
    """test for branch path lookups
184
 
 
185
 
    Branch.relpath and bzrlib.branch._relpath do a simple but subtle
186
 
    job: given a path (either relative to cwd or absolute), work out
187
 
    if it is inside a branch and return the path relative to the base.
188
 
    """
189
 
 
190
 
    def runTest(self):
 
157
    def test_relpath(self):
 
158
        """test for branch path lookups
 
159
    
 
160
        Branch.relpath and bzrlib.branch._relpath do a simple but subtle
 
161
        job: given a path (either relative to cwd or absolute), work out
 
162
        if it is inside a branch and return the path relative to the base.
 
163
        """
191
164
        from bzrlib.branch import _relpath
192
165
        import tempfile, shutil
193
166
        
238
211
        finally:
239
212
            os.chdir(savedir)
240
213
            shutil.rmtree(dtmp)
241
 
 
242
 
 
243
 
 
244
 
 
245
 
TEST_CLASSES = [Unknowns,
246
 
                ValidateRevisionId,
247
 
                PendingMerges,
248
 
                Revert,
249
 
                RenameDirs,
250
 
                BranchPathTestCase,
251
 
                ]