~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/whitebox.py

  • Committer: Aaron Bentley
  • Date: 2005-08-10 14:59:36 UTC
  • mto: (1092.1.41) (1185.3.4) (974.1.47)
  • mto: This revision was merged to the branch mainline in revision 1110.
  • Revision ID: abentley@panoramicfeedback.com-20050810145936-f1b0cf25e8b18f6c
Ensured that revert FILE only modifies that file.

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