MCPcopy Index your code
hub / github.com/python/cpython / test_reporthook

Method test_reporthook

Lib/test/test_urllibnet.py:203–227  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

201 self.fail('Date value not in %r format' % dateformat)
202
203 def test_reporthook(self):
204 records = []
205
206 def recording_reporthook(blocks, block_size, total_size):
207 records.append((blocks, block_size, total_size))
208
209 with self.urlretrieve(self.logo, reporthook=recording_reporthook) as (
210 file_location, fileheaders):
211 expected_size = int(fileheaders['Content-Length'])
212
213 records_repr = repr(records) # For use in error messages.
214 self.assertGreater(len(records), 1, msg="There should always be two "
215 "calls; the first one before the transfer starts.")
216 self.assertEqual(records[0][0], 0)
217 self.assertGreater(records[0][1], 0,
218 msg="block size can't be 0 in %s" % records_repr)
219 self.assertEqual(records[0][2], expected_size)
220 self.assertEqual(records[-1][2], expected_size)
221
222 block_sizes = {block_size for _, block_size, _ in records}
223 self.assertEqual({records[0][1]}, block_sizes,
224 msg="block sizes in %s must be equal" % records_repr)
225 self.assertGreaterEqual(records[-1][0]*records[0][1], expected_size,
226 msg="number of blocks * block size must be"
227 " >= total size in %s" % records_repr)
228
229
230if __name__ == "__main__":

Callers

nothing calls this directly

Calls 4

urlretrieveMethod · 0.95
assertGreaterMethod · 0.80
assertGreaterEqualMethod · 0.80
assertEqualMethod · 0.45

Tested by

no test coverage detected