~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_foreign.py

  • Committer: Martin Pool
  • Date: 2010-02-27 01:34:49 UTC
  • mto: This revision was merged to the branch mainline in revision 5064.
  • Revision ID: mbp@canonical.com-20100227013449-zxostilwfoendxfv
Handle "Directory not empty" from ftp as DirectoryNotEmpty.

FtpTransport._translate_ftp_error can handle all ftp errors; there's no clear
distinction between 'temporary' and 'permament'.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008 Canonical Ltd
 
1
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
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.
87
74
        self.mapping_registry = DummyForeignVcsMappingRegistry()
88
75
        self.mapping_registry.register("v1", DummyForeignVcsMapping(self),
89
76
                                       "Version 1")
 
77
        self.abbreviation = "dummy"
90
78
 
91
79
    def show_foreign_revid(self, foreign_revid):
92
80
        return { "dummy ding": "%s/%s\\%s" % foreign_revid }
93
81
 
 
82
    def serialize_foreign_revid(self, foreign_revid):
 
83
        return "%s|%s|%s" % foreign_revid
 
84
 
94
85
 
95
86
class DummyForeignVcsBranch(branch.BzrBranch6,foreign.ForeignBranch):
96
87
    """A Dummy VCS Branch."""
112
103
    def is_compatible(source, target):
113
104
        return isinstance(target, DummyForeignVcsBranch)
114
105
 
 
106
    def push(self, overwrite=False, stop_revision=None):
 
107
        raise errors.NoRoundtrippingSupport(self.source, self.target)
 
108
 
115
109
    def lossy_push(self, stop_revision=None):
116
110
        result = branch.BranchPushResult()
117
111
        result.source_branch = self.source
136
130
                    (str(rev.timestamp), str(rev.timezone), 
137
131
                        str(self.target.revno())))
138
132
                parent_revno, parent_revid= self.target.last_revision_info()
139
 
                if parent_revid == NULL_REVISION:
 
133
                if parent_revid == revision.NULL_REVISION:
140
134
                    parent_revids = []
141
135
                else:
142
136
                    parent_revids = [parent_revid]
192
186
            raise errors.NotBranchError(path=transport.base)
193
187
 
194
188
 
195
 
class DummyForeignVcsDirFormat(BzrDirMetaFormat1):
 
189
class DummyForeignVcsDirFormat(bzrdir.BzrDirMetaFormat1):
196
190
    """BzrDirFormat for the dummy foreign VCS."""
197
191
 
198
192
    @classmethod
239
233
        return DummyForeignVcsDir(transport, self)
240
234
 
241
235
 
242
 
class DummyForeignVcsDir(BzrDirMeta1):
 
236
class DummyForeignVcsDir(bzrdir.BzrDirMeta1):
243
237
 
244
238
    def __init__(self, _transport, _format):
245
239
        self._format = _format
254
248
 
255
249
    def cloning_metadir(self, stacked=False):
256
250
        """Produce a metadir suitable for cloning with."""
257
 
        return format_registry.make_bzrdir("default")
 
251
        return bzrdir.format_registry.make_bzrdir("default")
258
252
 
259
253
    def sprout(self, url, revision_id=None, force_new_repo=False,
260
254
               recurse='down', possible_transports=None,
268
262
                hardlink=hardlink, stacked=stacked, source_branch=source_branch)
269
263
 
270
264
 
271
 
class ForeignVcsRegistryTests(TestCase):
 
265
def register_dummy_foreign_for_test(testcase):
 
266
    bzrdir.BzrDirFormat.register_control_format(DummyForeignVcsDirFormat)
 
267
    testcase.addCleanup(bzrdir.BzrDirFormat.unregister_control_format,
 
268
                        DummyForeignVcsDirFormat)
 
269
    # We need to register the optimiser to make the dummy appears really
 
270
    # different from a regular bzr repository.
 
271
    branch.InterBranch.register_optimiser(InterToDummyVcsBranch)
 
272
    testcase.addCleanup(branch.InterBranch.unregister_optimiser,
 
273
                        InterToDummyVcsBranch)
 
274
 
 
275
 
 
276
class ForeignVcsRegistryTests(tests.TestCase):
272
277
    """Tests for the ForeignVcsRegistry class."""
273
278
 
274
279
    def test_parse_revision_id_no_dash(self):
289
294
                          reg.parse_revision_id("dummy-v1:some-foreign-revid"))
290
295
 
291
296
 
292
 
class ForeignRevisionTests(TestCase):
 
297
class ForeignRevisionTests(tests.TestCase):
293
298
    """Tests for the ForeignRevision class."""
294
299
 
295
300
    def test_create(self):
301
306
        self.assertEquals(mapp, rev.mapping)
302
307
 
303
308
 
304
 
class WorkingTreeFileUpdateTests(TestCaseWithTransport):
 
309
class WorkingTreeFileUpdateTests(tests.TestCaseWithTransport):
305
310
    """Tests for update_workingtree_fileids()."""
306
311
 
307
312
    def test_update_workingtree(self):
309
314
        self.build_tree_contents([('br1/bla', 'original contents\n')])
310
315
        wt.add('bla', 'bla-a')
311
316
        wt.commit('bla-a')
 
317
        root_id = wt.get_root_id()
312
318
        target = wt.bzrdir.sprout('br2').open_workingtree()
313
319
        target.unversion(['bla-a'])
314
320
        target.add('bla', 'bla-b')
319
325
        foreign.update_workingtree_fileids(wt, target_basis)
320
326
        wt.lock_read()
321
327
        try:
322
 
            self.assertEquals(["TREE_ROOT", "bla-b"], list(wt.inventory))
 
328
            self.assertEquals(set([root_id, "bla-b"]), set(wt.inventory))
323
329
        finally:
324
330
            wt.unlock()
325
331
 
326
332
 
327
 
class DummyForeignVcsTests(TestCaseWithTransport):
 
333
class DummyForeignVcsTests(tests.TestCaseWithTransport):
328
334
    """Very basic test for DummyForeignVcs."""
329
335
 
330
336
    def setUp(self):
331
 
        BzrDirFormat.register_control_format(DummyForeignVcsDirFormat)
332
 
        branch.InterBranch.register_optimiser(InterToDummyVcsBranch)
333
 
        self.addCleanup(self.unregister)
334
337
        super(DummyForeignVcsTests, self).setUp()
335
 
 
336
 
    def unregister(self):
337
 
        try:
338
 
            BzrDirFormat.unregister_control_format(DummyForeignVcsDirFormat)
339
 
        except ValueError:
340
 
            pass
341
 
        branch.InterBranch.unregister_optimiser(InterToDummyVcsBranch)
 
338
        register_dummy_foreign_for_test(self)
342
339
 
343
340
    def test_create(self):
344
341
        """Test we can create dummies."""
345
342
        self.make_branch_and_tree("d", format=DummyForeignVcsDirFormat())
346
 
        dir = BzrDir.open("d")
 
343
        dir = bzrdir.BzrDir.open("d")
347
344
        self.assertEquals("A Dummy VCS Dir", dir._format.get_format_string())
348
345
        dir.open_repository()
349
346
        dir.open_branch()
352
349
    def test_sprout(self):
353
350
        """Test we can clone dummies and that the format is not preserved."""
354
351
        self.make_branch_and_tree("d", format=DummyForeignVcsDirFormat())
355
 
        dir = BzrDir.open("d")
 
352
        dir = bzrdir.BzrDir.open("d")
356
353
        newdir = dir.sprout("e")
357
 
        self.assertNotEquals("A Dummy VCS Dir", newdir._format.get_format_string())
 
354
        self.assertNotEquals("A Dummy VCS Dir",
 
355
                             newdir._format.get_format_string())
 
356
 
 
357
    def test_push_not_supported(self):
 
358
        source_tree = self.make_branch_and_tree("source")
 
359
        target_tree = self.make_branch_and_tree("target", 
 
360
            format=DummyForeignVcsDirFormat())
 
361
        self.assertRaises(errors.NoRoundtrippingSupport, 
 
362
            source_tree.branch.push, target_tree.branch)
358
363
 
359
364
    def test_lossy_push_empty(self):
360
365
        source_tree = self.make_branch_and_tree("source")
361
366
        target_tree = self.make_branch_and_tree("target", 
362
367
            format=DummyForeignVcsDirFormat())
363
368
        pushresult = source_tree.branch.lossy_push(target_tree.branch)
364
 
        self.assertEquals(NULL_REVISION, pushresult.old_revid)
365
 
        self.assertEquals(NULL_REVISION, pushresult.new_revid)
 
369
        self.assertEquals(revision.NULL_REVISION, pushresult.old_revid)
 
370
        self.assertEquals(revision.NULL_REVISION, pushresult.new_revid)
366
371
        self.assertEquals({}, pushresult.revidmap)
367
372
 
368
373
    def test_lossy_push_simple(self):
377
382
            pushresult = source_tree.branch.lossy_push(target_tree.branch)
378
383
        finally:
379
384
            target_tree.branch.unlock()
380
 
        self.assertEquals(NULL_REVISION, pushresult.old_revid)
 
385
        self.assertEquals(revision.NULL_REVISION, pushresult.old_revid)
381
386
        self.assertEquals({revid1:target_tree.branch.last_revision()}, 
382
387
                           pushresult.revidmap)
383
388
        self.assertEquals(pushresult.revidmap[revid1], pushresult.new_revid)