~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_foreign.py

  • Committer: Vincent Ladeuil
  • Date: 2015-09-08 07:59:37 UTC
  • mto: This revision was merged to the branch mainline in revision 6604.
  • Revision ID: v.ladeuil+lp@free.fr-20150908075937-u63hgo67v3c2lapt
Skip the missed test in test_transport.

Show diffs side-by-side

added added

removed removed

Lines of Context:
91
91
class DummyForeignVcsBranch(branch.BzrBranch6,foreign.ForeignBranch):
92
92
    """A Dummy VCS Branch."""
93
93
 
 
94
    @property
 
95
    def user_transport(self):
 
96
        return self.bzrdir.user_transport
 
97
 
94
98
    def __init__(self, _format, _control_files, a_bzrdir, *args, **kwargs):
95
99
        self._format = _format
96
100
        self._base = a_bzrdir.transport.base
101
105
        branch.BzrBranch6.__init__(self, _format, _control_files, a_bzrdir,
102
106
            *args, **kwargs)
103
107
 
104
 
    def _get_checkout_format(self):
 
108
    def _get_checkout_format(self, lightweight=False):
105
109
        """Return the most suitable metadir for a checkout of this branch.
106
110
        Weaves are used if this branch's repository uses weaves.
107
111
        """
141
145
    repository_class = DummyForeignVcsRepository
142
146
    _commit_builder_class = DummyForeignCommitBuilder
143
147
 
144
 
    def get_format_string(self):
 
148
    @classmethod
 
149
    def get_format_string(cls):
145
150
        return "Dummy Foreign Vcs Repository"
146
151
 
147
152
    def get_format_description(self):
148
153
        return "Dummy Foreign Vcs Repository"
149
154
 
150
155
 
 
156
def branch_history(graph, revid):
 
157
    ret = list(graph.iter_lefthand_ancestry(revid,
 
158
        (revision.NULL_REVISION,)))
 
159
    ret.reverse()
 
160
    return ret
 
161
 
 
162
 
151
163
class InterToDummyVcsBranch(branch.GenericInterBranch):
152
164
 
153
165
    @staticmethod
165
177
        try:
166
178
            graph = self.source.repository.get_graph()
167
179
            # This just handles simple cases, but that's good enough for tests
168
 
            my_history = self.target.revision_history()
 
180
            my_history = branch_history(self.target.repository.get_graph(),
 
181
                result.old_revid)
169
182
            if stop_revision is None:
170
183
                stop_revision = self.source.last_revision()
171
 
            their_history = list(graph.iter_lefthand_ancestry(stop_revision,
172
 
                (revision.NULL_REVISION,)))
173
 
            their_history.reverse()
 
184
            their_history = branch_history(graph, stop_revision)
174
185
            if their_history[:min(len(my_history), len(their_history))] != my_history:
175
186
                raise errors.DivergedBranches(self.target, self.source)
176
187
            todo = their_history[len(my_history):]
190
201
                else:
191
202
                    parent_revids = [parent_revid]
192
203
                builder = self.target.get_commit_builder(parent_revids, 
193
 
                        self.target.get_config(), rev.timestamp,
 
204
                        self.target.get_config_stack(), rev.timestamp,
194
205
                        rev.timezone, rev.committer, rev.properties,
195
206
                        new_revid)
196
207
                try:
197
 
                    for path, ie in tree.inventory.iter_entries():
 
208
                    parent_tree = self.target.repository.revision_tree(
 
209
                        parent_revid)
 
210
                    for path, ie in tree.iter_entries_by_dir():
198
211
                        new_ie = ie.copy()
199
212
                        new_ie.revision = None
200
213
                        builder.record_entry_contents(new_ie, 
201
 
                            [self.target.repository.revision_tree(parent_revid).inventory],
 
214
                            [parent_tree.root_inventory],
202
215
                            path, tree, 
203
216
                            (ie.kind, ie.text_size, ie.executable, ie.text_sha1))
204
217
                    builder.finish_inventory()
219
232
 
220
233
class DummyForeignVcsBranchFormat(branch.BzrBranchFormat6):
221
234
 
222
 
    def get_format_string(self):
 
235
    @classmethod
 
236
    def get_format_string(cls):
223
237
        return "Branch for Testing"
224
238
 
225
 
    def __init__(self):
226
 
        super(DummyForeignVcsBranchFormat, self).__init__()
227
 
        self._matchingbzrdir = DummyForeignVcsDirFormat()
 
239
    @property
 
240
    def _matchingbzrdir(self):
 
241
        return DummyForeignVcsDirFormat()
228
242
 
229
243
    def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
230
244
            found_repository=None):
 
245
        if name is None:
 
246
            name = a_bzrdir._get_selected_branch()
231
247
        if not _found:
232
248
            raise NotImplementedError
233
249
        try:
239
255
            return DummyForeignVcsBranch(_format=self,
240
256
                              _control_files=control_files,
241
257
                              a_bzrdir=a_bzrdir,
242
 
                              _repository=found_repository)
 
258
                              _repository=found_repository,
 
259
                              name=name)
243
260
        except errors.NoSuchFile:
244
261
            raise errors.NotBranchError(path=transport.base)
245
262
 
303
320
        self.root_transport.put_bytes(".bzr", "foo")
304
321
        return super(DummyForeignVcsDir, self).create_workingtree()
305
322
 
306
 
    def open_branch(self, name=None, unsupported=False, ignore_fallbacks=True):
307
 
        if name is not None:
 
323
    def open_branch(self, name=None, unsupported=False, ignore_fallbacks=True,
 
324
            possible_transports=None):
 
325
        if name is None:
 
326
            name = self._get_selected_branch()
 
327
        if name != "":
308
328
            raise errors.NoColocatedBranchSupport(self)
309
329
        return self._format.get_branch_format().open(self, _found=True)
310
330
 
311
331
    def cloning_metadir(self, stacked=False):
312
332
        """Produce a metadir suitable for cloning with."""
313
 
        return bzrdir.format_registry.make_bzrdir("default")
 
333
        return controldir.format_registry.make_bzrdir("default")
314
334
 
315
335
    def checkout_metadir(self):
316
336
        return self.cloning_metadir()
411
431
        foreign.update_workingtree_fileids(wt, target_basis)
412
432
        wt.lock_read()
413
433
        try:
414
 
            self.assertEquals(set([root_id, "bla-b"]), set(wt.inventory))
 
434
            self.assertEquals(set([root_id, "bla-b"]), set(wt.all_file_ids()))
415
435
        finally:
416
436
            wt.unlock()
417
437
 
426
446
    def test_create(self):
427
447
        """Test we can create dummies."""
428
448
        self.make_branch_and_tree("d", format=DummyForeignVcsDirFormat())
429
 
        dir = bzrdir.BzrDir.open("d")
 
449
        dir = controldir.ControlDir.open("d")
430
450
        self.assertEquals("A Dummy VCS Dir", dir._format.get_format_string())
431
451
        dir.open_repository()
432
452
        dir.open_branch()
435
455
    def test_sprout(self):
436
456
        """Test we can clone dummies and that the format is not preserved."""
437
457
        self.make_branch_and_tree("d", format=DummyForeignVcsDirFormat())
438
 
        dir = bzrdir.BzrDir.open("d")
 
458
        dir = controldir.ControlDir.open("d")
439
459
        newdir = dir.sprout("e")
440
460
        self.assertNotEquals("A Dummy VCS Dir",
441
461
                             newdir._format.get_format_string())
465
485
            format=DummyForeignVcsDirFormat())
466
486
        target_tree.branch.lock_write()
467
487
        try:
468
 
            pushresult = source_tree.branch.push(target_tree.branch, lossy=True)
 
488
            pushresult = source_tree.branch.push(
 
489
                target_tree.branch, lossy=True)
469
490
        finally:
470
491
            target_tree.branch.unlock()
471
492
        self.assertEquals(revision.NULL_REVISION, pushresult.old_revid)