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
2d6931ab
Unverified
Commit
2d6931ab
authored
Jun 10, 2021
by
Anirudh
Committed by
GitHub
Jun 10, 2021
Browse files
Port test_hub.py to pytest (#4038)
parent
ec40ac3a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
13 deletions
+11
-13
.circleci/config.yml
.circleci/config.yml
+1
-0
.circleci/config.yml.in
.circleci/config.yml.in
+1
-0
test/test_hub.py
test/test_hub.py
+9
-13
No files found.
.circleci/config.yml
View file @
2d6931ab
...
@@ -242,6 +242,7 @@ jobs:
...
@@ -242,6 +242,7 @@ jobs:
pip install --user --progress-bar off --pre torch -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
pip install --user --progress-bar off --pre torch -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
# need to install torchvision dependencies due to transitive imports
# need to install torchvision dependencies due to transitive imports
pip install --user --progress-bar off --editable .
pip install --user --progress-bar off --editable .
pip install pytest
python test/test_hub.py
python test/test_hub.py
torch_onnx_test
:
torch_onnx_test
:
...
...
.circleci/config.yml.in
View file @
2d6931ab
...
@@ -242,6 +242,7 @@ jobs:
...
@@ -242,6 +242,7 @@ jobs:
pip install --user --progress-bar off --pre torch -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
pip install --user --progress-bar off --pre torch -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
# need to install torchvision dependencies due to transitive imports
# need to install torchvision dependencies due to transitive imports
pip install --user --progress-bar off --editable .
pip install --user --progress-bar off --editable .
pip install pytest
python test/test_hub.py
python test/test_hub.py
torch_onnx_test:
torch_onnx_test:
...
...
test/test_hub.py
View file @
2d6931ab
...
@@ -3,7 +3,7 @@ import tempfile
...
@@ -3,7 +3,7 @@ import tempfile
import
shutil
import
shutil
import
os
import
os
import
sys
import
sys
import
unit
test
import
py
test
def
sum_of_model_parameters
(
model
):
def
sum_of_model_parameters
(
model
):
...
@@ -16,9 +16,9 @@ def sum_of_model_parameters(model):
...
@@ -16,9 +16,9 @@ def sum_of_model_parameters(model):
SUM_OF_PRETRAINED_RESNET18_PARAMS
=
-
12703.9931640625
SUM_OF_PRETRAINED_RESNET18_PARAMS
=
-
12703.9931640625
@
unit
test
.
skip
I
f
(
'torchvision'
in
sys
.
modules
,
@
py
test
.
mark
.
skip
i
f
(
'torchvision'
in
sys
.
modules
,
'TestHub must start without torchvision imported'
)
reason
=
'TestHub must start without torchvision imported'
)
class
TestHub
(
unittest
.
TestCase
)
:
class
TestHub
:
# Only run this check ONCE before all tests start.
# Only run this check ONCE before all tests start.
# - If torchvision is imported before all tests start, e.g. we might find _C.so
# - If torchvision is imported before all tests start, e.g. we might find _C.so
# which doesn't exist in downloaded zip but in the installed wheel.
# which doesn't exist in downloaded zip but in the installed wheel.
...
@@ -31,9 +31,7 @@ class TestHub(unittest.TestCase):
...
@@ -31,9 +31,7 @@ class TestHub(unittest.TestCase):
'resnet18'
,
'resnet18'
,
pretrained
=
True
,
pretrained
=
True
,
progress
=
False
)
progress
=
False
)
self
.
assertAlmostEqual
(
sum_of_model_parameters
(
hub_model
).
item
(),
assert
sum_of_model_parameters
(
hub_model
).
item
()
==
pytest
.
approx
(
SUM_OF_PRETRAINED_RESNET18_PARAMS
)
SUM_OF_PRETRAINED_RESNET18_PARAMS
,
places
=
2
)
def
test_set_dir
(
self
):
def
test_set_dir
(
self
):
temp_dir
=
tempfile
.
gettempdir
()
temp_dir
=
tempfile
.
gettempdir
()
...
@@ -43,16 +41,14 @@ class TestHub(unittest.TestCase):
...
@@ -43,16 +41,14 @@ class TestHub(unittest.TestCase):
'resnet18'
,
'resnet18'
,
pretrained
=
True
,
pretrained
=
True
,
progress
=
False
)
progress
=
False
)
self
.
assertAlmostEqual
(
sum_of_model_parameters
(
hub_model
).
item
(),
assert
sum_of_model_parameters
(
hub_model
).
item
()
==
pytest
.
approx
(
SUM_OF_PRETRAINED_RESNET18_PARAMS
)
SUM_OF_PRETRAINED_RESNET18_PARAMS
,
assert
os
.
path
.
exists
(
temp_dir
+
'/pytorch_vision_master'
)
places
=
2
)
self
.
assertTrue
(
os
.
path
.
exists
(
temp_dir
+
'/pytorch_vision_master'
))
shutil
.
rmtree
(
temp_dir
+
'/pytorch_vision_master'
)
shutil
.
rmtree
(
temp_dir
+
'/pytorch_vision_master'
)
def
test_list_entrypoints
(
self
):
def
test_list_entrypoints
(
self
):
entry_lists
=
hub
.
list
(
'pytorch/vision'
,
force_reload
=
True
)
entry_lists
=
hub
.
list
(
'pytorch/vision'
,
force_reload
=
True
)
self
.
assert
In
(
'resnet18'
,
entry_lists
)
assert
'resnet18'
in
entry_lists
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
unit
test
.
main
()
py
test
.
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