Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
ICV-mmengine_basecode
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Florian Schiffel
ICV-mmengine_basecode
Commits
a9ad09bd
Unverified
Commit
a9ad09bd
authored
2 years ago
by
Zaida Zhou
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[Fix] Fix utils ut (#458)
parent
6c607bd2
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
mmengine/utils/__init__.py
+2
-2
2 additions, 2 deletions
mmengine/utils/__init__.py
tests/test_utils/test_progressbar.py
+15
-14
15 additions, 14 deletions
tests/test_utils/test_progressbar.py
tests/test_utils/test_timer.py
+10
-9
10 additions, 9 deletions
tests/test_utils/test_timer.py
with
27 additions
and
25 deletions
mmengine/utils/__init__.py
+
2
−
2
View file @
a9ad09bd
...
...
@@ -18,7 +18,7 @@ from .progressbar import (ProgressBar, track_iter_progress,
track_parallel_progress
,
track_progress
)
from
.setup_env
import
set_multi_processing
from
.sync_bn
import
revert_sync_batchnorm
from
.timer
import
Timer
,
check_time
from
.timer
import
Timer
,
TimerError
,
check_time
from
.torch_ops
import
torch_meshgrid
from
.trace
import
is_jit_tracing
from
.version_utils
import
digit_version
,
get_git_hash
...
...
@@ -38,7 +38,7 @@ __all__ = [
'
ManagerMeta
'
,
'
ManagerMixin
'
,
'
set_multi_processing
'
,
'
has_batch_norm
'
,
'
is_abs
'
,
'
is_installed
'
,
'
call_command
'
,
'
get_installed_path
'
,
'
check_install_package
'
,
'
is_abs
'
,
'
revert_sync_batchnorm
'
,
'
collect_env
'
,
'
Timer
'
,
'
check_time
'
,
'
ProgressBar
'
,
'
track_iter_progress
'
,
'
Timer
'
,
'
check_time
'
,
'
TimerError
'
,
'
ProgressBar
'
,
'
track_iter_progress
'
,
'
track_parallel_progress
'
,
'
track_progress
'
,
'
torch_meshgrid
'
,
'
is_jit_tracing
'
]
This diff is collapsed.
Click to expand it.
tests/test_utils/test_progressbar.py
+
15
−
14
View file @
a9ad09bd
...
...
@@ -4,7 +4,7 @@ import time
from
io
import
StringIO
from
unittest.mock
import
patch
import
mm
cv
import
mm
engine
def
reset_string_io
(
io
):
...
...
@@ -18,20 +18,21 @@ class TestProgressBar:
out
=
StringIO
()
bar_width
=
20
# without total task num
prog_bar
=
mm
cv
.
ProgressBar
(
bar_width
=
bar_width
,
file
=
out
)
prog_bar
=
mm
engine
.
ProgressBar
(
bar_width
=
bar_width
,
file
=
out
)
assert
out
.
getvalue
()
==
'
completed: 0, elapsed: 0s
'
reset_string_io
(
out
)
prog_bar
=
mmcv
.
ProgressBar
(
bar_width
=
bar_width
,
start
=
False
,
file
=
out
)
prog_bar
=
mmengine
.
ProgressBar
(
bar_width
=
bar_width
,
start
=
False
,
file
=
out
)
assert
out
.
getvalue
()
==
''
reset_string_io
(
out
)
prog_bar
.
start
()
assert
out
.
getvalue
()
==
'
completed: 0, elapsed: 0s
'
# with total task num
reset_string_io
(
out
)
prog_bar
=
mm
cv
.
ProgressBar
(
10
,
bar_width
=
bar_width
,
file
=
out
)
prog_bar
=
mm
engine
.
ProgressBar
(
10
,
bar_width
=
bar_width
,
file
=
out
)
assert
out
.
getvalue
()
==
f
'
[
{
"
"
*
bar_width
}
] 0/10, elapsed: 0s, ETA:
'
reset_string_io
(
out
)
prog_bar
=
mm
cv
.
ProgressBar
(
prog_bar
=
mm
engine
.
ProgressBar
(
10
,
bar_width
=
bar_width
,
start
=
False
,
file
=
out
)
assert
out
.
getvalue
()
==
''
reset_string_io
(
out
)
...
...
@@ -42,14 +43,14 @@ class TestProgressBar:
out
=
StringIO
()
bar_width
=
20
# without total task num
prog_bar
=
mm
cv
.
ProgressBar
(
bar_width
=
bar_width
,
file
=
out
)
prog_bar
=
mm
engine
.
ProgressBar
(
bar_width
=
bar_width
,
file
=
out
)
time
.
sleep
(
1
)
reset_string_io
(
out
)
prog_bar
.
update
()
assert
out
.
getvalue
()
==
'
completed: 1, elapsed: 1s, 1.0 tasks/s
'
reset_string_io
(
out
)
# with total task num
prog_bar
=
mm
cv
.
ProgressBar
(
10
,
bar_width
=
bar_width
,
file
=
out
)
prog_bar
=
mm
engine
.
ProgressBar
(
10
,
bar_width
=
bar_width
,
file
=
out
)
time
.
sleep
(
1
)
reset_string_io
(
out
)
prog_bar
.
update
()
...
...
@@ -60,7 +61,7 @@ class TestProgressBar:
with
patch
.
dict
(
'
os.environ
'
,
{
'
COLUMNS
'
:
'
80
'
}):
out
=
StringIO
()
bar_width
=
20
prog_bar
=
mm
cv
.
ProgressBar
(
10
,
bar_width
=
bar_width
,
file
=
out
)
prog_bar
=
mm
engine
.
ProgressBar
(
10
,
bar_width
=
bar_width
,
file
=
out
)
time
.
sleep
(
1
)
reset_string_io
(
out
)
prog_bar
.
update
()
...
...
@@ -84,7 +85,7 @@ def sleep_1s(num):
def
test_track_progress_list
():
out
=
StringIO
()
ret
=
mm
cv
.
track_progress
(
sleep_1s
,
[
1
,
2
,
3
],
bar_width
=
3
,
file
=
out
)
ret
=
mm
engine
.
track_progress
(
sleep_1s
,
[
1
,
2
,
3
],
bar_width
=
3
,
file
=
out
)
assert
out
.
getvalue
()
==
(
'
[ ] 0/3, elapsed: 0s, ETA:
'
'
\r
[> ] 1/3, 1.0 task/s, elapsed: 1s, ETA: 2s
'
...
...
@@ -95,7 +96,7 @@ def test_track_progress_list():
def
test_track_progress_iterator
():
out
=
StringIO
()
ret
=
mm
cv
.
track_progress
(
ret
=
mm
engine
.
track_progress
(
sleep_1s
,
((
i
for
i
in
[
1
,
2
,
3
]),
3
),
bar_width
=
3
,
file
=
out
)
assert
out
.
getvalue
()
==
(
'
[ ] 0/3, elapsed: 0s, ETA:
'
...
...
@@ -108,7 +109,7 @@ def test_track_progress_iterator():
def
test_track_iter_progress
():
out
=
StringIO
()
ret
=
[]
for
num
in
mm
cv
.
track_iter_progress
([
1
,
2
,
3
],
bar_width
=
3
,
file
=
out
):
for
num
in
mm
engine
.
track_iter_progress
([
1
,
2
,
3
],
bar_width
=
3
,
file
=
out
):
ret
.
append
(
sleep_1s
(
num
))
assert
out
.
getvalue
()
==
(
'
[ ] 0/3, elapsed: 0s, ETA:
'
...
...
@@ -123,7 +124,7 @@ def test_track_enum_progress():
ret
=
[]
count
=
[]
for
i
,
num
in
enumerate
(
mm
cv
.
track_iter_progress
([
1
,
2
,
3
],
bar_width
=
3
,
file
=
out
)):
mm
engine
.
track_iter_progress
([
1
,
2
,
3
],
bar_width
=
3
,
file
=
out
)):
ret
.
append
(
sleep_1s
(
num
))
count
.
append
(
i
)
assert
out
.
getvalue
()
==
(
...
...
@@ -137,7 +138,7 @@ def test_track_enum_progress():
def
test_track_parallel_progress_list
():
out
=
StringIO
()
results
=
mm
cv
.
track_parallel_progress
(
results
=
mm
engine
.
track_parallel_progress
(
sleep_1s
,
[
1
,
2
,
3
,
4
],
2
,
bar_width
=
4
,
file
=
out
)
# The following cannot pass CI on Github Action
# assert out.getvalue() == (
...
...
@@ -151,7 +152,7 @@ def test_track_parallel_progress_list():
def
test_track_parallel_progress_iterator
():
out
=
StringIO
()
results
=
mm
cv
.
track_parallel_progress
(
results
=
mm
engine
.
track_parallel_progress
(
sleep_1s
,
((
i
for
i
in
[
1
,
2
,
3
,
4
]),
4
),
2
,
bar_width
=
4
,
file
=
out
)
# The following cannot pass CI on Github Action
# assert out.getvalue() == (
...
...
This diff is collapsed.
Click to expand it.
tests/test_utils/test_timer.py
+
10
−
9
View file @
a9ad09bd
# Copyright (c) OpenMMLab. All rights reserved.
import
time
import
mmcv
import
pytest
import
mmengine
def
test_timer_init
():
timer
=
mm
cv
.
Timer
(
start
=
False
)
timer
=
mm
engine
.
Timer
(
start
=
False
)
assert
not
timer
.
is_running
timer
.
start
()
assert
timer
.
is_running
timer
=
mm
cv
.
Timer
()
timer
=
mm
engine
.
Timer
()
assert
timer
.
is_running
def
test_timer_run
():
timer
=
mm
cv
.
Timer
()
timer
=
mm
engine
.
Timer
()
time
.
sleep
(
1
)
assert
abs
(
timer
.
since_start
()
-
1
)
<
1e-2
time
.
sleep
(
1
)
assert
abs
(
timer
.
since_last_check
()
-
1
)
<
1e-2
assert
abs
(
timer
.
since_start
()
-
2
)
<
1e-2
timer
=
mm
cv
.
Timer
(
False
)
with
pytest
.
raises
(
mm
cv
.
TimerError
):
timer
=
mm
engine
.
Timer
(
False
)
with
pytest
.
raises
(
mm
engine
.
TimerError
):
timer
.
since_start
()
with
pytest
.
raises
(
mm
cv
.
TimerError
):
with
pytest
.
raises
(
mm
engine
.
TimerError
):
timer
.
since_last_check
()
def
test_timer_context
(
capsys
):
with
mm
cv
.
Timer
():
with
mm
engine
.
Timer
():
time
.
sleep
(
1
)
out
,
_
=
capsys
.
readouterr
()
assert
abs
(
float
(
out
)
-
1
)
<
1e-2
with
mm
cv
.
Timer
(
print_tmpl
=
'
time: {:.1f}s
'
):
with
mm
engine
.
Timer
(
print_tmpl
=
'
time: {:.1f}s
'
):
time
.
sleep
(
1
)
out
,
_
=
capsys
.
readouterr
()
assert
out
==
'
time: 1.0s
\n
'
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment