Skip to content
Snippets Groups Projects
Unverified Commit 6bd813c8 authored by Yifei Yang's avatar Yifei Yang Committed by GitHub
Browse files

[Feature] Add Config (#24)


* add config test

* Fix typo

Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* Update tests/config/test_config.py

Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* Reconstruct config test

* Fix import logic and error test

* Fix path error

* Restructuring Config

* simplify test logic

simplify test logic

* add config

* [Feature] Add Config

* fix lint

* remove test_config

* cancel change to pre-commit yaml

* solve conflict

* fix comments

* merge main

* fix lint

* update

* remove some magic docs

* Update mmengine/config/config.py

Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* Update mmengine/config/config.py

Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* Update mmengine/config/config.py

Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* add deprecation test

* Update mmengine/config/config.py

Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* Update mmengine/config/config.py

Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* Update mmengine/config/config.py

Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* Update mmengine/config/config.py

Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* Update mmengine/config/config.py

Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* Update mmengine/config/config.py

Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* Update mmengine/config/config.py

Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* Update mmengine/config/config.py

Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* Update mmengine/config/config.py

Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* Update mmengine/config/config.py

Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* Update mmengine/config/config.py

Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* Update mmengine/config/config.py

Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* Update mmengine/config/config.py

Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* Update mmengine/config/config.py

Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* Update mmengine/config/config.py

Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* Update mmengine/config/config.py

Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* Update mmengine/config/config.py

Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* Update mmengine/config/config.py

Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* Update mmengine/config/config.py

Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* Update mmengine/config/config.py

Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* Update mmengine/config/config.py

Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* Update mmengine/config/config.py

Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* Update mmengine/config/config.py

Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* Update mmengine/config/config.py

Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* Update mmengine/config/config.py

Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* Update mmengine/config/config.py

Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* update

* fix mypy

* fix lint

* fix super

* improve ut coverage

* add test dump

Co-authored-by: default avatarHAOCHENYE <21724054@zju.edu.cn>
Co-authored-by: default avatarMashiro <57566630+HAOCHENYE@users.noreply.github.com>
Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>
parent e2df3ed9
No related branches found
No related tags found
No related merge requests found
# Copyright (c) OpenMMLab. All rights reserved. # Copyright (c) OpenMMLab. All rights reserved.
# flake8: noqa # flake8: noqa
from .config import *
from .fileio import * from .fileio import *
from .registry import * from .registry import *
from .utils import * from .utils import *
# Copyright (c) OpenMMLab. All rights reserved.
from .config import Config, ConfigDict, DictAction
__all__ = ['Config', 'ConfigDict', 'DictAction']
This diff is collapsed.
# Copyright (c) OpenMMLab. All rights reserved.
_base_ = './base.py'
_deprecation_ = dict(
expected='tests/data/config/py_config/base.py', reference='')
# Copyright (c) OpenMMLab. All rights reserved.
_base_ = './test_deprecated.py'
...@@ -178,35 +178,34 @@ class TestConfig: ...@@ -178,35 +178,34 @@ class TestConfig:
assert args.config == sys.argv[1] assert args.config == sys.argv[1]
for key in cfg._cfg_dict.keys(): for key in cfg._cfg_dict.keys():
if not isinstance(cfg[key], ConfigDict): if not isinstance(cfg[key], ConfigDict):
assert getattr(args, key) is None assert not getattr(args, key)
# TODO currently do not support nested keys, bool args will be # TODO currently do not support nested keys, bool args will be
# overwritten by int # overwritten by int
sys.argv[1] = tmp sys.argv[1] = tmp
@pytest.mark.parametrize('file_path', [ def test_dump(self, tmp_path):
'config/py_config/simple_config.py', file_path = 'config/py_config/test_merge_from_multiple_bases.py'
'config/py_config/test_merge_from_multiple_bases.py'
])
def test_dump(self, file_path, tmp_path):
cfg_file = osp.join(self.data_path, file_path) cfg_file = osp.join(self.data_path, file_path)
cfg = Config.fromfile(cfg_file) cfg = Config.fromfile(cfg_file)
dump_py = tmp_path / 'simple_config.py' dump_py = tmp_path / 'simple_config.py'
dump_json = tmp_path / 'simple_config.json'
dump_yaml = tmp_path / 'simple_config.yaml'
cfg.dump(dump_py) cfg.dump(dump_py)
cfg.dump(dump_json)
cfg.dump(dump_yaml)
assert cfg.dump() == cfg.pretty_text assert cfg.dump() == cfg.pretty_text
assert open(dump_py, 'r').read() == cfg.pretty_text assert open(dump_py, 'r').read() == cfg.pretty_text
assert open(dump_json, 'r').read() == cfg.pretty_text
assert open(dump_yaml, 'r').read() == cfg.pretty_text # test dump json/yaml.
file_path = 'config/json_config/simple.config.json'
cfg_file = osp.join(self.data_path, file_path)
cfg = Config.fromfile(cfg_file)
dump_json = tmp_path / 'simple_config.json'
cfg.dump(dump_json)
with open(dump_json) as f:
assert f.read() == cfg.dump()
# test pickle # test pickle
cfg_file = osp.join(self.data_path, file_path = 'config/py_config/test_dump_pickle_support.py'
'config/py_config/test_dump_pickle_support.py') cfg_file = osp.join(self.data_path, file_path)
cfg = Config.fromfile(cfg_file) cfg = Config.fromfile(cfg_file)
text_cfg_filename = tmp_path / '_text_config.py' text_cfg_filename = tmp_path / '_text_config.py'
...@@ -395,6 +394,7 @@ class TestConfig: ...@@ -395,6 +394,7 @@ class TestConfig:
self._merge_delete() self._merge_delete()
self._merge_intermediate_variable() self._merge_intermediate_variable()
self._merge_recursive_bases() self._merge_recursive_bases()
self._deprecation()
def _simple_load(self): def _simple_load(self):
# test load simple config # test load simple config
...@@ -625,3 +625,15 @@ class TestConfig: ...@@ -625,3 +625,15 @@ class TestConfig:
assert cfg.cfg.item3 is True assert cfg.cfg.item3 is True
assert cfg.cfg.item4 == 'test' assert cfg.cfg.item4 == 'test'
assert cfg.item5 == 1 assert cfg.item5 == 1
def _deprecation(self):
deprecated_cfg_files = [
osp.join(self.data_path, 'config', 'py_config/test_deprecated.py'),
osp.join(self.data_path, 'config',
'py_config/test_deprecated_base.py')
]
for cfg_file in deprecated_cfg_files:
with pytest.warns(DeprecationWarning):
cfg = Config.fromfile(cfg_file)
assert cfg.item1 == [1, 2]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment