diff options
Diffstat (limited to 'Lib/test/test_urllibnet.py')
| -rw-r--r-- | Lib/test/test_urllibnet.py | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/Lib/test/test_urllibnet.py b/Lib/test/test_urllibnet.py index bac2049..32efb2b 100644 --- a/Lib/test/test_urllibnet.py +++ b/Lib/test/test_urllibnet.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import unittest from test import support @@ -12,8 +12,9 @@ import time class URLTimeoutTest(unittest.TestCase): + # XXX this test doesn't seem to test anything useful. - TIMEOUT = 10.0 + TIMEOUT = 30.0 def setUp(self): socket.setdefaulttimeout(self.TIMEOUT) @@ -24,7 +25,7 @@ class URLTimeoutTest(unittest.TestCase): def testURLread(self): with support.transient_internet("www.python.org"): f = urllib.request.urlopen("http://www.python.org/") - x = f.read() + x = f.read() class urlopenNetworkTests(unittest.TestCase): """Tests urllib.reqest.urlopen using the network. @@ -43,8 +44,10 @@ class urlopenNetworkTests(unittest.TestCase): def urlopen(self, *args, **kwargs): resource = args[0] - with support.transient_internet(resource): - return urllib.request.urlopen(*args, **kwargs) + cm = support.transient_internet(resource) + cm.__enter__() + self.addCleanup(cm.__exit__, None, None, None) + return urllib.request.urlopen(*args, **kwargs) def test_basic(self): # Simple test expected to pass. @@ -62,10 +65,10 @@ class urlopenNetworkTests(unittest.TestCase): # Test both readline and readlines. open_url = self.urlopen("http://www.python.org/") try: - self.assertTrue(isinstance(open_url.readline(), bytes), - "readline did not return bytes") - self.assertTrue(isinstance(open_url.readlines(), list), - "readlines did not return a list") + self.assertIsInstance(open_url.readline(), bytes, + "readline did not return a string") + self.assertIsInstance(open_url.readlines(), list, + "readlines did not return a list") finally: open_url.close() @@ -76,9 +79,9 @@ class urlopenNetworkTests(unittest.TestCase): info_obj = open_url.info() finally: open_url.close() - self.assertTrue(isinstance(info_obj, email.message.Message), - "object returned by 'info' is not an instance of " - "email.message.Message") + self.assertIsInstance(info_obj, email.message.Message, + "object returned by 'info' is not an " + "instance of email.message.Message") self.assertEqual(info_obj.get_content_subtype(), "html") def test_geturl(self): @@ -135,8 +138,10 @@ class urlretrieveNetworkTests(unittest.TestCase): def urlretrieve(self, *args): resource = args[0] - with support.transient_internet(resource): - return urllib.request.urlretrieve(*args) + cm = support.transient_internet(resource) + cm.__enter__() + self.addCleanup(cm.__exit__, None, None, None) + return urllib.request.urlretrieve(*args) def test_basic(self): # Test basic functionality. @@ -168,8 +173,8 @@ class urlretrieveNetworkTests(unittest.TestCase): # Make sure header returned as 2nd value from urlretrieve is good. file_location, header = self.urlretrieve("http://www.python.org/") os.unlink(file_location) - self.assertTrue(isinstance(header, email.message.Message), - "header is not an instance of email.message.Message") + self.assertIsInstance(header, email.message.Message, + "header is not an instance of email.message.Message") def test_data_header(self): logo = "http://www.python.org/community/logos/python-logo-master-v3-TM.png" |
