~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

Various changes to allow non-workingtree specific tests to run entirely
from MemoryTransports:
 * Create MemoryTree and pull up common code for it from WorkingTree to
   a new common base class MutableTree.
 * Add MutableTree.mkdir().
 * Add MutableTree.put_file_bytes_nonatomic().
 * New test helper make_branch_and_memory_tree().
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
import time
44
44
 
45
45
 
 
46
from bzrlib import memorytree
46
47
import bzrlib.branch
47
48
import bzrlib.bzrdir as bzrdir
48
49
import bzrlib.commands
1226
1227
 
1227
1228
    def make_bzrdir(self, relpath, format=None):
1228
1229
        try:
1229
 
            url = self.get_url(relpath)
1230
 
            mutter('relpath %r => url %r', relpath, url)
1231
 
            segments = url.split('/')
 
1230
            # might be a relative or absolute path
 
1231
            maybe_a_url = self.get_url(relpath)
 
1232
            segments = maybe_a_url.split('/')
 
1233
            t = get_transport(maybe_a_url)
1232
1234
            if segments and segments[-1] not in ('', '.'):
1233
 
                parent = '/'.join(segments[:-1])
1234
 
                t = get_transport(parent)
1235
1235
                try:
1236
 
                    t.mkdir(segments[-1])
 
1236
                    t.mkdir('.')
1237
1237
                except errors.FileExists:
1238
1238
                    pass
1239
1239
            if format is None:
1240
 
                format=bzrlib.bzrdir.BzrDirFormat.get_default_format()
1241
 
            # FIXME: make this use a single transport someday. RBC 20060418
1242
 
            return format.initialize_on_transport(get_transport(relpath))
 
1240
                format = bzrlib.bzrdir.BzrDirFormat.get_default_format()
 
1241
            return format.initialize_on_transport(t)
1243
1242
        except errors.UninitializableFormat:
1244
1243
            raise TestSkipped("Format %s is not initializable." % format)
1245
1244
 
1248
1247
        made_control = self.make_bzrdir(relpath, format=format)
1249
1248
        return made_control.create_repository(shared=shared)
1250
1249
 
 
1250
    def make_branch_and_memory_tree(self, relpath):
 
1251
        """Create a branch on the default transport and a MemoryTree for it."""
 
1252
        b = self.make_branch(relpath)
 
1253
        return memorytree.MemoryTree.create_on_branch(b)
 
1254
 
1251
1255
    def make_branch_and_tree(self, relpath, format=None):
1252
1256
        """Create a branch on the transport and a tree locally.
1253
1257
 
1404
1408
                   'bzrlib.tests.test_lockdir',
1405
1409
                   'bzrlib.tests.test_lockable_files',
1406
1410
                   'bzrlib.tests.test_log',
 
1411
                   'bzrlib.tests.test_memorytree',
1407
1412
                   'bzrlib.tests.test_merge',
1408
1413
                   'bzrlib.tests.test_merge3',
1409
1414
                   'bzrlib.tests.test_merge_core',
1442
1447
                   'bzrlib.tests.test_transform',
1443
1448
                   'bzrlib.tests.test_transport',
1444
1449
                   'bzrlib.tests.test_tree',
 
1450
                   'bzrlib.tests.test_treebuilder',
1445
1451
                   'bzrlib.tests.test_tsort',
1446
1452
                   'bzrlib.tests.test_tuned_gzip',
1447
1453
                   'bzrlib.tests.test_ui',