~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

  • Committer: John Arbash Meinel
  • Date: 2009-01-23 21:20:55 UTC
  • mto: This revision was merged to the branch mainline in revision 3958.
  • Revision ID: john@arbash-meinel.com-20090123212055-qsa1szqtrrxtwgdl
Add report_activity to osutils.pumpfile

Show diffs side-by-side

added added

removed removed

Lines of Context:
486
486
            message = "Data not equal.  Expected %d bytes, received %d."
487
487
            self.fail(message % (len(response_data), self.test_data_len))
488
488
 
 
489
    def test_report_activity(self):
 
490
        activity = []
 
491
        def log_activity(length, direction):
 
492
            activity.append((length, direction))
 
493
        from_file = StringIO(self.test_data)
 
494
        to_file = StringIO()
 
495
        pumpfile(from_file, to_file, buff_size=500,
 
496
                 report_activity=log_activity, direction='read')
 
497
        self.assertEqual([(500, 'read'), (500, 'read'), (500, 'read'),
 
498
                          (36, 'read')], activity)
 
499
 
 
500
        from_file = StringIO(self.test_data)
 
501
        to_file = StringIO()
 
502
        del activity[:]
 
503
        pumpfile(from_file, to_file, buff_size=500,
 
504
                 report_activity=log_activity, direction='write')
 
505
        self.assertEqual([(500, 'write'), (500, 'write'), (500, 'write'),
 
506
                          (36, 'write')], activity)
 
507
 
 
508
        # And with a limited amount of data
 
509
        from_file = StringIO(self.test_data)
 
510
        to_file = StringIO()
 
511
        del activity[:]
 
512
        pumpfile(from_file, to_file, buff_size=500, read_length=1028,
 
513
                 report_activity=log_activity, direction='read')
 
514
        self.assertEqual([(500, 'read'), (500, 'read'), (28, 'read')], activity)
 
515
 
 
516
 
489
517
 
490
518
class TestPumpStringFile(TestCase):
491
519