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
MMCV
Commits
b98980b7
Commit
b98980b7
authored
Oct 07, 2018
by
Kai Chen
Browse files
add some unit tests
parent
ecfce392
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
2 deletions
+35
-2
mmcv/utils/path.py
mmcv/utils/path.py
+1
-1
tests/test_arraymisc.py
tests/test_arraymisc.py
+15
-0
tests/test_config.py
tests/test_config.py
+6
-1
tests/test_path.py
tests/test_path.py
+13
-0
No files found.
mmcv/utils/path.py
View file @
b98980b7
...
@@ -40,7 +40,7 @@ def mkdir_or_exist(dir_name, mode=0o777):
...
@@ -40,7 +40,7 @@ def mkdir_or_exist(dir_name, mode=0o777):
os
.
makedirs
(
dir_name
,
mode
=
mode
,
exist_ok
=
True
)
os
.
makedirs
(
dir_name
,
mode
=
mode
,
exist_ok
=
True
)
else
:
else
:
if
not
osp
.
isdir
(
dir_name
):
if
not
osp
.
isdir
(
dir_name
):
os
.
makedirs
(
dir_name
,
mode
=
0o777
)
os
.
makedirs
(
dir_name
,
mode
=
mode
)
def
symlink
(
src
,
dst
,
overwrite
=
True
,
**
kwargs
):
def
symlink
(
src
,
dst
,
overwrite
=
True
,
**
kwargs
):
...
...
tests/test_arraymisc.py
View file @
b98980b7
...
@@ -2,6 +2,7 @@ from __future__ import division
...
@@ -2,6 +2,7 @@ from __future__ import division
import
mmcv
import
mmcv
import
numpy
as
np
import
numpy
as
np
import
pytest
def
test_quantize
():
def
test_quantize
():
...
@@ -21,6 +22,13 @@ def test_quantize():
...
@@ -21,6 +22,13 @@ def test_quantize():
assert
qarr
.
shape
==
arr
.
shape
assert
qarr
.
shape
==
arr
.
shape
assert
qarr
.
dtype
==
np
.
dtype
(
'uint8'
)
assert
qarr
.
dtype
==
np
.
dtype
(
'uint8'
)
with
pytest
.
raises
(
ValueError
):
mmcv
.
quantize
(
arr
,
-
1
,
1
,
levels
=
0
)
with
pytest
.
raises
(
ValueError
):
mmcv
.
quantize
(
arr
,
-
1
,
1
,
levels
=
10.0
)
with
pytest
.
raises
(
ValueError
):
mmcv
.
quantize
(
arr
,
2
,
1
,
levels
)
def
test_dequantize
():
def
test_dequantize
():
levels
=
20
levels
=
20
...
@@ -37,6 +45,13 @@ def test_dequantize():
...
@@ -37,6 +45,13 @@ def test_dequantize():
assert
arr
.
shape
==
qarr
.
shape
assert
arr
.
shape
==
qarr
.
shape
assert
arr
.
dtype
==
np
.
dtype
(
'float32'
)
assert
arr
.
dtype
==
np
.
dtype
(
'float32'
)
with
pytest
.
raises
(
ValueError
):
mmcv
.
dequantize
(
arr
,
-
1
,
1
,
levels
=
0
)
with
pytest
.
raises
(
ValueError
):
mmcv
.
dequantize
(
arr
,
-
1
,
1
,
levels
=
10.0
)
with
pytest
.
raises
(
ValueError
):
mmcv
.
dequantize
(
arr
,
2
,
1
,
levels
)
def
test_joint
():
def
test_joint
():
arr
=
np
.
random
.
randn
(
100
,
100
)
arr
=
np
.
random
.
randn
(
100
,
100
)
...
...
tests/test_config.py
View file @
b98980b7
...
@@ -4,13 +4,16 @@ import pytest
...
@@ -4,13 +4,16 @@ import pytest
from
mmcv
import
Config
,
FileNotFoundError
from
mmcv
import
Config
,
FileNotFoundError
def
test_
empty
():
def
test_
construct
():
cfg
=
Config
()
cfg
=
Config
()
assert
cfg
.
filename
is
None
assert
cfg
.
filename
is
None
assert
cfg
.
text
==
''
assert
cfg
.
text
==
''
assert
len
(
cfg
)
==
0
assert
len
(
cfg
)
==
0
assert
cfg
.
_cfg_dict
==
{}
assert
cfg
.
_cfg_dict
==
{}
with
pytest
.
raises
(
TypeError
):
Config
([
0
,
1
])
def
test_fromfile
():
def
test_fromfile
():
for
filename
in
[
'a.py'
,
'b.json'
,
'c.yaml'
]:
for
filename
in
[
'a.py'
,
'b.json'
,
'c.yaml'
]:
...
@@ -24,6 +27,8 @@ def test_fromfile():
...
@@ -24,6 +27,8 @@ def test_fromfile():
Config
.
fromfile
(
'no_such_file.py'
)
Config
.
fromfile
(
'no_such_file.py'
)
with
pytest
.
raises
(
ValueError
):
with
pytest
.
raises
(
ValueError
):
Config
.
fromfile
(
osp
.
join
(
osp
.
dirname
(
__file__
),
'data/config/a.b.py'
))
Config
.
fromfile
(
osp
.
join
(
osp
.
dirname
(
__file__
),
'data/config/a.b.py'
))
with
pytest
.
raises
(
IOError
):
Config
.
fromfile
(
osp
.
join
(
osp
.
dirname
(
__file__
),
'data/color.jpg'
))
def
test_dict
():
def
test_dict
():
...
...
tests/test_path.py
View file @
b98980b7
import
os.path
as
osp
import
os.path
as
osp
import
sys
import
sys
from
pathlib
import
Path
import
mmcv
import
mmcv
import
pytest
import
pytest
def
test_is_filepath
():
assert
mmcv
.
is_filepath
(
__file__
)
assert
mmcv
.
is_filepath
(
'abc'
)
assert
mmcv
.
is_filepath
(
Path
(
'/etc'
))
assert
not
mmcv
.
is_filepath
(
0
)
def
test_fopen
():
assert
hasattr
(
mmcv
.
fopen
(
__file__
),
'read'
)
assert
hasattr
(
Path
(
__file__
),
'read'
)
def
test_check_file_exist
():
def
test_check_file_exist
():
mmcv
.
check_file_exist
(
__file__
)
mmcv
.
check_file_exist
(
__file__
)
if
sys
.
version_info
>
(
3
,
3
):
if
sys
.
version_info
>
(
3
,
3
):
...
...
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