/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/branch.py

Implement BranchTestProviderAdapter, so tests now run across all branch formats.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
 
18
from copy import deepcopy
18
19
from cStringIO import StringIO
19
20
import errno
20
21
import os
21
22
import shutil
22
23
import sys
 
24
from unittest import TestSuite
23
25
from warnings import warn
24
26
 
25
27
 
29
31
import bzrlib.errors as errors
30
32
from bzrlib.errors import (BzrError, InvalidRevisionNumber, InvalidRevisionId,
31
33
                           NoSuchRevision, HistoryMissing, NotBranchError,
32
 
                           DivergedBranches, LockError, UnlistableStore,
 
34
                           DivergedBranches, LockError, 
 
35
                           UninitializableFormat,
 
36
                           UnlistableStore,
33
37
                           UnlistableBranch, NoSuchFile, NotVersionedError,
34
38
                           NoWorkingTree)
35
39
import bzrlib.inventory as inventory
47
51
from bzrlib.store import copy_all
48
52
from bzrlib.store.text import TextStore
49
53
from bzrlib.store.weave import WeaveStore
 
54
from bzrlib.symbol_versioning import deprecated_nonce, deprecated_passed
50
55
from bzrlib.testament import Testament
51
56
import bzrlib.transactions as transactions
52
57
from bzrlib.transport import Transport, get_transport
629
634
 
630
635
    def initialize(self, url):
631
636
        """Format 4 branches cannot be created."""
632
 
        raise NotImplementedError(self.initialize)
 
637
        raise UninitializableFormat(self)
633
638
 
634
639
 
635
640
class BzrBranchFormat5(BzrBranchFormat):
1269
1274
Branch.set_default_initializer(BzrBranch._initialize)
1270
1275
 
1271
1276
 
 
1277
class BranchTestProviderAdapter(object):
 
1278
    """A tool to generate a suite testing multiple branch formats at once.
 
1279
 
 
1280
    This is done by copying the test once for each transport and injecting
 
1281
    the transport_server, transport_readonly_server, and branch_format
 
1282
    classes into each copy. Each copy is also given a new id() to make it
 
1283
    easy to identify.
 
1284
    """
 
1285
 
 
1286
    def __init__(self, transport_server, transport_readonly_server, formats):
 
1287
        self._transport_server = transport_server
 
1288
        self._transport_readonly_server = transport_readonly_server
 
1289
        self._formats = formats
 
1290
    
 
1291
    def adapt(self, test):
 
1292
        result = TestSuite()
 
1293
        for format in self._formats:
 
1294
            new_test = deepcopy(test)
 
1295
            new_test.transport_server = self._transport_server
 
1296
            new_test.transport_readonly_server = self._transport_readonly_server
 
1297
            new_test.branch_format = format
 
1298
            def make_new_test_id():
 
1299
                new_id = "%s(%s)" % (new_test.id(), format.__class__.__name__)
 
1300
                return lambda: new_id
 
1301
            new_test.id = make_new_test_id()
 
1302
            result.addTest(new_test)
 
1303
        return result
 
1304
 
 
1305
 
1272
1306
class ScratchBranch(BzrBranch):
1273
1307
    """Special test class: a branch that cleans up after itself.
1274
1308