[Numpy-svn] r5346 - in trunk/numpy/lib: . tests

numpy-svn at scipy.org numpy-svn at scipy.org
Thu Jul 3 15:02:18 EDT 2008


Author: rkern
Date: 2008-07-03 14:02:15 -0500 (Thu, 03 Jul 2008)
New Revision: 5346

Modified:
   trunk/numpy/lib/_datasource.py
   trunk/numpy/lib/tests/test__datasource.py
Log:
BUG: Correctly stub out urllib2.urlopen() for tests given the refactoring of the local imports.

Modified: trunk/numpy/lib/_datasource.py
===================================================================
--- trunk/numpy/lib/_datasource.py	2008-07-03 16:29:36 UTC (rev 5345)
+++ trunk/numpy/lib/_datasource.py	2008-07-03 19:02:15 UTC (rev 5346)
@@ -341,7 +341,7 @@
         """
         # We import this here because importing urllib2 is slow and
         # a significant fraction of numpy's total import time.
-        from urllib2 import URLError
+        from urllib2 import urlopen, URLError
 
         # Test local path
         if os.path.exists(path):

Modified: trunk/numpy/lib/tests/test__datasource.py
===================================================================
--- trunk/numpy/lib/tests/test__datasource.py	2008-07-03 16:29:36 UTC (rev 5345)
+++ trunk/numpy/lib/tests/test__datasource.py	2008-07-03 19:02:15 UTC (rev 5346)
@@ -6,6 +6,7 @@
 from shutil import rmtree
 from urlparse import urlparse
 from urllib2 import URLError
+import urllib2
 
 from numpy.testing import *
 
@@ -19,10 +20,15 @@
     else:
         raise URLError('Name or service not known')
 
-# Rebind urlopen during testing.  For a 'real' test, uncomment the rebinding
-# below.
-datasource.urlopen = urlopen_stub
+old_urlopen = None
+def setup():
+    global old_urlopen
+    old_urlopen = urllib2.urlopen
+    urllib2.urlopen = urlopen_stub
 
+def teardown():
+    urllib2.urlopen = old_urlopen
+
 # A valid website for more robust testing
 http_path = 'http://www.google.com/'
 http_file = 'index.html'




More information about the Numpy-svn mailing list