164
164
t = get_transport('http+urllib://bzr.google.com/')
165
165
self.assertIsInstance(t, Transport)
166
166
self.assertIsInstance(t, bzrlib.transport.http._urllib.HttpTransport_urllib)
169
class TestOffsets(TestCase):
170
"""Test test_offsets_to_ranges method"""
172
def test_offsets_to_ranges_simple(self):
173
to_range = HttpTransportBase.offsets_to_ranges
174
ranges, tail = to_range([(10, 1)])
175
self.assertEqual([[10, 10]], ranges)
176
self.assertEqual(0, tail)
178
ranges, tail = to_range([(0, 1), (1, 1)])
179
self.assertEqual([[0, 1]], ranges)
180
self.assertEqual(0, tail)
182
ranges, tail = to_range([(1, 1), (0, 1)])
183
self.assertEqual([[0, 1]], ranges)
184
self.assertEqual(0, tail)
186
def test_offset_to_ranges_overlapped(self):
187
to_range = HttpTransportBase.offsets_to_ranges
189
ranges, tail = to_range([(10, 1), (20, 2), (22, 5)])
190
self.assertEquals(tuple(ranges[0]), (10, 10))
191
self.assertEquals(tuple(ranges[1]), (20, 26))
192
self.assertEquals(tail, 0)
194
ranges, tail = to_range([(10, 1), (11, 2), (22, 5), (-4, 4)])
195
self.assertEquals(tuple(ranges[0]), (10, 12))
196
self.assertEquals(tuple(ranges[1]), (22, 26))
197
self.assertEquals(tail, 4)
199
def test_offset_to_ranges_tail(self):
200
to_range = HttpTransportBase.offsets_to_ranges
202
ranges, tail = to_range([(-4, 4), (-8, 8)])
203
self.assertEquals(tuple(ranges), ())
204
self.assertEquals(tail, 8)
206
def test_offset_to_ranges_fudge(self):
207
to_range = HttpTransportBase.offsets_to_ranges
209
ranges, tail = to_range([(10, 1), (20, 2)], fudge_factor=9)
210
self.assertEquals(tuple(ranges[0]), (10, 21))
211
self.assertEquals(len(ranges), 1)
212
self.assertEquals(tail, 0)
214
ranges, tail = to_range([(10, 1), (20, 2)], fudge_factor=8)
215
self.assertEquals(tuple(ranges[0]), (10, 10))
216
self.assertEquals(tuple(ranges[1]), (20, 21))
217
self.assertEquals(tail, 0)