Skip to content
Snippets Groups Projects
Unverified Commit b8e7c8ee authored by Mashiro's avatar Mashiro Committed by GitHub
Browse files

Fix test_auto_argparse when pytest has multiple arguments (#34)

parent e908959c
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,6 @@ import copy ...@@ -4,7 +4,6 @@ import copy
import os import os
import os.path as osp import os.path as osp
import platform import platform
import re
import shutil import shutil
import sys import sys
import tempfile import tempfile
...@@ -26,6 +25,11 @@ DELETE_KEY = '_delete_' ...@@ -26,6 +25,11 @@ DELETE_KEY = '_delete_'
DEPRECATION_KEY = '_deprecation_' DEPRECATION_KEY = '_deprecation_'
RESERVED_KEYS = ['filename', 'text', 'pretty_text'] RESERVED_KEYS = ['filename', 'text', 'pretty_text']
if platform.system() == 'Windows':
import regex as re
else:
import re # type: ignore
class ConfigDict(Dict): class ConfigDict(Dict):
"""A dictionary for config which has the same interface as python's built- """A dictionary for config which has the same interface as python's built-
......
# Copyright (c) OpenMMLab. All rights reserved. # Copyright (c) OpenMMLab. All rights reserved.
from mmcv import Config # isort:skip from mmengine import Config # isort:skip
cfg = Config.fromfile('tests/data/config/py_config/simple_config.py') cfg = Config.fromfile('tests/data/config/py_config/simple_config.py')
item5 = cfg.item1[0] + cfg.item2.a item5 = cfg.item1[0] + cfg.item2.a
...@@ -169,7 +169,9 @@ class TestConfig: ...@@ -169,7 +169,9 @@ class TestConfig:
cfg.merge_from_dict(input_options, allow_list_keys=True) cfg.merge_from_dict(input_options, allow_list_keys=True)
def test_auto_argparser(self): def test_auto_argparser(self):
tmp = sys.argv[1] # Temporarily make sys.argv only has one argument and keep backups
tmp = sys.argv[1:]
sys.argv = sys.argv[:2]
sys.argv[1] = osp.join( sys.argv[1] = osp.join(
self.data_path, self.data_path,
'config/py_config/test_merge_from_multiple_bases.py') 'config/py_config/test_merge_from_multiple_bases.py')
...@@ -181,7 +183,7 @@ class TestConfig: ...@@ -181,7 +183,7 @@ class TestConfig:
assert not getattr(args, key) 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.extend(tmp)
def test_dump(self, tmp_path): def test_dump(self, tmp_path):
file_path = 'config/py_config/test_merge_from_multiple_bases.py' file_path = 'config/py_config/test_merge_from_multiple_bases.py'
......
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