Skip to content

Commit

Permalink
Add get_config and get_model test
Browse files Browse the repository at this point in the history
  • Loading branch information
HAOCHENYE committed Mar 10, 2022
1 parent 45221f8 commit 5342f51
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions tests/test_config/test_collect_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

from mmengine.config.collect_meta import (_get_external_cfg_base_path,
_parse_external_cfg_path,
_parse_rel_cfg_path)
_parse_cfg_name)


def test_get_external_cfg_base_path(tmp_path):
package_path = tmp_path
rel_cfg_path = 'cfg_dir/cfg_file'
with pytest.raises(FileNotFoundError):
_get_external_cfg_base_path(str(package_path), rel_cfg_path)
cfg_dir = tmp_path / '.mmengine' / 'configs' / 'cfg_dir'
cfg_dir = tmp_path / '.mim' / 'configs' / 'cfg_dir'
cfg_dir.mkdir(parents=True, exist_ok=True)
f = open(cfg_dir / 'cfg_file', 'w')
f.close()
Expand All @@ -22,20 +22,20 @@ def test_get_external_cfg_base_path(tmp_path):


def test_parse_external_cfg_path():
external_cfg_path = 'package::path/cfg'
external_cfg_path = 'mmdet::path/cfg'
package, rel_cfg_path = _parse_external_cfg_path(external_cfg_path)
assert package == 'package'
assert package == 'mmdet'
assert rel_cfg_path == 'path/cfg'
# external config must contain `::`.
external_cfg_path = 'path/cfg'
with pytest.raises(ValueError):
_parse_external_cfg_path(external_cfg_path)
# Use `:::` as operator will raise an error.
external_cfg_path = 'package:::path/cfg'
external_cfg_path = 'mmdet:::path/cfg'
with pytest.raises(ValueError):
_parse_external_cfg_path(external_cfg_path)
# Use `:` as operator will raise an error.
external_cfg_path = 'package:path/cfg'
external_cfg_path = 'mmdet:path/cfg'
with pytest.raises(ValueError):
_parse_external_cfg_path(external_cfg_path)
# Too much `::`
Expand All @@ -46,8 +46,5 @@ def test_parse_external_cfg_path():

def test_parse_rel_cfg_path():
rel_cfg_path = 'cfg_dir/cfg_file'
rel_cfg_dir, rel_cfg_file = _parse_rel_cfg_path(rel_cfg_path)
assert rel_cfg_dir == 'cfg_dir'
assert rel_cfg_file == 'cfg_file'
with pytest.raises(AssertionError):
_parse_rel_cfg_path('error/cfg_dir/cfg_file')
cfg_name = _parse_cfg_name(rel_cfg_path)
assert cfg_name == 'cfg_file'

0 comments on commit 5342f51

Please sign in to comment.