Unverified Commit 7693c896 authored by Francisco Massa's avatar Francisco Massa Committed by GitHub
Browse files

Raise error during downloading (#1013)

* Raise error during downloading

* Fix py2 error and lint
parent f9348a04
...@@ -62,6 +62,13 @@ class Tester(unittest.TestCase): ...@@ -62,6 +62,13 @@ class Tester(unittest.TestCase):
warnings.warn(msg, RuntimeWarning) warnings.warn(msg, RuntimeWarning)
raise unittest.SkipTest(msg) raise unittest.SkipTest(msg)
@unittest.skipIf(sys.version_info < (3,), "Python2 doesn't raise error")
def test_download_url_dont_exist(self):
with get_tmp_dir() as temp_dir:
url = "http://github.com/pytorch/vision/archive/this_doesnt_exist.zip"
with self.assertRaises(URLError):
utils.download_url(url, temp_dir)
def test_extract_zip(self): def test_extract_zip(self):
with get_tmp_dir() as temp_dir: with get_tmp_dir() as temp_dir:
with tempfile.NamedTemporaryFile(suffix='.zip') as f: with tempfile.NamedTemporaryFile(suffix='.zip') as f:
......
...@@ -82,7 +82,7 @@ def download_url(url, root, filename=None, md5=None): ...@@ -82,7 +82,7 @@ def download_url(url, root, filename=None, md5=None):
url, fpath, url, fpath,
reporthook=gen_bar_updater() reporthook=gen_bar_updater()
) )
except OSError: except urllib.error.URLError as e:
if url[:5] == 'https': if url[:5] == 'https':
url = url.replace('https:', 'http:') url = url.replace('https:', 'http:')
print('Failed download. Trying https -> http instead.' print('Failed download. Trying https -> http instead.'
...@@ -91,6 +91,8 @@ def download_url(url, root, filename=None, md5=None): ...@@ -91,6 +91,8 @@ def download_url(url, root, filename=None, md5=None):
url, fpath, url, fpath,
reporthook=gen_bar_updater() reporthook=gen_bar_updater()
) )
else:
raise e
def list_dir(root, prefix=False): def list_dir(root, prefix=False):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment