/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/matchers.py

  • Committer: Jelmer Vernooij
  • Date: 2020-05-24 00:39:50 UTC
  • mto: This revision was merged to the branch mainline in revision 7504.
  • Revision ID: jelmer@jelmer.uk-20200524003950-bbc545r76vc5yajg
Add github action.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
    'HasLayout',
31
31
    'HasPathRelations',
32
32
    'MatchesAncestry',
 
33
    'ContainsNoVfsCalls',
33
34
    'ReturnsUnlockable',
34
35
    'RevisionHistoryMatches',
35
36
    ]
38
39
    osutils,
39
40
    revision as _mod_revision,
40
41
    )
41
 
 
42
 
from ..tree import InterTree
 
42
from .. import lazy_import
 
43
lazy_import.lazy_import(globals(),
 
44
                        """
 
45
from breezy.bzr.smart.request import request_handlers as smart_request_handlers
 
46
from breezy.bzr.smart import vfs
 
47
""")
 
48
from ..tree import (
 
49
    find_previous_path,
 
50
    InterTree,
 
51
    )
43
52
 
44
53
from testtools.matchers import Equals, Mismatch, Matcher
45
54
 
269
278
                branch.last_revision(), [_mod_revision.NULL_REVISION]))
270
279
            history.reverse()
271
280
        return Equals(self.expected).match(history)
 
281
 
 
282
 
 
283
class _NoVfsCallsMismatch(Mismatch):
 
284
    """Mismatch describing a list of HPSS calls which includes VFS requests."""
 
285
 
 
286
    def __init__(self, vfs_calls):
 
287
        self.vfs_calls = vfs_calls
 
288
 
 
289
    def describe(self):
 
290
        return "no VFS calls expected, got: %s" % ",".join([
 
291
            "%s(%s)" % (c.method,
 
292
                        ", ".join([repr(a) for a in c.args])) for c in self.vfs_calls])
 
293
 
 
294
 
 
295
class ContainsNoVfsCalls(Matcher):
 
296
    """Ensure that none of the specified calls are HPSS calls."""
 
297
 
 
298
    def __str__(self):
 
299
        return 'ContainsNoVfsCalls()'
 
300
 
 
301
    @classmethod
 
302
    def match(cls, hpss_calls):
 
303
        vfs_calls = []
 
304
        for call in hpss_calls:
 
305
            try:
 
306
                request_method = smart_request_handlers.get(call.call.method)
 
307
            except KeyError:
 
308
                # A method we don't know about doesn't count as a VFS method.
 
309
                continue
 
310
            if issubclass(request_method, vfs.VfsRequest):
 
311
                vfs_calls.append(call.call)
 
312
        if len(vfs_calls) == 0:
 
313
            return None
 
314
        return _NoVfsCallsMismatch(vfs_calls)