32
33
'ReturnsUnlockable',
34
'RevisionHistoryMatches',
35
37
from bzrlib import (
37
39
revision as _mod_revision,
41
from bzrlib import lazy_import
42
lazy_import.lazy_import(globals(),
44
from bzrlib.smart.request import request_handlers as smart_request_handlers
45
from bzrlib.smart import vfs
40
48
from testtools.matchers import Equals, Mismatch, Matcher
176
184
entries = self.entries
177
185
return Equals(entries).match(actual)
188
class RevisionHistoryMatches(Matcher):
189
"""A matcher that checks if a branch has a specific revision history.
191
:ivar history: Revision history, as list of revisions. Oldest first.
194
def __init__(self, history):
195
Matcher.__init__(self)
196
self.expected = history
199
return 'RevisionHistoryMatches(%r)' % self.expected
201
def match(self, branch):
204
graph = branch.repository.get_graph()
205
history = list(graph.iter_lefthand_ancestry(
206
branch.last_revision(), [_mod_revision.NULL_REVISION]))
210
return Equals(self.expected).match(history)
213
class _NoVfsCallsMismatch(Mismatch):
214
"""Mismatch describing a list of HPSS calls which includes VFS requests."""
216
def __init__(self, vfs_calls):
217
self.vfs_calls = vfs_calls
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])
225
class ContainsNoVfsCalls(Matcher):
226
"""Ensure that none of the specified calls are HPSS calls."""
229
return 'ContainsNoVfsCalls()'
232
def match(cls, hpss_calls):
234
for call in hpss_calls:
236
request_method = smart_request_handlers.get(call.call.method)
238
# A method we don't know about doesn't count as a VFS method.
240
if issubclass(request_method, vfs.VfsRequest):
241
vfs_calls.append(call.call)
242
if len(vfs_calls) == 0:
244
return _NoVfsCallsMismatch(vfs_calls)