ยปCore Development>Code coverage>Lib/test/test_urllib_response.py

Python code coverage for Lib/test/test_urllib_response.py

#countcontent
1n/a"""Unit tests for code in urllib.response."""
2n/a
3n/aimport socket
4n/aimport tempfile
5n/aimport urllib.response
6n/aimport unittest
7n/a
8n/aclass TestResponse(unittest.TestCase):
9n/a
10n/a def setUp(self):
11n/a self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
12n/a self.fp = self.sock.makefile('rb')
13n/a self.test_headers = {"Host": "www.python.org",
14n/a "Connection": "close"}
15n/a
16n/a def test_with(self):
17n/a addbase = urllib.response.addbase(self.fp)
18n/a
19n/a self.assertIsInstance(addbase, tempfile._TemporaryFileWrapper)
20n/a
21n/a def f():
22n/a with addbase as spam:
23n/a pass
24n/a self.assertFalse(self.fp.closed)
25n/a f()
26n/a self.assertTrue(self.fp.closed)
27n/a self.assertRaises(ValueError, f)
28n/a
29n/a def test_addclosehook(self):
30n/a closehook_called = False
31n/a
32n/a def closehook():
33n/a nonlocal closehook_called
34n/a closehook_called = True
35n/a
36n/a closehook = urllib.response.addclosehook(self.fp, closehook)
37n/a closehook.close()
38n/a
39n/a self.assertTrue(self.fp.closed)
40n/a self.assertTrue(closehook_called)
41n/a
42n/a def test_addinfo(self):
43n/a info = urllib.response.addinfo(self.fp, self.test_headers)
44n/a self.assertEqual(info.info(), self.test_headers)
45n/a
46n/a def test_addinfourl(self):
47n/a url = "http://www.python.org"
48n/a code = 200
49n/a infourl = urllib.response.addinfourl(self.fp, self.test_headers,
50n/a url, code)
51n/a self.assertEqual(infourl.info(), self.test_headers)
52n/a self.assertEqual(infourl.geturl(), url)
53n/a self.assertEqual(infourl.getcode(), code)
54n/a
55n/a def tearDown(self):
56n/a self.sock.close()
57n/a
58n/aif __name__ == '__main__':
59n/a unittest.main()