~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_foreign.py

  • Committer: Vincent Ladeuil
  • Date: 2009-05-05 15:31:34 UTC
  • mto: (4343.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4344.
  • Revision ID: v.ladeuil+lp@free.fr-20090505153134-q4bp4is9gywsmzrv
Clean up test for log formats.

* bzrlib/tests/blackbox/test_logformats.py:
Update tests to actual style.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
    format_registry,
35
35
    )
36
36
from bzrlib.inventory import Inventory
37
 
from bzrlib.revision import (
38
 
    NULL_REVISION,
39
 
    Revision,
40
 
    )
 
37
from bzrlib.revision import Revision
41
38
from bzrlib.tests import (
42
39
    TestCase,
43
40
    TestCaseWithTransport,
104
101
        branch.BzrBranch6.__init__(self, _format, _control_files, a_bzrdir, 
105
102
            *args, **kwargs)
106
103
 
107
 
 
108
 
class InterToDummyVcsBranch(branch.GenericInterBranch,
109
 
                            foreign.InterToForeignBranch):
110
 
 
111
 
    @staticmethod
112
 
    def is_compatible(source, target):
113
 
        return isinstance(target, DummyForeignVcsBranch)
114
 
 
115
 
    def lossy_push(self, stop_revision=None):
116
 
        result = branch.BranchPushResult()
117
 
        result.source_branch = self.source
118
 
        result.target_branch = self.target
119
 
        result.old_revno, result.old_revid = self.target.last_revision_info()
120
 
        self.source.lock_read()
 
104
    def dpull(self, source, stop_revision=None):
 
105
        source.lock_read()
121
106
        try:
122
107
            # This just handles simple cases, but that's good enough for tests
123
 
            my_history = self.target.revision_history()
124
 
            their_history = self.source.revision_history()
 
108
            my_history = self.revision_history()
 
109
            their_history = source.revision_history()
125
110
            if their_history[:min(len(my_history), len(their_history))] != my_history:
126
 
                raise errors.DivergedBranches(self.target, self.source)
 
111
                raise errors.DivergedBranches(self, source)
127
112
            todo = their_history[len(my_history):]
128
113
            revidmap = {}
129
114
            for revid in todo:
130
 
                rev = self.source.repository.get_revision(revid)
131
 
                tree = self.source.repository.revision_tree(revid)
 
115
                rev = source.repository.get_revision(revid)
 
116
                tree = source.repository.revision_tree(revid)
132
117
                def get_file_with_stat(file_id, path=None):
133
118
                    return (tree.get_file(file_id), None)
134
119
                tree.get_file_with_stat = get_file_with_stat
135
 
                new_revid = self.target.mapping.revision_id_foreign_to_bzr(
136
 
                    (str(rev.timestamp), str(rev.timezone), 
137
 
                        str(self.target.revno())))
138
 
                parent_revno, parent_revid= self.target.last_revision_info()
139
 
                if parent_revid == NULL_REVISION:
140
 
                    parent_revids = []
141
 
                else:
142
 
                    parent_revids = [parent_revid]
143
 
                builder = self.target.get_commit_builder(parent_revids, 
144
 
                        self.target.get_config(), rev.timestamp,
 
120
                new_revid = self.mapping.revision_id_foreign_to_bzr(
 
121
                    (str(rev.timestamp), str(rev.timezone), str(self.revno())))
 
122
                parent_revno, parent_revid= self.last_revision_info()
 
123
                builder = self.get_commit_builder([parent_revid], 
 
124
                        self.get_config(), rev.timestamp,
145
125
                        rev.timezone, rev.committer, rev.properties,
146
126
                        new_revid)
147
127
                try:
149
129
                        new_ie = ie.copy()
150
130
                        new_ie.revision = None
151
131
                        builder.record_entry_contents(new_ie, 
152
 
                            [self.target.repository.revision_tree(parent_revid).inventory],
 
132
                            [self.repository.get_inventory(parent_revid)],
153
133
                            path, tree, 
154
134
                            (ie.kind, ie.text_size, ie.executable, ie.text_sha1))
155
135
                    builder.finish_inventory()
157
137
                    builder.abort()
158
138
                    raise
159
139
                revidmap[revid] = builder.commit(rev.message)
160
 
                self.target.set_last_revision_info(parent_revno+1, 
161
 
                    revidmap[revid])
 
140
                self.set_last_revision_info(parent_revno+1, revidmap[revid])
162
141
                trace.mutter('lossily pushed revision %s -> %s', 
163
142
                    revid, revidmap[revid])
164
143
        finally:
165
 
            self.source.unlock()
166
 
        result.new_revno, result.new_revid = self.target.last_revision_info()
167
 
        result.revidmap = revidmap
168
 
        return result
 
144
            source.unlock()
 
145
        return revidmap
169
146
 
170
147
 
171
148
class DummyForeignVcsBranchFormat(branch.BzrBranchFormat6):
301
278
        self.assertEquals(mapp, rev.mapping)
302
279
 
303
280
 
 
281
class ShowForeignPropertiesTests(TestCase):
 
282
    """Tests for the show_foreign_properties() function."""
 
283
 
 
284
    def setUp(self):
 
285
        super(ShowForeignPropertiesTests, self).setUp()
 
286
        self.vcs = DummyForeignVcs()
 
287
        foreign.foreign_vcs_registry.register("dummy",
 
288
            self.vcs, "Dummy VCS")
 
289
 
 
290
    def tearDown(self):
 
291
        super(ShowForeignPropertiesTests, self).tearDown()
 
292
        foreign.foreign_vcs_registry.remove("dummy")
 
293
 
 
294
    def test_show_non_foreign(self):
 
295
        """Test use with a native (non-foreign) bzr revision."""
 
296
        self.assertEquals({}, foreign.show_foreign_properties(Revision("arevid")))
 
297
 
 
298
    def test_show_imported(self):
 
299
        rev = Revision("dummy-v1:my-foreign-revid")
 
300
        self.assertEquals({ "dummy ding": "my/foreign\\revid" },
 
301
                          foreign.show_foreign_properties(rev))
 
302
 
 
303
    def test_show_direct(self):
 
304
        rev = foreign.ForeignRevision(("some", "foreign", "revid"),
 
305
                                      DummyForeignVcsMapping(self.vcs),
 
306
                                      "roundtrip-revid")
 
307
        self.assertEquals({ "dummy ding": "some/foreign\\revid" },
 
308
                          foreign.show_foreign_properties(rev))
 
309
 
 
310
 
304
311
class WorkingTreeFileUpdateTests(TestCaseWithTransport):
305
312
    """Tests for update_workingtree_fileids()."""
306
313
 
329
336
 
330
337
    def setUp(self):
331
338
        BzrDirFormat.register_control_format(DummyForeignVcsDirFormat)
332
 
        branch.InterBranch.register_optimiser(InterToDummyVcsBranch)
333
339
        self.addCleanup(self.unregister)
334
340
        super(DummyForeignVcsTests, self).setUp()
335
341
 
338
344
            BzrDirFormat.unregister_control_format(DummyForeignVcsDirFormat)
339
345
        except ValueError:
340
346
            pass
341
 
        branch.InterBranch.unregister_optimiser(InterToDummyVcsBranch)
342
347
 
343
348
    def test_create(self):
344
349
        """Test we can create dummies."""
355
360
        dir = BzrDir.open("d")
356
361
        newdir = dir.sprout("e")
357
362
        self.assertNotEquals("A Dummy VCS Dir", newdir._format.get_format_string())
358
 
 
359
 
    def test_lossy_push_empty(self):
360
 
        source_tree = self.make_branch_and_tree("source")
361
 
        target_tree = self.make_branch_and_tree("target", 
362
 
            format=DummyForeignVcsDirFormat())
363
 
        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)
366
 
        self.assertEquals({}, pushresult.revidmap)
367
 
 
368
 
    def test_lossy_push_simple(self):
369
 
        source_tree = self.make_branch_and_tree("source")
370
 
        self.build_tree(['source/a', 'source/b'])
371
 
        source_tree.add(['a', 'b'])
372
 
        revid1 = source_tree.commit("msg")
373
 
        target_tree = self.make_branch_and_tree("target", 
374
 
            format=DummyForeignVcsDirFormat())
375
 
        target_tree.branch.lock_write()
376
 
        try:
377
 
            pushresult = source_tree.branch.lossy_push(target_tree.branch)
378
 
        finally:
379
 
            target_tree.branch.unlock()
380
 
        self.assertEquals(NULL_REVISION, pushresult.old_revid)
381
 
        self.assertEquals({revid1:target_tree.branch.last_revision()}, 
382
 
                           pushresult.revidmap)
383
 
        self.assertEquals(pushresult.revidmap[revid1], pushresult.new_revid)