diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2013-04-14 12:17:43 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2013-04-14 12:24:40 -0600 |
commit | c70025a46d655a19c6c7d64dbbf96849093afb18 (patch) | |
tree | d1ed0a80aa0a9358ae52a3ac2f2ea28897f5101b /numpy/lib/tests/test__datasource.py | |
parent | 6c47259eec0ec20c1150c2b29994de59a3158964 (diff) | |
download | numpy-c70025a46d655a19c6c7d64dbbf96849093afb18.tar.gz |
2to3: Apply urllib fixer.
Various functions have been moved around in the stdlib for Python 3,
this fixes that up so that the code is valid in both Python 2 and
Python 3.
Note: monkey patching the stlib urlopen for testing looks a bit hokey
to me, but I don't see an easier, more reliable way to do the test.
Closes #3090.
Diffstat (limited to 'numpy/lib/tests/test__datasource.py')
-rw-r--r-- | numpy/lib/tests/test__datasource.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/numpy/lib/tests/test__datasource.py b/numpy/lib/tests/test__datasource.py index 3933fdcde..8d3e32b1b 100644 --- a/numpy/lib/tests/test__datasource.py +++ b/numpy/lib/tests/test__datasource.py @@ -1,20 +1,21 @@ from __future__ import division, absolute_import, print_function import os -import urllib2 import sys import numpy.lib._datasource as datasource from tempfile import mkdtemp, mkstemp, NamedTemporaryFile from shutil import rmtree -from urllib2 import URLError from numpy.compat import asbytes from numpy.testing import * - if sys.version_info[0] >= 3: + import urllib.request as urllib_request from urllib.parse import urlparse + from urllib.error import URLError else: + import urllib2 as urllib_request from urlparse import urlparse + from urllib2 import URLError def urlopen_stub(url, data=None): '''Stub to replace urlopen for testing.''' @@ -24,14 +25,17 @@ def urlopen_stub(url, data=None): else: raise URLError('Name or service not known') +# setup and teardown old_urlopen = None + def setup(): global old_urlopen - old_urlopen = urllib2.urlopen - urllib2.urlopen = urlopen_stub + + old_urlopen = urllib_request.urlopen + urllib_request.urlopen = urlopen_stub def teardown(): - urllib2.urlopen = old_urlopen + urllib_request.urlopen = old_urlopen # A valid website for more robust testing http_path = 'http://www.google.com/' |