From 6bcaac2077f2d1b8a08010da102ffdf6f0ba1f2a Mon Sep 17 00:00:00 2001 From: Olivier Delalleau <507137+odelalleau@users.noreply.github.com> Date: Wed, 16 Dec 2020 17:24:52 -0500 Subject: [PATCH] Move test from test_hydra to test_config_loader --- tests/test_config_loader.py | 32 ++++++++++++++++++++++++++++++++ tests/test_hydra.py | 32 -------------------------------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/tests/test_config_loader.py b/tests/test_config_loader.py index d26893d80b6..2fa62d7d0f5 100644 --- a/tests/test_config_loader.py +++ b/tests/test_config_loader.py @@ -593,6 +593,38 @@ def test_sweep_config_cache( monkeypatch.setenv("HOME", "/another/home/dir/") assert sweep_cfg.home == os.getenv("HOME") + @pytest.mark.parametrize( # type: ignore + "key,expected", + [ + pytest.param("id123", "id123", id="id"), + pytest.param("123id", "123id", id="int_plus_id"), + pytest.param("'quoted_single'", "quoted_single", id="quoted_single"), + pytest.param('"quoted_double"', "quoted_double", id="quoted_double"), + pytest.param("'quoted_$(){}[]'", "quoted_$(){}[]", id="quoted_misc_chars"), + pytest.param("a/-\\+.$%*@", "a/-\\+.$%*@", id="unquoted_misc_chars"), + pytest.param("white space", "white space", id="whitespace"), + pytest.param( + "\\\\\\(\\)\\[\\]\\{\\}\\:\\=\\ \\\t\\,", + "\\()[]{}:= \t,", + id="unquoted_esc", + ), + ], + ) + def test_dict_key_formats( + self, hydra_restore_singletons: Any, path: str, key: str, expected: str + ) -> None: + """Test that we can assign dictionaries with keys that are not just IDs""" + config_loader = ConfigLoaderImpl( + config_search_path=create_config_search_path(path) + ) + cfg = config_loader.load_configuration( + config_name="config.yaml", + overrides=[f"+dict={{{key}: 123}}"], + run_mode=RunMode.RUN, + ) + assert "dict" in cfg + assert cfg.dict == {expected: 123} + @pytest.mark.parametrize( # type:ignore "config_file, overrides", diff --git a/tests/test_hydra.py b/tests/test_hydra.py index 18609d49184..d0dcb20c12f 100644 --- a/tests/test_hydra.py +++ b/tests/test_hydra.py @@ -1208,35 +1208,3 @@ def test_structured_with_none_list(monkeypatch: Any, tmpdir: Path) -> None: ] result, _err = get_run_output(cmd) assert result == "{'list': None}" - - -def test_overrides_dict_keys(tmpdir: Path) -> None: - """Test that different types of dictionary keys can be overridden""" - # Not currently testing non-string keys since they are not supported - # by OmegaConf. - cfg = OmegaConf.create( - { - "foo": { - "quoted_$(){}[]": 0, - "id123": 0, - "123id": 0, - "a/-\\+.$%*@": 0, - "\\()[]{}:= \t,": 0, - "white space": 0, - } - } - ) - integration_test( - tmpdir=tmpdir, - task_config=cfg, - overrides=[ - "foo={'quoted_$(){}[]': 1, id123: 1, 123id: 1, a/-\\+.$%*@: 1, " - "\\\\\\(\\)\\[\\]\\{\\}\\:\\=\\ \\\t\\,: 1, white space: 1}" - ], - prints=( - "','.join(map(repr, [cfg.foo[x] for x in [" - "'quoted_$(){}[]', 'id123', '123id', 'a/-\\+.$%*@', '\\()[]{}:= \t,', 'white space'" - "]]))" - ), - expected_outputs="1,1,1,1,1,1", - )