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
2786a124
Unverified
Commit
2786a124
authored
Jun 14, 2021
by
Nicolas Hug
Committed by
GitHub
Jun 14, 2021
Browse files
Port test_internet.py to pytest and add pytest-mock dependency (#4032)
parent
508b289c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
17 deletions
+18
-17
.circleci/unittest/linux/scripts/environment.yml
.circleci/unittest/linux/scripts/environment.yml
+1
-0
.circleci/unittest/windows/scripts/environment.yml
.circleci/unittest/windows/scripts/environment.yml
+1
-0
CONTRIBUTING.md
CONTRIBUTING.md
+1
-1
test/test_internet.py
test/test_internet.py
+15
-16
No files found.
.circleci/unittest/linux/scripts/environment.yml
View file @
2786a124
...
...
@@ -6,6 +6,7 @@ channels:
dependencies
:
-
pytest
-
pytest-cov
-
pytest-mock
-
pip
-
libpng
# NOTE: Pinned to fix issues with size_t on Windows
...
...
.circleci/unittest/windows/scripts/environment.yml
View file @
2786a124
...
...
@@ -6,6 +6,7 @@ channels:
dependencies
:
-
pytest
-
pytest-cov
-
pytest-mock
-
pip
-
libpng
# NOTE: Pinned to fix issues with size_t on Windows
...
...
CONTRIBUTING.md
View file @
2786a124
...
...
@@ -49,7 +49,7 @@ python setup.py develop
# MACOSX_DEPLOYMENT_TARGET=10.9 CC=clang CXX=clang++ python setup.py develop
# for C++ debugging, please use DEBUG=1
# DEBUG=1 python setup.py develop
pip
install
flake8 typing mypy pytest scipy
pip
install
flake8 typing mypy pytest
pytest-mock
scipy
```
You may also have to install
`libpng-dev`
and
`libjpeg-turbo8-dev`
libraries:
```
bash
...
...
test/test_internet.py
View file @
2786a124
...
...
@@ -6,8 +6,7 @@ cleanly ignored in FB internal test infra.
"""
import
os
import
unittest
import
unittest.mock
import
pytest
import
warnings
from
urllib.error
import
URLError
...
...
@@ -15,7 +14,7 @@ import torchvision.datasets.utils as utils
from
common_utils
import
get_tmp_dir
class
DatasetUtils
Tester
(
unittest
.
TestCase
)
:
class
Test
DatasetUtils
:
def
test_get_redirect_url
(
self
):
url
=
"http://www.vision.caltech.edu/visipedia-data/CUB-200-2011/CUB_200_2011.tgz"
...
...
@@ -26,7 +25,7 @@ class DatasetUtilsTester(unittest.TestCase):
def
test_get_redirect_url_max_hops_exceeded
(
self
):
url
=
"http://www.vision.caltech.edu/visipedia-data/CUB-200-2011/CUB_200_2011.tgz"
with
self
.
assertR
aises
(
RecursionError
):
with
pytest
.
r
aises
(
RecursionError
):
utils
.
_get_redirect_url
(
url
,
max_hops
=
0
)
def
test_download_url
(
self
):
...
...
@@ -34,38 +33,38 @@ class DatasetUtilsTester(unittest.TestCase):
url
=
"http://github.com/pytorch/vision/archive/master.zip"
try
:
utils
.
download_url
(
url
,
temp_dir
)
self
.
assert
False
(
len
(
os
.
listdir
(
temp_dir
))
=
=
0
)
assert
len
(
os
.
listdir
(
temp_dir
))
!
=
0
except
URLError
:
msg
=
"could not download test file '{}'"
.
format
(
url
)
warnings
.
warn
(
msg
,
RuntimeWarning
)
raise
unittest
.
SkipTest
(
msg
)
pytest
.
skip
(
f
"could not download test file '
{
url
}
'"
)
def
test_download_url_retry_http
(
self
):
with
get_tmp_dir
()
as
temp_dir
:
url
=
"https://github.com/pytorch/vision/archive/master.zip"
try
:
utils
.
download_url
(
url
,
temp_dir
)
self
.
assert
False
(
len
(
os
.
listdir
(
temp_dir
))
=
=
0
)
assert
len
(
os
.
listdir
(
temp_dir
))
!
=
0
except
URLError
:
msg
=
"could not download test file '{}'"
.
format
(
url
)
warnings
.
warn
(
msg
,
RuntimeWarning
)
raise
unittest
.
SkipTest
(
msg
)
pytest
.
skip
(
f
"could not download test file '
{
url
}
'"
)
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
.
assertR
aises
(
URLError
):
with
pytest
.
r
aises
(
URLError
):
utils
.
download_url
(
url
,
temp_dir
)
@
unittest
.
mock
.
patch
(
"torchvision.datasets.utils.download_file_from_google_drive"
)
def
test_download_url_dispatch_download_from_google_drive
(
self
,
mock
):
def
test_download_url_dispatch_download_from_google_drive
(
self
,
mocker
):
url
=
"https://drive.google.com/file/d/1hbzc_P1FuxMkcabkgn9ZKinBwW683j45/view"
id
=
"1hbzc_P1FuxMkcabkgn9ZKinBwW683j45"
filename
=
"filename"
md5
=
"md5"
mocked
=
mocker
.
patch
(
'torchvision.datasets.utils.download_file_from_google_drive'
)
with
get_tmp_dir
()
as
root
:
utils
.
download_url
(
url
,
root
,
filename
,
md5
)
mock
.
assert_called_once_with
(
id
,
root
,
filename
,
md5
)
mocked
.
assert_called_once_with
(
id
,
root
,
filename
,
md5
)
if
__name__
==
'__main__'
:
pytest
.
main
([
__file__
])
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