~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/matchers.py

  • Committer: Jelmer Vernooij
  • Date: 2011-08-29 21:53:33 UTC
  • mto: This revision was merged to the branch mainline in revision 6119.
  • Revision ID: jelmer@samba.org-20110829215333-t7b6up4hgzf2jfws
In HasLayout, take into consideration Tree.has_versioned_directories.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
    ]
34
34
 
35
35
from bzrlib import (
 
36
    osutils,
36
37
    revision as _mod_revision,
37
38
    )
38
39
 
54
55
        self.lockable_thing = lockable_thing
55
56
 
56
57
    def __str__(self):
57
 
        return ('ReturnsUnlockable(lockable_thing=%s)' % 
 
58
        return ('ReturnsUnlockable(lockable_thing=%s)' %
58
59
            self.lockable_thing)
59
60
 
60
61
    def match(self, lock_method):
131
132
        """Get the (path, file_id) pairs for the current tree."""
132
133
        tree.lock_read()
133
134
        try:
134
 
            return [(path, ie.file_id) for path, ie
135
 
                    in tree.iter_entries_by_dir()]
 
135
            for path, ie in tree.iter_entries_by_dir():
 
136
                if ie.parent_id is None:
 
137
                    yield (u"", ie.file_id)
 
138
                else:
 
139
                    yield (path+ie.kind_character(), ie.file_id)
136
140
        finally:
137
141
            tree.unlock()
138
142
 
 
143
    @staticmethod
 
144
    def _strip_unreferenced_directories(entries):
 
145
        directories = []
 
146
        for entry in entries:
 
147
            if isinstance(entry, basestring):
 
148
                path = entry
 
149
            else:
 
150
                path = entry[0]
 
151
            if path == u"" or path[-1] == "/":
 
152
                # directory
 
153
                directories.append((path, entry))
 
154
            else:
 
155
                # Yield the referenced parent directories
 
156
                for dirpath, direntry in directories:
 
157
                    if osutils.is_inside(dirpath, path):
 
158
                        yield direntry
 
159
                directories = []
 
160
                yield entry
 
161
 
139
162
    def __str__(self):
140
 
        return ('HasLayout(%r)' % self.entries)
 
163
        return 'HasLayout(%r)' % self.entries
141
164
 
142
165
    def match(self, tree):
143
 
        actual = self.get_tree_layout(tree)
 
166
        actual = list(self.get_tree_layout(tree))
144
167
        if self.entries and isinstance(self.entries[0], basestring):
145
168
            actual = [path for (path, fileid) in actual]
146
 
        return Equals(actual).match(self.entries)
 
169
        if not tree.has_versioned_directories():
 
170
            entries = list(self._strip_unreferenced_directories(self.entries))
 
171
        else:
 
172
            entries = self.entries
 
173
        return Equals(actual).match(entries)