Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
vision
Commits
00c460af
Unverified
Commit
00c460af
authored
Mar 17, 2021
by
Philip Meier
Committed by
GitHub
Mar 17, 2021
Browse files
fix redirection in download tests (#3568)
Co-authored-by:
Francisco Massa
<
fvsmassa@gmail.com
>
parent
8ee63393
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
13 deletions
+25
-13
test/test_datasets_download.py
test/test_datasets_download.py
+25
-13
No files found.
test/test_datasets_download.py
View file @
00c460af
...
@@ -14,7 +14,13 @@ import warnings
...
@@ -14,7 +14,13 @@ import warnings
import
pytest
import
pytest
from
torchvision
import
datasets
from
torchvision
import
datasets
from
torchvision.datasets.utils
import
download_url
,
check_integrity
,
download_file_from_google_drive
,
USER_AGENT
from
torchvision.datasets.utils
import
(
download_url
,
check_integrity
,
download_file_from_google_drive
,
_get_redirect_url
,
USER_AGENT
,
)
from
common_utils
import
get_tmp_dir
from
common_utils
import
get_tmp_dir
from
fakedata_generation
import
places365_root
from
fakedata_generation
import
places365_root
...
@@ -48,22 +54,28 @@ def limit_requests_per_time(min_secs_between_requests=2.0):
...
@@ -48,22 +54,28 @@ def limit_requests_per_time(min_secs_between_requests=2.0):
urlopen
=
limit_requests_per_time
()(
urlopen
)
urlopen
=
limit_requests_per_time
()(
urlopen
)
def
resolve_redirects
(
max_
redirect
s
=
3
):
def
resolve_redirects
(
max_
hop
s
=
3
):
def
outer_wrapper
(
fn
):
def
outer_wrapper
(
fn
):
def
inner_wrapper
(
request
,
*
args
,
**
kwargs
):
def
inner_wrapper
(
request
,
*
args
,
**
kwargs
):
url
=
initial_url
=
request
.
full_url
if
isinstance
(
request
,
Request
)
else
request
initial_url
=
request
.
full_url
if
isinstance
(
request
,
Request
)
else
request
url
=
_get_redirect_url
(
initial_url
,
max_hops
=
max_hops
)
for
_
in
range
(
max_redirects
+
1
)
:
if
url
==
initial_url
:
re
sponse
=
fn
(
request
,
*
args
,
**
kwargs
)
re
turn
fn
(
request
,
*
args
,
**
kwargs
)
if
response
.
url
==
url
or
response
.
url
is
None
:
warnings
.
warn
(
f
"The URL
{
initial_url
}
ultimately redirects to
{
url
}
."
)
if
url
!=
initial_url
:
warnings
.
warn
(
f
"The URL
{
initial_url
}
ultimately redirects to
{
url
}
."
)
return
response
url
=
response
.
url
if
not
isinstance
(
request
,
Request
):
else
:
return
fn
(
url
,
*
args
,
**
kwargs
)
raise
RecursionError
(
f
"Request to
{
initial_url
}
exceeded
{
max_redirects
}
redirects."
)
request_attrs
=
{
attr
:
getattr
(
request
,
attr
)
for
attr
in
(
"data"
,
"headers"
,
"origin_req_host"
,
"unverifiable"
)
}
# the 'method' attribute does only exist if the request was created with it
if
hasattr
(
request
,
"method"
):
request_attrs
[
"method"
]
=
request
.
method
return
fn
(
Request
(
url
,
**
request_attrs
),
*
args
,
**
kwargs
)
return
inner_wrapper
return
inner_wrapper
...
@@ -150,7 +162,7 @@ def assert_server_response_ok():
...
@@ -150,7 +162,7 @@ def assert_server_response_ok():
def
assert_url_is_accessible
(
url
,
timeout
=
5.0
):
def
assert_url_is_accessible
(
url
,
timeout
=
5.0
):
request
=
Request
(
url
,
headers
=
{
"method"
:
"HEAD"
,
"User-Agent"
:
USER_AGENT
})
request
=
Request
(
url
,
headers
=
{
"User-Agent"
:
USER_AGENT
}
,
method
=
"HEAD"
)
with
assert_server_response_ok
():
with
assert_server_response_ok
():
urlopen
(
request
,
timeout
=
timeout
)
urlopen
(
request
,
timeout
=
timeout
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment