~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/matchers.py

  • Committer: Patch Queue Manager
  • Date: 2011-12-14 12:53:59 UTC
  • mfrom: (6352.2.5 hpss-no-vfs)
  • Revision ID: pqm@pqm.ubuntu.com-20111214125359-l2d2nv046utd1vfz
(jelmer) Add ContainsNoVfsCalls matcher. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
__all__ = [
30
30
    'HasLayout',
31
31
    'MatchesAncestry',
 
32
    'ContainsNoVfsCalls',
32
33
    'ReturnsUnlockable',
33
34
    ]
34
35
 
36
37
    osutils,
37
38
    revision as _mod_revision,
38
39
    )
 
40
from bzrlib import lazy_import
 
41
lazy_import.lazy_import(globals(),
 
42
"""
 
43
from bzrlib.smart.request import request_handlers as smart_request_handlers
 
44
from bzrlib.smart import vfs
 
45
""")
39
46
 
40
47
from testtools.matchers import Equals, Mismatch, Matcher
41
48
 
175
182
        else:
176
183
            entries = self.entries
177
184
        return Equals(entries).match(actual)
 
185
 
 
186
 
 
187
class _NoVfsCallsMismatch(Mismatch):
 
188
    """Mismatch describing a list of HPSS calls which includes VFS requests."""
 
189
 
 
190
    def __init__(self, vfs_calls):
 
191
        self.vfs_calls = vfs_calls
 
192
 
 
193
    def describe(self):
 
194
        return "no VFS calls expected, got: %s" % ",".join([
 
195
            "%s(%s)" % (c.method,
 
196
                ", ".join([repr(a) for a in c.args])) for c in self.vfs_calls])
 
197
 
 
198
 
 
199
class ContainsNoVfsCalls(Matcher):
 
200
    """Ensure that none of the specified calls are HPSS calls."""
 
201
 
 
202
    def __str__(self):
 
203
        return 'ContainsNoVfsCalls()'
 
204
 
 
205
    @classmethod
 
206
    def match(cls, hpss_calls):
 
207
        vfs_calls = []
 
208
        for call in hpss_calls:
 
209
            try:
 
210
                request_method = smart_request_handlers.get(call.call.method)
 
211
            except KeyError:
 
212
                # A method we don't know about doesn't count as a VFS method.
 
213
                continue
 
214
            if issubclass(request_method, vfs.VfsRequest):
 
215
                vfs_calls.append(call.call)
 
216
        if len(vfs_calls) == 0:
 
217
            return None
 
218
        return _NoVfsCallsMismatch(vfs_calls)