~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_foreign.py

  • Committer: John Arbash Meinel
  • Date: 2011-05-11 11:35:28 UTC
  • mto: This revision was merged to the branch mainline in revision 5851.
  • Revision ID: john@arbash-meinel.com-20110511113528-qepibuwxicjrbb2h
Break compatibility with python <2.6.

This includes auditing the code for places where we were doing
explicit 'sys.version' checks and removing them as appropriate.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2008-2011 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
21
21
from bzrlib import (
22
22
    branch,
23
23
    bzrdir,
 
24
    controldir,
24
25
    errors,
25
26
    foreign,
26
27
    lockable_files,
27
28
    lockdir,
 
29
    repository,
28
30
    revision,
29
31
    tests,
30
32
    trace,
 
33
    vf_repository,
31
34
    )
32
35
 
 
36
from bzrlib.repofmt import groupcompress_repo
 
37
 
33
38
# This is the dummy foreign revision control system, used 
34
39
# mainly here in the testsuite to test the foreign VCS infrastructure.
35
40
# It is basically standard Bazaar with some minor modifications to 
91
96
        self._base = a_bzrdir.transport.base
92
97
        self._ignore_fallbacks = False
93
98
        self.bzrdir = a_bzrdir
94
 
        foreign.ForeignBranch.__init__(self, 
 
99
        foreign.ForeignBranch.__init__(self,
95
100
            DummyForeignVcsMapping(DummyForeignVcs()))
96
 
        branch.BzrBranch6.__init__(self, _format, _control_files, a_bzrdir, 
 
101
        branch.BzrBranch6.__init__(self, _format, _control_files, a_bzrdir,
97
102
            *args, **kwargs)
98
103
 
 
104
    def _get_checkout_format(self):
 
105
        """Return the most suitable metadir for a checkout of this branch.
 
106
        Weaves are used if this branch's repository uses weaves.
 
107
        """
 
108
        return self.bzrdir.checkout_metadir()
 
109
 
 
110
    def import_last_revision_info_and_tags(self, source, revno, revid,
 
111
                                           lossy=False):
 
112
        interbranch = InterToDummyVcsBranch(source, self)
 
113
        if lossy:
 
114
            result = interbranch.lossy_push(revid)
 
115
            revid = result.revidmap[revid]
 
116
        else:
 
117
            interbranch.push(revid)
 
118
        return (revno, revid)
 
119
 
 
120
 
 
121
class DummyForeignCommitBuilder(vf_repository.VersionedFileRootCommitBuilder):
 
122
 
 
123
    def _generate_revision_if_needed(self):
 
124
        mapping = DummyForeignVcsMapping(DummyForeignVcs())
 
125
        if self._lossy:
 
126
            self._new_revision_id = mapping.revision_id_foreign_to_bzr(
 
127
                (str(self._timestamp), str(self._timezone), "UNKNOWN"))
 
128
            self.random_revid = False
 
129
        elif self._new_revision_id is not None:
 
130
            self.random_revid = False
 
131
        else:
 
132
            self._new_revision_id = self._gen_revision_id()
 
133
            self.random_revid = True
 
134
 
 
135
 
 
136
class DummyForeignVcsRepository(groupcompress_repo.CHKInventoryRepository,
 
137
    foreign.ForeignRepository):
 
138
    """Dummy foreign vcs repository."""
 
139
 
 
140
 
 
141
class DummyForeignVcsRepositoryFormat(groupcompress_repo.RepositoryFormat2a):
 
142
 
 
143
    repository_class = DummyForeignVcsRepository
 
144
    _commit_builder_class = DummyForeignCommitBuilder
 
145
 
 
146
    def get_format_string(self):
 
147
        return "Dummy Foreign Vcs Repository"
 
148
 
 
149
    def get_format_description(self):
 
150
        return "Dummy Foreign Vcs Repository"
 
151
 
99
152
 
100
153
class InterToDummyVcsBranch(branch.GenericInterBranch,
101
154
                            foreign.InterToForeignBranch):
116
169
        try:
117
170
            # This just handles simple cases, but that's good enough for tests
118
171
            my_history = self.target.revision_history()
119
 
            their_history = self.source.revision_history()
 
172
            if stop_revision is None:
 
173
                stop_revision = self.source.last_revision()
 
174
            their_history = list(self.source.repository.iter_reverse_revision_history(stop_revision))
 
175
            their_history.reverse()
120
176
            if their_history[:min(len(my_history), len(their_history))] != my_history:
121
177
                raise errors.DivergedBranches(self.target, self.source)
122
178
            todo = their_history[len(my_history):]
172
228
        super(DummyForeignVcsBranchFormat, self).__init__()
173
229
        self._matchingbzrdir = DummyForeignVcsDirFormat()
174
230
 
175
 
    def open(self, a_bzrdir, name=None, _found=False):
 
231
    def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
 
232
            found_repository=None):
176
233
        if not _found:
177
234
            raise NotImplementedError
178
235
        try:
179
236
            transport = a_bzrdir.get_branch_transport(None, name=name)
180
237
            control_files = lockable_files.LockableFiles(transport, 'lock',
181
238
                                                         lockdir.LockDir)
 
239
            if found_repository is None:
 
240
                found_repository = a_bzrdir.find_repository()
182
241
            return DummyForeignVcsBranch(_format=self,
183
242
                              _control_files=control_files,
184
243
                              a_bzrdir=a_bzrdir,
185
 
                              _repository=a_bzrdir.find_repository())
 
244
                              _repository=found_repository)
186
245
        except errors.NoSuchFile:
187
246
            raise errors.NotBranchError(path=transport.base)
188
247
 
205
264
    def get_branch_format(self):
206
265
        return DummyForeignVcsBranchFormat()
207
266
 
208
 
    @classmethod
209
 
    def probe_transport(klass, transport):
210
 
        """Return the .bzrdir style format present in a directory."""
211
 
        if not transport.has('.dummy'):
212
 
            raise errors.NotBranchError(path=transport.base)
213
 
        return klass()
 
267
    @property
 
268
    def repository_format(self):
 
269
        return DummyForeignVcsRepositoryFormat()
214
270
 
215
271
    def initialize_on_transport(self, transport):
216
272
        """Initialize a new bzrdir in the base directory of a Transport."""
244
300
        self._control_files = lockable_files.LockableFiles(self.transport,
245
301
            "lock", lockable_files.TransportLock)
246
302
 
 
303
    def create_workingtree(self):
 
304
        # dirstate requires a ".bzr" entry to exist
 
305
        self.root_transport.put_bytes(".bzr", "foo")
 
306
        return super(DummyForeignVcsDir, self).create_workingtree()
 
307
 
247
308
    def open_branch(self, name=None, unsupported=False, ignore_fallbacks=True):
248
309
        if name is not None:
249
310
            raise errors.NoColocatedBranchSupport(self)
253
314
        """Produce a metadir suitable for cloning with."""
254
315
        return bzrdir.format_registry.make_bzrdir("default")
255
316
 
 
317
    def checkout_metadir(self):
 
318
        return self.cloning_metadir()
 
319
 
256
320
    def sprout(self, url, revision_id=None, force_new_repo=False,
257
321
               recurse='down', possible_transports=None,
258
322
               accelerator_tree=None, hardlink=False, stacked=False,
266
330
 
267
331
 
268
332
def register_dummy_foreign_for_test(testcase):
269
 
    bzrdir.BzrDirFormat.register_control_format(DummyForeignVcsDirFormat)
270
 
    testcase.addCleanup(bzrdir.BzrDirFormat.unregister_control_format,
271
 
                        DummyForeignVcsDirFormat)
 
333
    controldir.ControlDirFormat.register_prober(DummyForeignProber)
 
334
    testcase.addCleanup(controldir.ControlDirFormat.unregister_prober,
 
335
        DummyForeignProber)
 
336
    repository.format_registry.register(DummyForeignVcsRepositoryFormat())
 
337
    testcase.addCleanup(repository.format_registry.remove,
 
338
            DummyForeignVcsRepositoryFormat())
 
339
    branch.format_registry.register(DummyForeignVcsBranchFormat())
 
340
    testcase.addCleanup(branch.format_registry.remove,
 
341
            DummyForeignVcsBranchFormat())
272
342
    # We need to register the optimiser to make the dummy appears really
273
343
    # different from a regular bzr repository.
274
344
    branch.InterBranch.register_optimiser(InterToDummyVcsBranch)
276
346
                        InterToDummyVcsBranch)
277
347
 
278
348
 
 
349
class DummyForeignProber(controldir.Prober):
 
350
 
 
351
    @classmethod
 
352
    def probe_transport(klass, transport):
 
353
        """Return the .bzrdir style format present in a directory."""
 
354
        if not transport.has('.dummy'):
 
355
            raise errors.NotBranchError(path=transport.base)
 
356
        return DummyForeignVcsDirFormat()
 
357
 
 
358
    @classmethod
 
359
    def known_formats(cls):
 
360
        return set([DummyForeignVcsDirFormat()])
 
361
 
 
362
 
279
363
class ForeignVcsRegistryTests(tests.TestCase):
280
364
    """Tests for the ForeignVcsRegistry class."""
281
365
 
293
377
        reg = foreign.ForeignVcsRegistry()
294
378
        vcs = DummyForeignVcs()
295
379
        reg.register("dummy", vcs, "Dummy VCS")
296
 
        self.assertEquals((("some", "foreign", "revid"), DummyForeignVcsMapping(vcs)),
297
 
                          reg.parse_revision_id("dummy-v1:some-foreign-revid"))
 
380
        self.assertEquals((
 
381
            ("some", "foreign", "revid"), DummyForeignVcsMapping(vcs)),
 
382
            reg.parse_revision_id("dummy-v1:some-foreign-revid"))
298
383
 
299
384
 
300
385
class ForeignRevisionTests(tests.TestCase):