diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2011-03-26 17:38:06 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-03-26 17:38:06 (GMT) |
commit | d9faa201cedbb5a1882ad50e72e85c6f99c7f18e (patch) | |
tree | eb84f0486e82d04bdebad8c42389733e76149b07 /Lib | |
parent | 006ba5c1659c7f9107fb4a8032ab5db041c82648 (diff) | |
parent | b651949f53134776a6bdda311832d0d59648013f (diff) | |
download | cpython-d9faa201cedbb5a1882ad50e72e85c6f99c7f18e.zip cpython-d9faa201cedbb5a1882ad50e72e85c6f99c7f18e.tar.gz cpython-d9faa201cedbb5a1882ad50e72e85c6f99c7f18e.tar.bz2 |
Read HTTP response inside transient_internet()
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_urllibnet.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/Lib/test/test_urllibnet.py b/Lib/test/test_urllibnet.py index c885103..32efb2b 100644 --- a/Lib/test/test_urllibnet.py +++ b/Lib/test/test_urllibnet.py @@ -12,6 +12,7 @@ import time class URLTimeoutTest(unittest.TestCase): + # XXX this test doesn't seem to test anything useful. TIMEOUT = 30.0 @@ -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. @@ -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. |