463
463
self.assertAlmostEqual(t2 - t1, 100 + 7)
466
class ReadvFile(object):
467
"""An object that acts like Paramiko's SFTPFile.readv()"""
469
def __init__(self, data):
472
def readv(self, requests):
473
for start, length in requests:
474
yield self._data[start:start+length]
466
477
class Test_SFTPReadvHelper(tests.TestCase):
468
479
def checkGetRequests(self, expected_requests, offsets):
485
496
[(0, 40000), (40000, 100), (40100, 1900),
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)
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)])
489
519
class TestUsesAuthConfig(TestCaseWithSFTPServer):
490
520
"""Test that AuthenticationConfig can supply default usernames."""