Skip to content

Commit

Permalink
fix misc and test set env
Browse files Browse the repository at this point in the history
  • Loading branch information
MeowZheng committed Feb 20, 2022
1 parent a120ea8 commit a7cd26a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 10 additions & 9 deletions tests/test_utils/test_misc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright (c) OpenMMLab. All rights reserved.
import os
import tempfile

from mmflow.utils import find_latest_checkpoint
Expand All @@ -11,33 +12,33 @@ def test_find_latest_checkpoint():
# There are no checkpoints in the path.
assert latest is None

path = tmpdir + '/none'
path = tmpdir + f'{os.sep}none'
latest = find_latest_checkpoint(path)

# The path does not exist.
assert latest is None

with tempfile.TemporaryDirectory() as tmpdir:
with open(tmpdir + '/latest.pth', 'w') as f:
with open(tmpdir + f'{os.sep}latest.pth', 'w') as f:
f.write('latest')
path = tmpdir
latest = find_latest_checkpoint(path)
assert latest == tmpdir + '/latest.pth'
assert latest == tmpdir + f'{os.sep}latest.pth'

with tempfile.TemporaryDirectory() as tmpdir:
with open(tmpdir + '/iter_4000.pth', 'w') as f:
with open(tmpdir + f'{os.sep}iter_4000.pth', 'w') as f:
f.write('iter_4000')
with open(tmpdir + '/iter_8000.pth', 'w') as f:
with open(tmpdir + f'{os.sep}iter_8000.pth', 'w') as f:
f.write('iter_8000')
path = tmpdir
latest = find_latest_checkpoint(path)
assert latest == tmpdir + '/iter_8000.pth'
assert latest == tmpdir + f'{os.sep}iter_8000.pth'

with tempfile.TemporaryDirectory() as tmpdir:
with open(tmpdir + '/epoch_1.pth', 'w') as f:
with open(tmpdir + f'{os.sep}epoch_1.pth', 'w') as f:
f.write('epoch_1')
with open(tmpdir + '/epoch_2.pth', 'w') as f:
with open(tmpdir + f'{os.sep}epoch_2.pth', 'w') as f:
f.write('epoch_2')
path = tmpdir
latest = find_latest_checkpoint(path)
assert latest == tmpdir + '/epoch_2.pth'
assert latest == tmpdir + f'{os.sep}epoch_2.pth'
2 changes: 1 addition & 1 deletion tests/test_utils/test_set_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_setup_multi_processes(workers_per_gpu, valid, env_cfg):
os.environ['MKL_NUM_THREADS'] = sys_mkl_threads

else:
assert mp.get_start_method() == sys_start_mehod
assert mp.get_start_method(allow_none=True) == sys_start_mehod
assert cv2.getNumThreads() == sys_cv_threads
assert 'OMP_NUM_THREADS' not in os.environ
assert 'MKL_NUM_THREADS' not in os.environ

0 comments on commit a7cd26a

Please sign in to comment.