summaryrefslogtreecommitdiff
path: root/Lib/test/test_urllib.py
diff options
context:
space:
mode:
authorSenthil Kumaran <senthil@uthcode.com>2012-03-13 19:29:33 -0700
committerSenthil Kumaran <senthil@uthcode.com>2012-03-13 19:29:33 -0700
commite24f96a05973ddbb59d88c03570aef8545c5ef10 (patch)
treec3c8721fe8e2bf99cf6bb2c6761ad14adc88eb48 /Lib/test/test_urllib.py
parenta2251aadaa6de54eaf9663451afd16806a0712f3 (diff)
downloadcpython-git-e24f96a05973ddbb59d88c03570aef8545c5ef10.tar.gz
Issue10050 - urlretrieve uses newer urlopen. reporthook of urlretrieve takes, block number, block read size, file_size
Diffstat (limited to 'Lib/test/test_urllib.py')
-rw-r--r--Lib/test/test_urllib.py34
1 files changed, 17 insertions, 17 deletions
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
index b2680edd42..85f8f841df 100644
--- a/Lib/test/test_urllib.py
+++ b/Lib/test/test_urllib.py
@@ -384,11 +384,11 @@ class urlretrieve_FileTests(unittest.TestCase):
def test_reporthook(self):
# Make sure that the reporthook works.
- def hooktester(count, block_size, total_size, count_holder=[0]):
- self.assertIsInstance(count, int)
- self.assertIsInstance(block_size, int)
- self.assertIsInstance(total_size, int)
- self.assertEqual(count, count_holder[0])
+ def hooktester(block_count, block_read_size, file_size, count_holder=[0]):
+ self.assertIsInstance(block_count, int)
+ self.assertIsInstance(block_read_size, int)
+ self.assertIsInstance(file_size, int)
+ self.assertEqual(block_count, count_holder[0])
count_holder[0] = count_holder[0] + 1
second_temp = "%s.2" % support.TESTFN
self.registerFileForCleanUp(second_temp)
@@ -399,8 +399,8 @@ class urlretrieve_FileTests(unittest.TestCase):
def test_reporthook_0_bytes(self):
# Test on zero length file. Should call reporthook only 1 time.
report = []
- def hooktester(count, block_size, total_size, _report=report):
- _report.append((count, block_size, total_size))
+ def hooktester(block_count, block_read_size, file_size, _report=report):
+ _report.append((block_count, block_read_size, file_size))
srcFileName = self.createNewTempFile()
urllib.request.urlretrieve(self.constructLocalFileUrl(srcFileName),
support.TESTFN, hooktester)
@@ -410,31 +410,31 @@ class urlretrieve_FileTests(unittest.TestCase):
def test_reporthook_5_bytes(self):
# Test on 5 byte file. Should call reporthook only 2 times (once when
# the "network connection" is established and once when the block is
- # read). Since the block size is 8192 bytes, only one block read is
- # required to read the entire file.
+ # read).
report = []
- def hooktester(count, block_size, total_size, _report=report):
- _report.append((count, block_size, total_size))
+ def hooktester(block_count, block_read_size, file_size, _report=report):
+ _report.append((block_count, block_read_size, file_size))
srcFileName = self.createNewTempFile(b"x" * 5)
urllib.request.urlretrieve(self.constructLocalFileUrl(srcFileName),
support.TESTFN, hooktester)
self.assertEqual(len(report), 2)
- self.assertEqual(report[0][1], 8192)
- self.assertEqual(report[0][2], 5)
+ self.assertEqual(report[0][1], 0)
+ self.assertEqual(report[1][1], 5)
def test_reporthook_8193_bytes(self):
# Test on 8193 byte file. Should call reporthook only 3 times (once
# when the "network connection" is established, once for the next 8192
# bytes, and once for the last byte).
report = []
- def hooktester(count, block_size, total_size, _report=report):
- _report.append((count, block_size, total_size))
+ def hooktester(block_count, block_read_size, file_size, _report=report):
+ _report.append((block_count, block_read_size, file_size))
srcFileName = self.createNewTempFile(b"x" * 8193)
urllib.request.urlretrieve(self.constructLocalFileUrl(srcFileName),
support.TESTFN, hooktester)
self.assertEqual(len(report), 3)
- self.assertEqual(report[0][1], 8192)
- self.assertEqual(report[0][2], 8193)
+ self.assertEqual(report[0][1], 0)
+ self.assertEqual(report[1][1], 8192)
+ self.assertEqual(report[2][1], 1)
class urlretrieve_HttpTests(unittest.TestCase, FakeHTTPMixin):