37
40
class TestReportChanges(tests.TestCase):
38
41
"""Test the new change reporting infrastructure"""
40
def assertReport(self, expected, file_id='fid', path='path',
43
def assertReport(self, expected, file_id=b'fid', path='path',
41
44
versioned_change='unchanged', renamed=False,
42
45
modified='unchanged', exe_change=False,
43
46
kind=('file', 'file'), old_path=None,
123
125
renamed=False, modified='created', exe_change=False,
124
126
kind=(None, 'file'), unversioned_filter=lambda x:True)
128
def test_missing(self):
129
self.assertReport('+! missing.c', file_id=None, path='missing.c',
130
old_path=None, versioned_change='added',
131
renamed=False, modified='missing', exe_change=False,
126
134
def test_view_filtering(self):
127
135
# If a file in within the view, it should appear in the output
128
136
expected_lines = [
129
137
"Operating on whole tree but only reporting on 'my' view.",
131
139
self.assertReportLines(expected_lines, modified='modified',
132
view_info=('my',['path']))
140
view_info=('my', ['path']))
133
141
# If a file in outside the view, it should not appear in the output
134
142
expected_lines = [
135
143
"Operating on whole tree but only reporting on 'my' view."]
136
144
self.assertReportLines(expected_lines, modified='modified',
137
path="foo", view_info=('my',['path']))
145
path="foo", view_info=('my', ['path']))
139
147
def assertChangesEqual(self,
141
149
paths=('path', 'path'),
142
150
content_change=False,
143
151
versioned=(True, True),
228
236
"""Doing a status when a file has changed kind should work"""
229
237
tree = self.make_branch_and_tree('.')
230
238
self.build_tree(['filename'])
231
tree.add('filename', 'file-id')
239
tree.add('filename', b'file-id')
232
240
tree.commit('added filename')
233
241
os.unlink('filename')
234
242
self.build_tree(['filename/'])
235
243
delta = tree.changes_from(tree.basis_tree())
236
self.assertEqual([('filename', 'file-id', 'file', 'directory')],
244
self.assertEqual([('filename', b'file-id', 'file', 'directory')],
237
245
delta.kind_changed)
238
246
self.assertEqual([], delta.added)
239
247
self.assertEqual([], delta.removed)
241
249
self.assertEqual([], delta.modified)
242
250
self.assertEqual([], delta.unchanged)
243
251
self.assertTrue(delta.has_changed())
244
self.assertTrue(delta.touches_file_id('file-id'))
252
self.assertTrue(delta.touches_file_id(b'file-id'))
245
253
self.assertEqual('kind changed:\n filename (file => directory)\n',
246
254
self.show_string(delta))
247
255
other_delta = _mod_delta.TreeDelta()
248
256
self.assertNotEqual(other_delta, delta)
249
other_delta.kind_changed = [('filename', 'file-id', 'file',
257
other_delta.kind_changed = [('filename', b'file-id', 'file',
251
259
self.assertNotEqual(other_delta, delta)
252
other_delta.kind_changed = [('filename', 'file-id', 'file',
260
other_delta.kind_changed = [('filename', b'file-id', 'file',
254
262
self.assertEqual(other_delta, delta)
255
self.assertEqualDiff("TreeDelta(added=[], removed=[], renamed=[],"
256
" kind_changed=[(u'filename', 'file-id', 'file', 'directory')],"
257
" modified=[], unchanged=[], unversioned=[])", repr(delta))
264
self.assertEqualDiff("TreeDelta(added=[], removed=[], renamed=[],"
265
" kind_changed=[('filename', b'file-id', 'file', 'directory')],"
266
" modified=[], unchanged=[], unversioned=[])", repr(delta))
268
self.assertEqualDiff("TreeDelta(added=[], removed=[], renamed=[],"
269
" kind_changed=[(u'filename', 'file-id', 'file', 'directory')],"
270
" modified=[], unchanged=[], unversioned=[])", repr(delta))
258
272
self.assertEqual('K filename (file => directory) file-id\n',
259
273
self.show_string(delta, show_ids=True,
260
274
short_status=True))
264
278
self.assertEqual([], delta.kind_changed)
265
279
# This loses the fact that kind changed, remembering it as a
267
self.assertEqual([('filename', 'dirname', 'file-id', 'directory',
281
self.assertEqual([('filename', 'dirname', b'file-id', 'directory',
268
282
True, False)], delta.renamed)
269
283
self.assertTrue(delta.has_changed())
270
self.assertTrue(delta.touches_file_id('file-id'))
284
self.assertTrue(delta.touches_file_id(b'file-id'))
273
287
class TestDeltaShow(tests.TestCaseWithTransport):
276
290
# We build the delta from a real tree to avoid depending on internal
277
291
# implementation details.
278
292
wt = self.make_branch_and_tree('branch')
279
self.build_tree_contents([('branch/f1', '1\n'),
280
('branch/f2', '2\n'),
281
('branch/f3', '3\n'),
282
('branch/f4', '4\n'),
293
self.build_tree_contents([('branch/f1', b'1\n'),
294
('branch/f2', b'2\n'),
295
('branch/f3', b'3\n'),
296
('branch/f4', b'4\n'),
297
('branch/f5', b'5\n'),
283
298
('branch/dir/',),
285
300
wt.add(['f1', 'f2', 'f3', 'f4', 'dir'],
286
['f1-id', 'f2-id', 'f3-id', 'f4-id', 'dir-id'])
287
wt.commit('commit one', rev_id='1')
301
[b'f1-id', b'f2-id', b'f3-id', b'f4-id', b'dir-id'])
302
wt.commit('commit one', rev_id=b'1')
304
# TODO add rename,removed,etc. here?
306
os.unlink('branch/f5')
289
308
long_status = """added:
296
317
short_status = """A dir/
303
325
repo = wt.branch.repository
304
326
d = wt.changes_from(repo.revision_tree(_mod_revision.NULL_REVISION))
305
327
return d, long_status, short_status
307
def test_delta_show_short_status_no_filter(self):
329
def test_short_status(self):
308
330
d, long_status, short_status = self._get_delta()
310
332
_mod_delta.report_delta(out, d, short_status=True)
311
self.assertEquals(short_status, out.getvalue())
333
self.assertEqual(short_status, out.getvalue())
313
def test_delta_show_long_status_no_filter(self):
335
def test_long_status(self):
314
336
d, long_status, short_status = self._get_delta()
316
338
_mod_delta.report_delta(out, d, short_status=False)
317
self.assertEquals(long_status, out.getvalue())
339
self.assertEqual(long_status, out.getvalue())
319
def test_delta_show_no_filter(self):
341
def test_predicate_always(self):
320
342
d, long_status, short_status = self._get_delta()
322
def not_a_filter(path, file_id):
344
def always(path, file_id):
324
_mod_delta.report_delta(out, d, short_status=True, filter=not_a_filter)
325
self.assertEquals(short_status, out.getvalue())
327
def test_delta_show_short_status_single_file_filter(self):
328
d, long_status, short_status = self._get_delta()
330
def only_f2(path, file_id):
332
_mod_delta.report_delta(out, d, short_status=True, filter=only_f2)
333
self.assertEquals("A f2\n", out.getvalue())
335
def test_delta_show_long_status_single_file_filter(self):
336
d, long_status, short_status = self._get_delta()
338
def only_f2(path, file_id):
340
_mod_delta.report_delta(out, d, short_status=False, filter=only_f2)
341
self.assertEquals("added:\n f2\n", out.getvalue())
343
def test_delta_show_short_status_single_file_id_filter(self):
346
_mod_delta.report_delta(out, d, short_status=True, predicate=always)
347
self.assertEqual(short_status, out.getvalue())
349
def test_short_status_path_predicate(self):
350
d, long_status, short_status = self._get_delta()
352
def only_f2(path, file_id):
354
_mod_delta.report_delta(out, d, short_status=True, predicate=only_f2)
355
self.assertEqual("A f2\n", out.getvalue())
357
def test_long_status_path_predicate(self):
358
d, long_status, short_status = self._get_delta()
360
def only_f2(path, file_id):
362
_mod_delta.report_delta(out, d, short_status=False, predicate=only_f2)
363
self.assertEqual("added:\n f2\n", out.getvalue())
365
def test_long_status_id_predicate(self):
344
366
d, long_status, short_status = self._get_delta()
346
368
def only_f2_id(path, file_id):
347
return file_id == 'f2-id'
348
_mod_delta.report_delta(out, d, short_status=True, filter=only_f2_id)
349
self.assertEquals("A f2\n", out.getvalue())
369
return file_id == b'f2-id'
370
_mod_delta.report_delta(out, d, predicate=only_f2_id)
371
self.assertEqual("added:\n f2\n", out.getvalue())