/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_delta.py

  • Committer: Vincent Ladeuil
  • Date: 2008-12-10 08:44:03 UTC
  • mto: (3941.1.1 bzr.integration)
  • mto: This revision was merged to the branch mainline in revision 3942.
  • Revision ID: v.ladeuil+lp@free.fr-20081210084403-89803az7m7rysrsy
Add a 'path_filter' parameter to delta.show().

* bzrlib/tests/test_delta.py:
(TestDeltaShow): Tests for delta.show() and the new 'path_filter'
parameter.

* bzrlib/delta.py:
(TreeDelta.show.show_list): Display header only once, before first
file is displayed. Add a path_filter parameter. Add doc_string.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
import os
18
 
from StringIO import StringIO
 
18
from cStringIO import StringIO
19
19
 
20
20
from bzrlib import (
21
21
    delta as _mod_delta,
 
22
    revision as _mod_revision,
22
23
    tests,
23
24
    )
24
25
 
187
188
                           exe_change=False)
188
189
 
189
190
 
190
 
class TestChangesFrom (tests.TestCaseWithTransport):
 
191
class TestChangesFrom(tests.TestCaseWithTransport):
191
192
 
192
193
    def show_string(self, delta, *args,  **kwargs):
193
194
        to_file = StringIO()
238
239
                           True, False)], delta.renamed)
239
240
        self.assertTrue(delta.has_changed())
240
241
        self.assertTrue(delta.touches_file_id('file-id'))
 
242
 
 
243
 
 
244
class TestDeltaShow(tests.TestCaseWithTransport):
 
245
 
 
246
    def _get_delta(self):
 
247
        # We build the delta from a real tree to avoid depending on internal
 
248
        # implementation details.
 
249
        wt = self.make_branch_and_tree('branch')
 
250
        self.build_tree_contents([('branch/f1', '1\n'),
 
251
                                  ('branch/f2', '2\n'),
 
252
                                  ('branch/f3', '3\n'),
 
253
                                  ('branch/f4', '4\n'),
 
254
                                  ('branch/dir/',),
 
255
                                 ])
 
256
        wt.add(['f1', 'f2', 'f3', 'f4', 'dir'],
 
257
               ['f1-id', 'f2-id', 'f3-id', 'f4-id', 'dir-id'])
 
258
        wt.commit('commit one', rev_id='1')
 
259
 
 
260
        long_status = """added:
 
261
  f1
 
262
  f2
 
263
  f3
 
264
  f4
 
265
"""
 
266
        short_status = """A  f1
 
267
A  f2
 
268
A  f3
 
269
A  f4
 
270
"""
 
271
 
 
272
        repo = wt.branch.repository
 
273
        d = wt.changes_from(repo.revision_tree(_mod_revision.NULL_REVISION))
 
274
        return d, long_status, short_status
 
275
 
 
276
    def test_delta_show_short_status_no_filter(self):
 
277
        d, long_status, short_status = self._get_delta()
 
278
        out = StringIO()
 
279
        d.show(out, short_status=True)
 
280
        self.assertEquals(short_status, out.getvalue())
 
281
 
 
282
    def test_delta_show_long_status_no_filter(self):
 
283
        d, long_status, short_status = self._get_delta()
 
284
        out = StringIO()
 
285
        d.show(out, short_status=False)
 
286
        self.assertEquals(long_status, out.getvalue())
 
287
 
 
288
    def test_delta_show_no_filter(self):
 
289
        d, long_status, short_status = self._get_delta()
 
290
        out = StringIO()
 
291
        def not_a_filter(path):
 
292
            return True
 
293
        d.show(out, short_status=True, path_filter=not_a_filter)
 
294
        self.assertEquals(short_status, out.getvalue())
 
295
 
 
296
    def test_delta_show_short_status_single_file_filter(self):
 
297
        d, long_status, short_status = self._get_delta()
 
298
        out = StringIO()
 
299
        def only_f2(path):
 
300
            return path == 'f2'
 
301
        d.show(out, short_status=True, path_filter=only_f2)
 
302
        self.assertEquals("A  f2\n", out.getvalue())
 
303
 
 
304
    def test_delta_show_long_status_single_file_filter(self):
 
305
        d, long_status, short_status = self._get_delta()
 
306
        out = StringIO()
 
307
        def only_f2(path):
 
308
            return path == 'f2'
 
309
        d.show(out, short_status=False, path_filter=only_f2)
 
310
        self.assertEquals("added:\n  f2\n", out.getvalue())