[Python-checkins] cpython (3.2): test_urllibnet: make it so that transient_internet() applies to the

antoine.pitrou python-checkins at python.org
Sat Mar 26 18:40:01 CET 2011


http://hg.python.org/cpython/rev/b65f417dd266
changeset:   68972:b65f417dd266
branch:      3.2
parent:      68967:c89db9b36ea6
user:        Antoine Pitrou <solipsis at pitrou.net>
date:        Sat Mar 26 18:36:42 2011 +0100
summary:
  test_urllibnet: make it so that transient_internet() applies to the
whole HTTP exchange, not only the opening.

files:
  Lib/test/test_urllibnet.py |  12 ++++++++----
  1 files changed, 8 insertions(+), 4 deletions(-)


diff --git a/Lib/test/test_urllibnet.py b/Lib/test/test_urllibnet.py
--- a/Lib/test/test_urllibnet.py
+++ b/Lib/test/test_urllibnet.py
@@ -43,8 +43,10 @@
 
     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 +137,10 @@
 
     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.

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list