~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_delta.py

  • Committer: Robert Collins
  • Date: 2007-02-06 23:53:30 UTC
  • mfrom: (2268 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2274.
  • Revision ID: robertc@robertcollins.net-20070206235330-2sy67ccuq0ksubqa
Merge HEAD.

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])
53
56
    def test_rename(self):
54
57
        self.assertReport('R   old => path', renamed=True, old_path='old')
55
58
        self.assertReport('    path')
 
59
        self.assertReport('RN  old => path', renamed=True, old_path='old',
 
60
                          modified='created', kind=(None, 'file'))
56
61
 
57
62
    def test_kind(self):
58
63
        self.assertReport(' K  path => path/', modified='kind changed',
67
72
                          kind=(None, 'directory'))
68
73
        self.assertReport('+   path/', versioned_change='added',
69
74
                          modified='unchanged', kind=(None, 'directory'))
 
75
        self.assertReport('+   path', versioned_change='added',
 
76
                          modified='unchanged', kind=(None, None))
70
77
        self.assertReport('+N  path/', versioned_change='added',
71
78
                          modified='created', kind=(None, 'directory'))
72
79
        self.assertReport('+M  path/', versioned_change='added',
100
107
                           modified='unchanged',
101
108
                           exe_change=False):
102
109
        reporter = InstrumentedReporter()
103
 
        delta.report_changes([(file_id, path, content_change, versioned,
104
 
                               parent_id, name, kind, executable)], reporter)
 
110
        _mod_delta.report_changes([(file_id, path, content_change, versioned,
 
111
            parent_id, name, kind, executable)], reporter)
105
112
        output = reporter.calls[0]
106
113
        self.assertEqual(file_id, output[0])
107
114
        self.assertEqual(path, output[1])
150
157
                                exe_change=True, versioned=(True, False),
151
158
                                content_change=True, name=('old', 'new'),
152
159
                                executable=(False, True))
 
160
 
 
161
 
 
162
class TestChangesFrom (tests.TestCaseWithTransport):
 
163
 
 
164
    def show_string(self, delta, *args,  **kwargs):
 
165
        to_file = StringIO()
 
166
        delta.show(to_file, *args, **kwargs)
 
167
        return to_file.getvalue()
 
168
 
 
169
    def test_kind_change(self):
 
170
        """Doing a status when a file has changed kind should work"""
 
171
        tree = self.make_branch_and_tree('.')
 
172
        self.build_tree(['filename'])
 
173
        tree.add('filename', 'file-id')
 
174
        tree.commit('added filename')
 
175
        os.unlink('filename')
 
176
        self.build_tree(['filename/'])
 
177
        delta = tree.changes_from(tree.basis_tree())
 
178
        self.assertEqual([('filename', 'file-id', 'file', 'directory')],
 
179
                         delta.kind_changed)
 
180
        self.assertEqual([], delta.added)
 
181
        self.assertEqual([], delta.removed)
 
182
        self.assertEqual([], delta.renamed)
 
183
        self.assertEqual([], delta.modified)
 
184
        self.assertEqual([], delta.unchanged)
 
185
        self.assertTrue(delta.has_changed())
 
186
        self.assertTrue(delta.touches_file_id('file-id'))
 
187
        self.assertEqual('kind changed:\n  filename (file => directory)\n',
 
188
                         self.show_string(delta))
 
189
        other_delta = _mod_delta.TreeDelta()
 
190
        self.assertNotEqual(other_delta, delta)
 
191
        other_delta.kind_changed = [('filename', 'file-id', 'file',
 
192
                                     'symlink')]
 
193
        self.assertNotEqual(other_delta, delta)
 
194
        other_delta.kind_changed = [('filename', 'file-id', 'file',
 
195
                                     'directory')]
 
196
        self.assertEqual(other_delta, delta)
 
197
        self.assertEqualDiff("TreeDelta(added=[], removed=[], renamed=[],"
 
198
            " kind_changed=[(u'filename', 'file-id', 'file', 'directory')],"
 
199
            " modified=[], unchanged=[])", repr(delta))
 
200
        self.assertEqual('K  filename (file => directory) file-id\n',
 
201
                         self.show_string(delta, show_ids=True,
 
202
                         short_status=True))
 
203
 
 
204
        tree.rename_one('filename', 'dirname')
 
205
        delta = tree.changes_from(tree.basis_tree())
 
206
        self.assertEqual([], delta.kind_changed)
 
207
        # This loses the fact that kind changed, remembering it as a
 
208
        # modification
 
209
        self.assertEqual([('filename', 'dirname', 'file-id', 'directory',
 
210
                           True, False)], delta.renamed)
 
211
        self.assertTrue(delta.has_changed())
 
212
        self.assertTrue(delta.touches_file_id('file-id'))