~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_delta.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-02-04 15:21:37 UTC
  • mfrom: (1551.10.6 Aaron's mergeable stuff)
  • Revision ID: pqm@pqm.ubuntu.com-20070204152137-9848ed97ad8e6a88
Support kind changes in tree deltas

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
 
17
import os
 
18
from StringIO import StringIO
 
19
 
17
20
from bzrlib import (
18
 
    delta,
 
21
    delta as _mod_delta,
19
22
    inventory,
20
23
    tests,
21
24
    )
45
48
        if old_path is not None:
46
49
            inv.add(inventory.InventoryFile(file_id, old_path,
47
50
                                            inv.root.file_id))
48
 
        reporter = delta.ChangeReporter(inv, result_line)
 
51
        reporter = _mod_delta.ChangeReporter(inv, result_line)
49
52
        reporter.report(file_id, path, versioned_change, renamed, modified,
50
53
                         exe_change, kind)
51
54
        self.assertEqualDiff(expected, result[0])
100
103
                           modified='unchanged',
101
104
                           exe_change=False):
102
105
        reporter = InstrumentedReporter()
103
 
        delta.report_changes([(file_id, path, content_change, versioned,
104
 
                               parent_id, name, kind, executable)], reporter)
 
106
        _mod_delta.report_changes([(file_id, path, content_change, versioned,
 
107
            parent_id, name, kind, executable)], reporter)
105
108
        output = reporter.calls[0]
106
109
        self.assertEqual(file_id, output[0])
107
110
        self.assertEqual(path, output[1])
150
153
                                exe_change=True, versioned=(True, False),
151
154
                                content_change=True, name=('old', 'new'),
152
155
                                executable=(False, True))
 
156
 
 
157
 
 
158
class TestChangesFrom (tests.TestCaseWithTransport):
 
159
 
 
160
    def show_string(self, delta, *args,  **kwargs):
 
161
        to_file = StringIO()
 
162
        delta.show(to_file, *args, **kwargs)
 
163
        return to_file.getvalue()
 
164
 
 
165
    def test_kind_change(self):
 
166
        """Doing a status when a file has changed kind should work"""
 
167
        tree = self.make_branch_and_tree('.')
 
168
        self.build_tree(['filename'])
 
169
        tree.add('filename', 'file-id')
 
170
        tree.commit('added filename')
 
171
        os.unlink('filename')
 
172
        self.build_tree(['filename/'])
 
173
        delta = tree.changes_from(tree.basis_tree())
 
174
        self.assertEqual([('filename', 'file-id', 'file', 'directory')],
 
175
                         delta.kind_changed)
 
176
        self.assertEqual([], delta.added)
 
177
        self.assertEqual([], delta.removed)
 
178
        self.assertEqual([], delta.renamed)
 
179
        self.assertEqual([], delta.modified)
 
180
        self.assertEqual([], delta.unchanged)
 
181
        self.assertTrue(delta.has_changed())
 
182
        self.assertTrue(delta.touches_file_id('file-id'))
 
183
        self.assertEqual('kind changed:\n  filename (file => directory)\n',
 
184
                         self.show_string(delta))
 
185
        other_delta = _mod_delta.TreeDelta()
 
186
        self.assertNotEqual(other_delta, delta)
 
187
        other_delta.kind_changed = [('filename', 'file-id', 'file',
 
188
                                     'symlink')]
 
189
        self.assertNotEqual(other_delta, delta)
 
190
        other_delta.kind_changed = [('filename', 'file-id', 'file',
 
191
                                     'directory')]
 
192
        self.assertEqual(other_delta, delta)
 
193
        self.assertEqualDiff("TreeDelta(added=[], removed=[], renamed=[],"
 
194
            " kind_changed=[(u'filename', 'file-id', 'file', 'directory')],"
 
195
            " modified=[], unchanged=[])", repr(delta))
 
196
        self.assertEqual('K  filename (file => directory) file-id\n',
 
197
                         self.show_string(delta, show_ids=True,
 
198
                         short_status=True))
 
199
 
 
200
        tree.rename_one('filename', 'dirname')
 
201
        delta = tree.changes_from(tree.basis_tree())
 
202
        self.assertEqual([], delta.kind_changed)
 
203
        # This loses the fact that kind changed, remembering it as a
 
204
        # modification
 
205
        self.assertEqual([('filename', 'dirname', 'file-id', 'directory',
 
206
                           True, False)], delta.renamed)
 
207
        self.assertTrue(delta.has_changed())
 
208
        self.assertTrue(delta.touches_file_id('file-id'))