13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
from cStringIO import StringIO
41
41
versioned_change='unchanged', renamed=False,
42
42
modified='unchanged', exe_change=False,
43
43
kind=('file', 'file'), old_path=None,
44
unversioned_filter=None):
44
unversioned_filter=None, view_info=None):
48
expected_lines = [expected]
49
self.assertReportLines(expected_lines, file_id, path,
50
versioned_change, renamed,
53
unversioned_filter, view_info)
55
def assertReportLines(self, expected_lines, file_id='fid', path='path',
56
versioned_change='unchanged', renamed=False,
57
modified='unchanged', exe_change=False,
58
kind=('file', 'file'), old_path=None,
59
unversioned_filter=None, view_info=None):
46
61
def result_line(format, *args):
47
62
result.append(format % args)
48
63
reporter = _mod_delta._ChangeReporter(result_line,
49
unversioned_filter=unversioned_filter)
64
unversioned_filter=unversioned_filter, view_info=view_info)
50
65
reporter.report(file_id, (old_path, path), versioned_change, renamed,
51
66
modified, exe_change, kind)
52
if expected is not None:
53
self.assertEqualDiff(expected, result[0])
67
if expected_lines is not None:
68
for i in range(len(expected_lines)):
69
self.assertEqualDiff(expected_lines[i], result[i])
55
71
self.assertEqual([], result)
100
116
old_path=None, versioned_change='unversioned',
101
117
renamed=False, modified='created', exe_change=False,
102
118
kind=(None, 'file'))
103
# but we can choose to filter these. Probably that should be done
119
# but we can choose to filter these. Probably that should be done
104
120
# close to the tree, but this is a reasonable starting point.
105
121
self.assertReport(None, file_id=None, path='subdir/foo~',
106
122
old_path=None, versioned_change='unversioned',
107
123
renamed=False, modified='created', exe_change=False,
108
124
kind=(None, 'file'), unversioned_filter=lambda x:True)
126
def test_view_filtering(self):
127
# If a file in within the view, it should appear in the output
129
"Operating on whole tree but only reporting on 'my' view.",
131
self.assertReportLines(expected_lines, modified='modified',
132
view_info=('my',['path']))
133
# If a file in outside the view, it should not appear in the output
135
"Operating on whole tree but only reporting on 'my' view."]
136
self.assertReportLines(expected_lines, modified='modified',
137
path="foo", view_info=('my',['path']))
110
139
def assertChangesEqual(self,
112
141
paths=('path', 'path'),
193
222
def show_string(self, delta, *args, **kwargs):
194
223
to_file = StringIO()
195
delta.show(to_file, *args, **kwargs)
224
_mod_delta.report_delta(to_file, delta, *args, **kwargs)
196
225
return to_file.getvalue()
198
227
def test_kind_change(self):
278
307
def test_delta_show_short_status_no_filter(self):
279
308
d, long_status, short_status = self._get_delta()
281
d.show(out, short_status=True)
310
_mod_delta.report_delta(out, d, short_status=True)
282
311
self.assertEquals(short_status, out.getvalue())
284
313
def test_delta_show_long_status_no_filter(self):
285
314
d, long_status, short_status = self._get_delta()
287
d.show(out, short_status=False)
316
_mod_delta.report_delta(out, d, short_status=False)
288
317
self.assertEquals(long_status, out.getvalue())
290
319
def test_delta_show_no_filter(self):
293
322
def not_a_filter(path, file_id):
295
d.show(out, short_status=True, filter=not_a_filter)
324
_mod_delta.report_delta(out, d, short_status=True, filter=not_a_filter)
296
325
self.assertEquals(short_status, out.getvalue())
298
327
def test_delta_show_short_status_single_file_filter(self):
301
330
def only_f2(path, file_id):
302
331
return path == 'f2'
303
d.show(out, short_status=True, filter=only_f2)
332
_mod_delta.report_delta(out, d, short_status=True, filter=only_f2)
304
333
self.assertEquals("A f2\n", out.getvalue())
306
335
def test_delta_show_long_status_single_file_filter(self):
309
338
def only_f2(path, file_id):
310
339
return path == 'f2'
311
d.show(out, short_status=False, filter=only_f2)
340
_mod_delta.report_delta(out, d, short_status=False, filter=only_f2)
312
341
self.assertEquals("added:\n f2\n", out.getvalue())
314
343
def test_delta_show_short_status_single_file_id_filter(self):
317
346
def only_f2_id(path, file_id):
318
347
return file_id == 'f2-id'
319
d.show(out, short_status=True, filter=only_f2_id)
348
_mod_delta.report_delta(out, d, short_status=True, filter=only_f2_id)
320
349
self.assertEquals("A f2\n", out.getvalue())