~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/whitebox.py

  • Committer: Martin Pool
  • Date: 2005-08-24 02:34:24 UTC
  • Revision ID: mbp@sourcefrog.net-20050824023424-67667e2b57c3d7d0
- merge test refactoring from robertc

  More of the common test infrastructure to do with 
  making temporary directories, etc, is now done from a 
  TestCase subclass, and generally have less magic
  compared to unittest. 

robertc@robertcollins.net-20050823111339-fb55b8ce170b20e0

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 InTempDir, 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(InTempDir):
 
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
 
82
 
 
83
75
class PendingMerges(InTempDir):
84
 
    """Tracking pending-merged revisions."""
85
 
    def runTest(self):
 
76
    def test_pending_merges(self):
 
77
        """Tracking pending-merged revisions."""
86
78
        b = Branch('.', init=True)
87
79
 
88
80
        self.assertEquals(b.pending_merges(), [])
112
104
        # list should be cleared when we do a commit
113
105
        self.assertEquals(b.pending_merges(), [])
114
106
        
115
 
        
116
 
        
117
 
 
118
 
class Revert(InTempDir):
119
 
    """Test selected-file revert"""
120
 
    def runTest(self):
 
107
    def test_revert(self):
 
108
        """Test selected-file revert"""
121
109
        b = Branch('.', init=True)
122
110
 
123
111
        self.build_tree(['hello.txt'])
143
131
        self.check_file_contents('hello.txt', 'initial hello')
144
132
        self.check_file_contents('hello.txt~', 'initial hello')
145
133
 
146
 
 
147
 
 
148
 
class RenameDirs(InTempDir):
149
 
    """Test renaming directories and the files within them."""
150
 
    def runTest(self):
 
134
    def test_rename_dirs(self):
 
135
        """Test renaming directories and the files within them."""
151
136
        b = Branch('.', init=True)
152
137
        self.build_tree(['dir/', 'dir/sub/', 'dir/sub/file'])
153
138
        b.add(['dir', 'dir/sub', 'dir/sub/file'])
176
161
                                   ['newdir', 'newdir/newsub',
177
162
                                    'newdir/newsub/file'])
178
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
    def test_relpath(self):
 
165
        """test for branch path lookups
 
166
    
 
167
        Branch.relpath and bzrlib.branch._relpath do a simple but subtle
 
168
        job: given a path (either relative to cwd or absolute), work out
 
169
        if it is inside a branch and return the path relative to the base.
 
170
        """
191
171
        from bzrlib.branch import _relpath
192
172
        import tempfile, shutil
193
173
        
240
220
            shutil.rmtree(dtmp)
241
221
 
242
222
 
243
 
 
244
 
 
245
 
TEST_CLASSES = [Unknowns,
246
 
                ValidateRevisionId,
247
 
                PendingMerges,
248
 
                Revert,
249
 
                RenameDirs,
250
 
                BranchPathTestCase,
 
223
TEST_CLASSES = [TestBranch,
 
224
                TestRevisionId,
 
225
                PendingMerges
251
226
                ]