Example #1
0
def test_apply_overrides_to_defaults(input_defaults: List[str],
                                     overrides: List[str],
                                     expected: Any) -> None:
    defaults = ConfigLoaderImpl._parse_defaults(
        OmegaConf.create({"defaults": input_defaults}))

    parser = OverridesParser.create()
    if isinstance(expected, list):
        parsed_overrides = parser.parse_overrides(overrides=overrides)
        expected_defaults = ConfigLoaderImpl._parse_defaults(
            OmegaConf.create({"defaults": expected}))
        ConfigLoaderImpl._apply_overrides_to_defaults(
            overrides=parsed_overrides, defaults=defaults)
        assert defaults == expected_defaults
    else:
        with expected:
            parsed_overrides = parser.parse_overrides(overrides=overrides)
            ConfigLoaderImpl._apply_overrides_to_defaults(
                overrides=parsed_overrides, defaults=defaults)
Example #2
0
def test_delete_by_assigning_null_is_deprecated() -> None:
    msg = ("\nRemoving from the defaults list by assigning 'null' "
           "is deprecated and will be removed in Hydra 1.1."
           "\nUse ~db")

    defaults = ConfigLoaderImpl._parse_defaults(
        OmegaConf.create({"defaults": [{
            "db": "mysql"
        }]}))
    parsed_overrides = [ConfigLoaderImpl._parse_override("db=null")]

    with pytest.warns(expected_warning=UserWarning, match=re.escape(msg)):
        assert parsed_overrides[0].override.is_delete()
        ConfigLoaderImpl._apply_overrides_to_defaults(
            overrides=parsed_overrides, defaults=defaults)
        assert defaults == []