~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_foreign.py

MergeĀ lp:bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
from bzrlib import (
22
22
    branch,
 
23
    bzrdir,
23
24
    errors,
24
25
    foreign,
25
26
    lockable_files,
26
27
    lockdir,
 
28
    revision,
 
29
    tests,
27
30
    trace,
28
31
    )
29
 
from bzrlib.bzrdir import (
30
 
    BzrDir,
31
 
    BzrDirFormat,
32
 
    BzrDirMeta1,
33
 
    BzrDirMetaFormat1,
34
 
    format_registry,
35
 
    )
36
 
from bzrlib.inventory import Inventory
37
 
from bzrlib.revision import (
38
 
    NULL_REVISION,
39
 
    Revision,
40
 
    )
41
 
from bzrlib.tests import (
42
 
    TestCase,
43
 
    TestCaseWithTransport,
44
 
    )
45
32
 
46
33
# This is the dummy foreign revision control system, used 
47
34
# mainly here in the testsuite to test the foreign VCS infrastructure.
136
123
                    (str(rev.timestamp), str(rev.timezone), 
137
124
                        str(self.target.revno())))
138
125
                parent_revno, parent_revid= self.target.last_revision_info()
139
 
                if parent_revid == NULL_REVISION:
 
126
                if parent_revid == revision.NULL_REVISION:
140
127
                    parent_revids = []
141
128
                else:
142
129
                    parent_revids = [parent_revid]
192
179
            raise errors.NotBranchError(path=transport.base)
193
180
 
194
181
 
195
 
class DummyForeignVcsDirFormat(BzrDirMetaFormat1):
 
182
class DummyForeignVcsDirFormat(bzrdir.BzrDirMetaFormat1):
196
183
    """BzrDirFormat for the dummy foreign VCS."""
197
184
 
198
185
    @classmethod
239
226
        return DummyForeignVcsDir(transport, self)
240
227
 
241
228
 
242
 
class DummyForeignVcsDir(BzrDirMeta1):
 
229
class DummyForeignVcsDir(bzrdir.BzrDirMeta1):
243
230
 
244
231
    def __init__(self, _transport, _format):
245
232
        self._format = _format
254
241
 
255
242
    def cloning_metadir(self, stacked=False):
256
243
        """Produce a metadir suitable for cloning with."""
257
 
        return format_registry.make_bzrdir("default")
 
244
        return bzrdir.format_registry.make_bzrdir("default")
258
245
 
259
246
    def sprout(self, url, revision_id=None, force_new_repo=False,
260
247
               recurse='down', possible_transports=None,
268
255
                hardlink=hardlink, stacked=stacked, source_branch=source_branch)
269
256
 
270
257
 
271
 
class ForeignVcsRegistryTests(TestCase):
 
258
def register_dummy_foreign_for_test(testcase):
 
259
    bzrdir.BzrDirFormat.register_control_format(DummyForeignVcsDirFormat)
 
260
    testcase.addCleanup(bzrdir.BzrDirFormat.unregister_control_format,
 
261
                        DummyForeignVcsDirFormat)
 
262
    # We need to register the optimiser to make the dummy appears really
 
263
    # different from a regular bzr repository.
 
264
    branch.InterBranch.register_optimiser(InterToDummyVcsBranch)
 
265
    testcase.addCleanup(branch.InterBranch.unregister_optimiser,
 
266
                        InterToDummyVcsBranch)
 
267
 
 
268
 
 
269
class ForeignVcsRegistryTests(tests.TestCase):
272
270
    """Tests for the ForeignVcsRegistry class."""
273
271
 
274
272
    def test_parse_revision_id_no_dash(self):
289
287
                          reg.parse_revision_id("dummy-v1:some-foreign-revid"))
290
288
 
291
289
 
292
 
class ForeignRevisionTests(TestCase):
 
290
class ForeignRevisionTests(tests.TestCase):
293
291
    """Tests for the ForeignRevision class."""
294
292
 
295
293
    def test_create(self):
301
299
        self.assertEquals(mapp, rev.mapping)
302
300
 
303
301
 
304
 
class WorkingTreeFileUpdateTests(TestCaseWithTransport):
 
302
class WorkingTreeFileUpdateTests(tests.TestCaseWithTransport):
305
303
    """Tests for update_workingtree_fileids()."""
306
304
 
307
305
    def test_update_workingtree(self):
325
323
            wt.unlock()
326
324
 
327
325
 
328
 
class DummyForeignVcsTests(TestCaseWithTransport):
 
326
class DummyForeignVcsTests(tests.TestCaseWithTransport):
329
327
    """Very basic test for DummyForeignVcs."""
330
328
 
331
329
    def setUp(self):
332
 
        BzrDirFormat.register_control_format(DummyForeignVcsDirFormat)
333
 
        branch.InterBranch.register_optimiser(InterToDummyVcsBranch)
334
 
        self.addCleanup(self.unregister)
335
330
        super(DummyForeignVcsTests, self).setUp()
336
 
 
337
 
    def unregister(self):
338
 
        try:
339
 
            BzrDirFormat.unregister_control_format(DummyForeignVcsDirFormat)
340
 
        except ValueError:
341
 
            pass
342
 
        branch.InterBranch.unregister_optimiser(InterToDummyVcsBranch)
 
331
        register_dummy_foreign_for_test(self)
343
332
 
344
333
    def test_create(self):
345
334
        """Test we can create dummies."""
346
335
        self.make_branch_and_tree("d", format=DummyForeignVcsDirFormat())
347
 
        dir = BzrDir.open("d")
 
336
        dir = bzrdir.BzrDir.open("d")
348
337
        self.assertEquals("A Dummy VCS Dir", dir._format.get_format_string())
349
338
        dir.open_repository()
350
339
        dir.open_branch()
353
342
    def test_sprout(self):
354
343
        """Test we can clone dummies and that the format is not preserved."""
355
344
        self.make_branch_and_tree("d", format=DummyForeignVcsDirFormat())
356
 
        dir = BzrDir.open("d")
 
345
        dir = bzrdir.BzrDir.open("d")
357
346
        newdir = dir.sprout("e")
358
 
        self.assertNotEquals("A Dummy VCS Dir", newdir._format.get_format_string())
 
347
        self.assertNotEquals("A Dummy VCS Dir",
 
348
                             newdir._format.get_format_string())
359
349
 
360
350
    def test_lossy_push_empty(self):
361
351
        source_tree = self.make_branch_and_tree("source")
362
352
        target_tree = self.make_branch_and_tree("target", 
363
353
            format=DummyForeignVcsDirFormat())
364
354
        pushresult = source_tree.branch.lossy_push(target_tree.branch)
365
 
        self.assertEquals(NULL_REVISION, pushresult.old_revid)
366
 
        self.assertEquals(NULL_REVISION, pushresult.new_revid)
 
355
        self.assertEquals(revision.NULL_REVISION, pushresult.old_revid)
 
356
        self.assertEquals(revision.NULL_REVISION, pushresult.new_revid)
367
357
        self.assertEquals({}, pushresult.revidmap)
368
358
 
369
359
    def test_lossy_push_simple(self):
378
368
            pushresult = source_tree.branch.lossy_push(target_tree.branch)
379
369
        finally:
380
370
            target_tree.branch.unlock()
381
 
        self.assertEquals(NULL_REVISION, pushresult.old_revid)
 
371
        self.assertEquals(revision.NULL_REVISION, pushresult.old_revid)
382
372
        self.assertEquals({revid1:target_tree.branch.last_revision()}, 
383
373
                           pushresult.revidmap)
384
374
        self.assertEquals(pushresult.revidmap[revid1], pushresult.new_revid)