diff options
author | Robert Kern <robert.kern@gmail.com> | 2008-07-03 19:02:15 +0000 |
---|---|---|
committer | Robert Kern <robert.kern@gmail.com> | 2008-07-03 19:02:15 +0000 |
commit | 0c817a5d51c2c16db9df5c015ff846002d991d74 (patch) | |
tree | c10daa592ed0df44f1962125776141f7b8d47040 /numpy/lib | |
parent | c8f88c0411203a0d1a09aadef920c563ef54c12a (diff) | |
download | numpy-0c817a5d51c2c16db9df5c015ff846002d991d74.tar.gz |
BUG: Correctly stub out urllib2.urlopen() for tests given the refactoring of the local imports.
Diffstat (limited to 'numpy/lib')
-rw-r--r-- | numpy/lib/_datasource.py | 2 | ||||
-rw-r--r-- | numpy/lib/tests/test__datasource.py | 12 |
2 files changed, 10 insertions, 4 deletions
diff --git a/numpy/lib/_datasource.py b/numpy/lib/_datasource.py index 0dc744dbc..d70e5db9d 100644 --- a/numpy/lib/_datasource.py +++ b/numpy/lib/_datasource.py @@ -341,7 +341,7 @@ class DataSource (object): """ # 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): diff --git a/numpy/lib/tests/test__datasource.py b/numpy/lib/tests/test__datasource.py index d55e52973..c9e9b2eee 100644 --- a/numpy/lib/tests/test__datasource.py +++ b/numpy/lib/tests/test__datasource.py @@ -6,6 +6,7 @@ from tempfile import mkdtemp, mkstemp, NamedTemporaryFile from shutil import rmtree from urlparse import urlparse from urllib2 import URLError +import urllib2 from numpy.testing import * @@ -19,9 +20,14 @@ def urlopen_stub(url, data=None): 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/' |