~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/matchers.py

  • Committer: Jelmer Vernooij
  • Date: 2012-01-06 22:44:57 UTC
  • mfrom: (6436 +trunk)
  • mto: (6437.3.11 2.5)
  • mto: This revision was merged to the branch mainline in revision 6444.
  • Revision ID: jelmer@samba.org-20120106224457-re0pcy0fz31xob77
Merge bzr.dev.

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
    'RevisionHistoryMatches',
34
35
    ]
37
38
    osutils,
38
39
    revision as _mod_revision,
39
40
    )
 
41
from bzrlib import lazy_import
 
42
lazy_import.lazy_import(globals(),
 
43
"""
 
44
from bzrlib.smart.request import request_handlers as smart_request_handlers
 
45
from bzrlib.smart import vfs
 
46
""")
40
47
 
41
48
from testtools.matchers import Equals, Mismatch, Matcher
42
49
 
201
208
        finally:
202
209
            branch.unlock()
203
210
        return Equals(self.expected).match(history)
 
211
 
 
212
 
 
213
class _NoVfsCallsMismatch(Mismatch):
 
214
    """Mismatch describing a list of HPSS calls which includes VFS requests."""
 
215
 
 
216
    def __init__(self, vfs_calls):
 
217
        self.vfs_calls = vfs_calls
 
218
 
 
219
    def describe(self):
 
220
        return "no VFS calls expected, got: %s" % ",".join([
 
221
            "%s(%s)" % (c.method,
 
222
                ", ".join([repr(a) for a in c.args])) for c in self.vfs_calls])
 
223
 
 
224
 
 
225
class ContainsNoVfsCalls(Matcher):
 
226
    """Ensure that none of the specified calls are HPSS calls."""
 
227
 
 
228
    def __str__(self):
 
229
        return 'ContainsNoVfsCalls()'
 
230
 
 
231
    @classmethod
 
232
    def match(cls, hpss_calls):
 
233
        vfs_calls = []
 
234
        for call in hpss_calls:
 
235
            try:
 
236
                request_method = smart_request_handlers.get(call.call.method)
 
237
            except KeyError:
 
238
                # A method we don't know about doesn't count as a VFS method.
 
239
                continue
 
240
            if issubclass(request_method, vfs.VfsRequest):
 
241
                vfs_calls.append(call.call)
 
242
        if len(vfs_calls) == 0:
 
243
            return None
 
244
        return _NoVfsCallsMismatch(vfs_calls)