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
Show 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:
...
@@ -6,6 +6,7 @@ channels:
dependencies
:
dependencies
:
-
pytest
-
pytest
-
pytest-cov
-
pytest-cov
-
pytest-mock
-
pip
-
pip
-
libpng
-
libpng
# NOTE: Pinned to fix issues with size_t on Windows
# NOTE: Pinned to fix issues with size_t on Windows
...
...
.circleci/unittest/windows/scripts/environment.yml
View file @
2786a124
...
@@ -6,6 +6,7 @@ channels:
...
@@ -6,6 +6,7 @@ channels:
dependencies
:
dependencies
:
-
pytest
-
pytest
-
pytest-cov
-
pytest-cov
-
pytest-mock
-
pip
-
pip
-
libpng
-
libpng
# NOTE: Pinned to fix issues with size_t on Windows
# NOTE: Pinned to fix issues with size_t on Windows
...
...
CONTRIBUTING.md
View file @
2786a124
...
@@ -49,7 +49,7 @@ python setup.py develop
...
@@ -49,7 +49,7 @@ python setup.py develop
# MACOSX_DEPLOYMENT_TARGET=10.9 CC=clang CXX=clang++ python setup.py develop
# MACOSX_DEPLOYMENT_TARGET=10.9 CC=clang CXX=clang++ python setup.py develop
# for C++ debugging, please use DEBUG=1
# for C++ debugging, please use DEBUG=1
# DEBUG=1 python setup.py develop
# 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:
You may also have to install
`libpng-dev`
and
`libjpeg-turbo8-dev`
libraries:
```
bash
```
bash
...
...
test/test_internet.py
View file @
2786a124
...
@@ -6,8 +6,7 @@ cleanly ignored in FB internal test infra.
...
@@ -6,8 +6,7 @@ cleanly ignored in FB internal test infra.
"""
"""
import
os
import
os
import
unittest
import
pytest
import
unittest.mock
import
warnings
import
warnings
from
urllib.error
import
URLError
from
urllib.error
import
URLError
...
@@ -15,7 +14,7 @@ import torchvision.datasets.utils as utils
...
@@ -15,7 +14,7 @@ import torchvision.datasets.utils as utils
from
common_utils
import
get_tmp_dir
from
common_utils
import
get_tmp_dir
class
DatasetUtils
Tester
(
unittest
.
TestCase
)
:
class
Test
DatasetUtils
:
def
test_get_redirect_url
(
self
):
def
test_get_redirect_url
(
self
):
url
=
"http://www.vision.caltech.edu/visipedia-data/CUB-200-2011/CUB_200_2011.tgz"
url
=
"http://www.vision.caltech.edu/visipedia-data/CUB-200-2011/CUB_200_2011.tgz"
...
@@ -26,7 +25,7 @@ class DatasetUtilsTester(unittest.TestCase):
...
@@ -26,7 +25,7 @@ class DatasetUtilsTester(unittest.TestCase):
def
test_get_redirect_url_max_hops_exceeded
(
self
):
def
test_get_redirect_url_max_hops_exceeded
(
self
):
url
=
"http://www.vision.caltech.edu/visipedia-data/CUB-200-2011/CUB_200_2011.tgz"
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
)
utils
.
_get_redirect_url
(
url
,
max_hops
=
0
)
def
test_download_url
(
self
):
def
test_download_url
(
self
):
...
@@ -34,38 +33,38 @@ class DatasetUtilsTester(unittest.TestCase):
...
@@ -34,38 +33,38 @@ class DatasetUtilsTester(unittest.TestCase):
url
=
"http://github.com/pytorch/vision/archive/master.zip"
url
=
"http://github.com/pytorch/vision/archive/master.zip"
try
:
try
:
utils
.
download_url
(
url
,
temp_dir
)
utils
.
download_url
(
url
,
temp_dir
)
self
.
assert
False
(
len
(
os
.
listdir
(
temp_dir
))
=
=
0
)
assert
len
(
os
.
listdir
(
temp_dir
))
!
=
0
except
URLError
:
except
URLError
:
msg
=
"could not download test file '{}'"
.
format
(
url
)
pytest
.
skip
(
f
"could not download test file '
{
url
}
'"
)
warnings
.
warn
(
msg
,
RuntimeWarning
)
raise
unittest
.
SkipTest
(
msg
)
def
test_download_url_retry_http
(
self
):
def
test_download_url_retry_http
(
self
):
with
get_tmp_dir
()
as
temp_dir
:
with
get_tmp_dir
()
as
temp_dir
:
url
=
"https://github.com/pytorch/vision/archive/master.zip"
url
=
"https://github.com/pytorch/vision/archive/master.zip"
try
:
try
:
utils
.
download_url
(
url
,
temp_dir
)
utils
.
download_url
(
url
,
temp_dir
)
self
.
assert
False
(
len
(
os
.
listdir
(
temp_dir
))
=
=
0
)
assert
len
(
os
.
listdir
(
temp_dir
))
!
=
0
except
URLError
:
except
URLError
:
msg
=
"could not download test file '{}'"
.
format
(
url
)
pytest
.
skip
(
f
"could not download test file '
{
url
}
'"
)
warnings
.
warn
(
msg
,
RuntimeWarning
)
raise
unittest
.
SkipTest
(
msg
)
def
test_download_url_dont_exist
(
self
):
def
test_download_url_dont_exist
(
self
):
with
get_tmp_dir
()
as
temp_dir
:
with
get_tmp_dir
()
as
temp_dir
:
url
=
"http://github.com/pytorch/vision/archive/this_doesnt_exist.zip"
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
)
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
,
mocker
):
def
test_download_url_dispatch_download_from_google_drive
(
self
,
mock
):
url
=
"https://drive.google.com/file/d/1hbzc_P1FuxMkcabkgn9ZKinBwW683j45/view"
url
=
"https://drive.google.com/file/d/1hbzc_P1FuxMkcabkgn9ZKinBwW683j45/view"
id
=
"1hbzc_P1FuxMkcabkgn9ZKinBwW683j45"
id
=
"1hbzc_P1FuxMkcabkgn9ZKinBwW683j45"
filename
=
"filename"
filename
=
"filename"
md5
=
"md5"
md5
=
"md5"
mocked
=
mocker
.
patch
(
'torchvision.datasets.utils.download_file_from_google_drive'
)
with
get_tmp_dir
()
as
root
:
with
get_tmp_dir
()
as
root
:
utils
.
download_url
(
url
,
root
,
filename
,
md5
)
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