~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_rename_map.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-01 08:02:42 UTC
  • mfrom: (5390.3.3 faster-revert-593560)
  • Revision ID: pqm@pqm.ubuntu.com-20100901080242-esg62ody4frwmy66
(spiv) Avoid repeatedly calling self.target.all_file_ids() in
 InterTree.iter_changes. (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
import os
19
19
 
 
20
from bzrlib import trace
20
21
from bzrlib.rename_map import RenameMap
21
22
from bzrlib.tests import TestCaseWithTransport
22
23
 
149
150
        """When a directory has been moved, its children are preserved."""
150
151
        tree = self.make_branch_and_tree('tree')
151
152
        tree.lock_write()
 
153
        self.addCleanup(tree.unlock)
152
154
        self.build_tree_contents([('tree/foo/', ''),
153
155
                                  ('tree/foo/bar', 'bar'),
154
156
                                  ('tree/foo/empty', '')])
158
160
        os.rename('tree/foo', 'tree/baz')
159
161
        RenameMap.guess_renames(tree)
160
162
        self.assertEqual('baz/empty', tree.id2path('empty-id'))
 
163
 
 
164
    def test_guess_renames_dry_run(self):
 
165
        tree = self.make_branch_and_tree('tree')
 
166
        tree.lock_write()
 
167
        self.addCleanup(tree.unlock)
 
168
        self.build_tree(['tree/file'])
 
169
        tree.add('file', 'file-id')
 
170
        tree.commit('Added file')
 
171
        os.rename('tree/file', 'tree/file2')
 
172
        RenameMap.guess_renames(tree, dry_run=True)
 
173
        self.assertEqual('file', tree.id2path('file-id'))
 
174
 
 
175
    @staticmethod
 
176
    def captureNotes(cmd, *args, **kwargs):
 
177
        notes = []
 
178
        def my_note(fmt, *args):
 
179
            notes.append(fmt % args)
 
180
        old_note = trace.note
 
181
        trace.note = my_note
 
182
        try:
 
183
            result = cmd(*args, **kwargs)
 
184
        finally:
 
185
            trace.note = old_note
 
186
        return notes, result
 
187
 
 
188
    def test_guess_renames_output(self):
 
189
        """guess_renames emits output whether dry_run is True or False."""
 
190
        tree = self.make_branch_and_tree('tree')
 
191
        tree.lock_write()
 
192
        self.addCleanup(tree.unlock)
 
193
        self.build_tree(['tree/file'])
 
194
        tree.add('file', 'file-id')
 
195
        tree.commit('Added file')
 
196
        os.rename('tree/file', 'tree/file2')
 
197
        notes = self.captureNotes(RenameMap.guess_renames, tree,
 
198
                                  dry_run=True)[0]
 
199
        self.assertEqual('file => file2', ''.join(notes))
 
200
        notes = self.captureNotes(RenameMap.guess_renames, tree,
 
201
                                  dry_run=False)[0]
 
202
        self.assertEqual('file => file2', ''.join(notes))