~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: 2009-04-02 16:35:02 UTC
  • mfrom: (3193.8.39 guess-renames)
  • Revision ID: pqm@pqm.ubuntu.com-20090402163502-ryn8zr2giilw5bki
(abentley) Change guess-renames to mv --auto, add --dry-run

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
 
158
159
        os.rename('tree/foo', 'tree/baz')
159
160
        RenameMap.guess_renames(tree)
160
161
        self.assertEqual('baz/empty', tree.id2path('empty-id'))
 
162
 
 
163
    def test_guess_renames_dry_run(self):
 
164
        tree = self.make_branch_and_tree('tree')
 
165
        tree.lock_write()
 
166
        self.addCleanup(tree.unlock)
 
167
        self.build_tree(['tree/file'])
 
168
        tree.add('file', 'file-id')
 
169
        tree.commit('Added file')
 
170
        os.rename('tree/file', 'tree/file2')
 
171
        RenameMap.guess_renames(tree, dry_run=True)
 
172
        self.assertEqual('file', tree.id2path('file-id'))
 
173
 
 
174
    @staticmethod
 
175
    def captureNotes(cmd, *args, **kwargs):
 
176
        notes = []
 
177
        def my_note(fmt, *args):
 
178
            notes.append(fmt % args)
 
179
        old_note = trace.note
 
180
        trace.note = my_note
 
181
        try:
 
182
            result = cmd(*args, **kwargs)
 
183
        finally:
 
184
            trace.note = old_note
 
185
        return notes, result
 
186
 
 
187
    def test_guess_renames_output(self):
 
188
        """guess_renames emits output whether dry_run is True or False."""
 
189
        tree = self.make_branch_and_tree('tree')
 
190
        tree.lock_write()
 
191
        self.addCleanup(tree.unlock)
 
192
        self.build_tree(['tree/file'])
 
193
        tree.add('file', 'file-id')
 
194
        tree.commit('Added file')
 
195
        os.rename('tree/file', 'tree/file2')
 
196
        notes = self.captureNotes(RenameMap.guess_renames, tree,
 
197
                                  dry_run=True)[0]
 
198
        self.assertEqual('file => file2', ''.join(notes))
 
199
        notes = self.captureNotes(RenameMap.guess_renames, tree,
 
200
                                  dry_run=False)[0]
 
201
        self.assertEqual('file => file2', ''.join(notes))