Skip to content

Commit

Permalink
Move test from test_hydra to test_config_loader
Browse files Browse the repository at this point in the history
  • Loading branch information
odelalleau committed Dec 16, 2020
1 parent 0b53209 commit 6bcaac2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
32 changes: 32 additions & 0 deletions tests/test_config_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
32 changes: 0 additions & 32 deletions tests/test_hydra.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)

0 comments on commit 6bcaac2

Please sign in to comment.