429
429
# and in the worst case, use bzrlib.user_encoding
430
430
self.assertEqual('user_encoding', osutils.get_terminal_encoding())
433
class TestOffsets(TestCase):
434
"""Test test_offsets_to_ranges method that is used to convert
435
readv into combined ranges."""
437
def test_offsets_to_http_ranges(self):
438
ranges, tail = osutils.offsets_to_http_ranges([(10, 1), (20, 2), (22, 5)])
439
self.assertEquals(tuple(ranges[0]), (10, 10))
440
self.assertEquals(tuple(ranges[1]), (20, 26))
441
self.assertEquals(tail, 0)
443
ranges, tail = osutils.offsets_to_http_ranges([(10, 1), (11, 2), (22, 5), (-4, 4)])
444
self.assertEquals(tuple(ranges[0]), (10, 12))
445
self.assertEquals(tuple(ranges[1]), (22, 26))
446
self.assertEquals(tail, 4)
448
ranges, tail = osutils.offsets_to_http_ranges([(-4, 4), (-8, 8)])
449
self.assertEquals(tuple(ranges), ())
450
self.assertEquals(tail, 8)
452
ranges, tail = osutils.offsets_to_http_ranges([(10, 1), (20, 2)], fudge_factor=9)
453
self.assertEquals(tuple(ranges[0]), (10, 21))
454
self.assertEquals(len(ranges), 1)
455
self.assertEquals(tail, 0)
457
ranges, tail = osutils.offsets_to_http_ranges([(10, 1), (20, 2)], fudge_factor=8)
458
self.assertEquals(tuple(ranges[0]), (10, 10))
459
self.assertEquals(tuple(ranges[1]), (20, 21))
460
self.assertEquals(tail, 0)