67
81
def describe(self):
68
82
return "%s is locked" % self.lockable_thing
85
class _AncestryMismatch(Mismatch):
86
"""Ancestry matching mismatch."""
88
def __init__(self, tip_revision, got, expected):
89
self.tip_revision = tip_revision
91
self.expected = expected
94
return "mismatched ancestry for revision %r was %r, expected %r" % (
95
self.tip_revision, self.got, self.expected)
98
class MatchesAncestry(Matcher):
99
"""A matcher that checks the ancestry of a particular revision.
101
:ivar graph: Graph in which to check the ancestry
102
:ivar revision_id: Revision id of the revision
105
def __init__(self, repository, revision_id):
106
Matcher.__init__(self)
107
self.repository = repository
108
self.revision_id = revision_id
111
return ('MatchesAncestry(repository=%r, revision_id=%r)' % (
112
self.repository, self.revision_id))
114
def match(self, expected):
115
self.repository.lock_read()
117
graph = self.repository.get_graph()
118
got = [r for r, p in graph.iter_ancestry([self.revision_id])]
119
if _mod_revision.NULL_REVISION in got:
120
got.remove(_mod_revision.NULL_REVISION)
122
self.repository.unlock()
123
if sorted(got) != sorted(expected):
124
return _AncestryMismatch(self.revision_id, sorted(got),
128
class HasLayout(Matcher):
129
"""A matcher that checks if a tree has a specific layout.
131
:ivar entries: List of expected entries, as (path, file_id) pairs.
134
def __init__(self, entries):
135
Matcher.__init__(self)
136
self.entries = entries
138
def get_tree_layout(self, tree):
139
"""Get the (path, file_id) pairs for the current tree."""
142
for path, ie in tree.iter_entries_by_dir():
143
if ie.parent_id is None:
144
yield (u"", ie.file_id)
146
yield (path+ie.kind_character(), ie.file_id)
151
def _strip_unreferenced_directories(entries):
152
"""Strip all directories that don't (in)directly contain any files.
154
:param entries: List of path strings or (path, ie) tuples to process
157
for entry in entries:
158
if isinstance(entry, basestring):
162
if not path or path[-1] == "/":
164
directories.append((path, entry))
166
# Yield the referenced parent directories
167
for dirpath, direntry in directories:
168
if osutils.is_inside(dirpath, path):
174
return 'HasLayout(%r)' % self.entries
176
def match(self, tree):
177
actual = list(self.get_tree_layout(tree))
178
if self.entries and isinstance(self.entries[0], basestring):
179
actual = [path for (path, fileid) in actual]
180
if not tree.has_versioned_directories():
181
entries = list(self._strip_unreferenced_directories(self.entries))
183
entries = self.entries
184
return Equals(entries).match(actual)
187
class _NoVfsCallsMismatch(Mismatch):
188
"""Mismatch describing a list of HPSS calls which includes VFS requests."""
190
def __init__(self, vfs_calls):
191
self.vfs_calls = vfs_calls
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])
199
class ContainsNoVfsCalls(Matcher):
200
"""Ensure that none of the specified calls are HPSS calls."""
203
return 'ContainsNoVfsCalls()'
206
def match(cls, hpss_calls):
208
for call in hpss_calls:
210
request_method = smart_request_handlers.get(call.call.method)
212
# A method we don't know about doesn't count as a VFS method.
214
if issubclass(request_method, vfs.VfsRequest):
215
vfs_calls.append(call.call)
216
if len(vfs_calls) == 0:
218
return _NoVfsCallsMismatch(vfs_calls)