~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/matchers.py

  • Committer: Jelmer Vernooij
  • Date: 2011-10-20 16:04:35 UTC
  • mto: (6437.3.11 2.5)
  • mto: This revision was merged to the branch mainline in revision 6444.
  • Revision ID: jelmer@samba.org-20111020160435-j5z353cvzdhge8n3
Add RevisionHistoryMatches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
    'HasLayout',
31
31
    'MatchesAncestry',
32
32
    'ReturnsUnlockable',
 
33
    'RevisionHistoryMatches',
33
34
    ]
34
35
 
35
36
from bzrlib import (
175
176
        else:
176
177
            entries = self.entries
177
178
        return Equals(entries).match(actual)
 
179
 
 
180
 
 
181
class RevisionHistoryMatches(Matcher):
 
182
    """A matcher that checks if a branch has a specific revision history.
 
183
 
 
184
    :ivar history: Revision history, as list of revisions. Oldest first.
 
185
    """
 
186
 
 
187
    def __init__(self, history):
 
188
        Matcher.__init__(self)
 
189
        self.expected = history
 
190
 
 
191
    def __str__(self):
 
192
        return 'RevisionHistoryMatches(%r)' % self.expected
 
193
 
 
194
    def match(self, branch):
 
195
        branch.lock_read()
 
196
        try:
 
197
            graph = branch.repository.get_graph()
 
198
            history = list(graph.iter_lefthand_ancestry(
 
199
                branch.last_revision(), [_mod_revision.NULL_REVISION]))
 
200
            history.reverse()
 
201
        finally:
 
202
            branch.unlock()
 
203
        return Equals(self.expected).match(history)