~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_sftp_transport.py

  • Committer: Martin Pool
  • Date: 2008-11-07 05:39:09 UTC
  • mto: (3815.3.2 1.9)
  • mto: This revision was merged to the branch mainline in revision 3827.
  • Revision ID: mbp@sourcefrog.net-20081107053909-kwq9p72djtac71dm
merge fix for out-of-order SFTP readv

Show diffs side-by-side

added added

removed removed

Lines of Context:
463
463
        self.assertAlmostEqual(t2 - t1, 100 + 7)
464
464
 
465
465
 
 
466
class ReadvFile(object):
 
467
    """An object that acts like Paramiko's SFTPFile.readv()"""
 
468
 
 
469
    def __init__(self, data):
 
470
        self._data = data
 
471
 
 
472
    def readv(self, requests):
 
473
        for start, length in requests:
 
474
            yield self._data[start:start+length]
 
475
 
 
476
 
466
477
class Test_SFTPReadvHelper(tests.TestCase):
467
478
 
468
479
    def checkGetRequests(self, expected_requests, offsets):
485
496
                              [(0, 40000), (40000, 100), (40100, 1900),
486
497
                               (42000, 24000)])
487
498
 
 
499
    def checkRequestAndYield(self, expected, data, offsets):
 
500
        helper = _mod_sftp._SFTPReadvHelper(offsets, 'artificial_test')
 
501
        data_f = ReadvFile(data)
 
502
        result = list(helper.request_and_yield_offsets(data_f))
 
503
        self.assertEqual(expected, result)
 
504
 
 
505
    def test_request_and_yield_offsets(self):
 
506
        data = 'abcdefghijklmnopqrstuvwxyz'
 
507
        self.checkRequestAndYield([(0, 'a'), (5, 'f'), (10, 'klm')], data,
 
508
                                  [(0, 1), (5, 1), (10, 3)])
 
509
        # Should combine requests, and split them again
 
510
        self.checkRequestAndYield([(0, 'a'), (1, 'b'), (10, 'klm')], data,
 
511
                                  [(0, 1), (1, 1), (10, 3)])
 
512
        # Out of order requests. The requests should get combined, but then be
 
513
        # yielded out-of-order. We also need one that is at the end of a
 
514
        # previous range. See bug #293746
 
515
        self.checkRequestAndYield([(0, 'a'), (10, 'k'), (4, 'efg'), (1, 'bcd')],
 
516
                                  data, [(0, 1), (10, 1), (4, 3), (1, 3)])
 
517
 
488
518
 
489
519
class TestUsesAuthConfig(TestCaseWithSFTPServer):
490
520
    """Test that AuthenticationConfig can supply default usernames."""