Beispiel #1
0
def test_load_strict():
    """
    Ensure that in strict mode we can override only things that are already in the config
    :return:
    """
    config_loader = ConfigLoader(
        config_search_path=create_search_path(["demos/3_config_file"]),
        config_file="config.yaml",
        strict_cfg=True,
    )
    cfg = config_loader.load_configuration(overrides=["dataset.name=foobar"])
    del cfg["hydra"]
    assert cfg == dict(dataset=dict(name="foobar", path="/datasets/imagenet"))
    with pytest.raises(KeyError):
        cfg.not_here

    with pytest.raises(KeyError):
        cfg.dataset.not_here

    config_loader = ConfigLoader(
        config_search_path=create_search_path(["demos/3_config_file"]),
        config_file="config.yaml",
        strict_cfg=True,
    )
    with pytest.raises(KeyError):
        config_loader.load_configuration(overrides=["dataset.bad_key=foobar"])
Beispiel #2
0
 def test_load_with_optional_default(self, path: str) -> None:
     config_loader = ConfigLoader(
         config_search_path=create_search_path([path]))
     cfg = config_loader.load_configuration(
         config_file="optional-default.yaml", overrides=[], strict=False)
     del cfg["hydra"]
     assert cfg == dict(foo=10)
Beispiel #3
0
def test_override_hydra_config_value_from_config_file() -> None:
    config_loader = ConfigLoader(
        config_search_path=create_search_path(["hydra/test_utils/configs"]))

    cfg = config_loader.load_configuration(
        config_file="overriding_output_dir.yaml", overrides=[], strict=False)
    assert cfg.hydra.run.dir == "foo"
Beispiel #4
0
def test_defaults_not_list_exception() -> None:
    config_loader = ConfigLoader(
        config_search_path=create_search_path(["hydra/test_utils/configs"]))
    with pytest.raises(ValueError):
        config_loader.load_configuration(config_file="defaults_not_list.yaml",
                                         overrides=[],
                                         strict=False)
Beispiel #5
0
 def test_load_with_missing_optional_default(self, path):
     config_loader = ConfigLoader(
         config_search_path=create_search_path([path]))
     cfg = config_loader.load_configuration(
         config_file="missing-optional-default.yaml", strict=False)
     del cfg["hydra"]
     assert cfg == {}
Beispiel #6
0
 def test_load_configuration(self, path: str) -> None:
     config_loader = ConfigLoader(config_search_path=create_search_path([path]))
     cfg = config_loader.load_configuration(
         config_file="config.yaml", strict=False, overrides=["abc=123"]
     )
     del cfg["hydra"]
     assert cfg == OmegaConf.create({"normal_yaml_config": True, "abc": 123})
Beispiel #7
0
 def test_load_yml_file(self, path):
     config_loader = ConfigLoader(
         config_search_path=create_search_path([path]))
     cfg = config_loader.load_configuration(config_file="config.yml",
                                            strict=False)
     del cfg["hydra"]
     assert cfg == dict(yml_file_here=True)
Beispiel #8
0
 def test_compose_file_with_dot(self, path: str) -> None:
     config_loader = ConfigLoader(config_search_path=create_search_path([path]))
     cfg = config_loader.load_configuration(
         config_file="compose.yaml", overrides=["group1=abc.cde"], strict=False
     )
     del cfg["hydra"]
     assert cfg == {"abc=cde": None, "bar": 100}
Beispiel #9
0
 def test_override_with_equals(self, path: str) -> None:
     config_loader = ConfigLoader(config_search_path=create_search_path([path]))
     cfg = config_loader.load_configuration(
         config_file="config.yaml", overrides=["abc='cde=12'"], strict=False
     )
     del cfg["hydra"]
     assert cfg == OmegaConf.create({"normal_yaml_config": True, "abc": "cde=12"})
Beispiel #10
0
def test_mixed_composition_order():
    """
    Tests that the order of mixed composition (defaults contains both config group and non config group
    items) is correct
    """
    config_loader = ConfigLoader(
        config_search_path=create_search_path(["hydra/test_utils/configs"]),
        strict_cfg=False,
        config_file="mixed_compose.yaml",
    )
    config_loader.load_configuration()
    assert config_loader.get_load_history() == [
        ("hydra.yaml", "pkg://hydra.conf", "hydra"),
        ("hydra/hydra_logging/default.yaml", "pkg://hydra.conf", "hydra"),
        ("hydra/job_logging/default.yaml", "pkg://hydra.conf", "hydra"),
        ("hydra/launcher/basic.yaml", "pkg://hydra.conf", "hydra"),
        ("hydra/sweeper/basic.yaml", "pkg://hydra.conf", "hydra"),
        ("hydra/output/default.yaml", "pkg://hydra.conf", "hydra"),
        ("hydra/help/default.yaml", "pkg://hydra.conf", "hydra"),
        ("hydra/hydra_help/default.yaml", "pkg://hydra.conf", "hydra"),
        ("mixed_compose.yaml", "hydra/test_utils/configs", "test"),
        ("some_config.yaml", "hydra/test_utils/configs", "test"),
        ("group1/file1.yaml", "hydra/test_utils/configs", "test"),
        ("config.yaml", "hydra/test_utils/configs", "test"),
    ]
Beispiel #11
0
def create_config_loader():
    return ConfigLoader(
        config_search_path=create_search_path(
            ["hydra/test_utils/configs/completion_test"], abspath=True),
        strict_cfg=False,
        config_file="config.yaml",
    )
Beispiel #12
0
 def test_change_run_dir_with_config(self, path):
     config_loader = ConfigLoader(
         config_search_path=create_search_path([path]),
         strict_cfg=False,
         config_file="overriding_run_dir.yaml",
     )
     cfg = config_loader.load_configuration(overrides=[])
     assert cfg.hydra.run.dir == "cde"
Beispiel #13
0
def test_load_with_missing_default():
    config_loader = ConfigLoader(
        config_search_path=create_search_path(["hydra/test_utils/configs"]),
        strict_cfg=False,
        config_file="missing-default.yaml",
    )
    with pytest.raises(MissingConfigException):
        config_loader.load_configuration()
Beispiel #14
0
 def test_change_run_dir_with_override(self, path: str) -> None:
     config_loader = ConfigLoader(config_search_path=create_search_path([path]))
     cfg = config_loader.load_configuration(
         config_file="overriding_run_dir.yaml",
         overrides=["hydra.run.dir=abc"],
         strict=False,
     )
     assert cfg.hydra.run.dir == "abc"
Beispiel #15
0
 def test_load_adding_group_not_in_default(self, path: str) -> None:
     config_loader = ConfigLoader(config_search_path=create_search_path([path]))
     cfg = config_loader.load_configuration(
         config_file="optional-default.yaml",
         overrides=["group2=file1"],
         strict=False,
     )
     del cfg["hydra"]
     assert cfg == dict(foo=10, bar=100)
Beispiel #16
0
 def test_compose_file_with_dot(self, path):
     config_loader = ConfigLoader(
         config_search_path=create_search_path([path]),
         strict_cfg=False,
         config_file="compose.yaml",
     )
     cfg = config_loader.load_configuration(["group1=abc.cde"])
     del cfg["hydra"]
     assert cfg == {"abc=cde": None, "bar": 100}
Beispiel #17
0
def test_load_with_optional_default():
    config_loader = ConfigLoader(
        config_search_path=create_search_path(["hydra/test_utils/configs"]),
        strict_cfg=False,
        config_file="optional-default.yaml",
    )
    cfg = config_loader.load_configuration()
    del cfg["hydra"]
    assert cfg == dict(foo=10)
Beispiel #18
0
def test_load_adding_group_not_in_default():
    config_loader = ConfigLoader(
        config_search_path=create_search_path(["hydra/test_utils/configs"]),
        strict_cfg=False,
        config_file="optional-default.yaml",
    )
    cfg = config_loader.load_configuration(["group2=file1"])
    del cfg["hydra"]
    assert cfg == dict(foo=10, bar=100)
Beispiel #19
0
def test_load_yml_file():
    config_loader = ConfigLoader(
        config_search_path=create_search_path(["hydra/test_utils/configs"]),
        strict_cfg=False,
        config_file="config.yml",
    )
    cfg = config_loader.load_configuration()
    del cfg["hydra"]
    assert cfg == dict(yml_file_here=True)
Beispiel #20
0
 def test_load_changing_group_in_default(self, path):
     config_loader = ConfigLoader(
         config_search_path=create_search_path([path]),
         strict_cfg=False,
         config_file="optional-default.yaml",
     )
     cfg = config_loader.load_configuration(["group1=file2"])
     del cfg["hydra"]
     assert cfg == dict(foo=20)
Beispiel #21
0
def test_override_run_dir_with_hydra_cfg():
    config_loader = ConfigLoader(
        config_search_path=create_search_path(
            ["demos/99_hydra_configuration/workdir/"]
        ),
        strict_cfg=False,
        config_file=None,
    )
    cfg = config_loader.load_configuration(overrides=["hydra.run.dir=abc"])
    assert cfg.hydra.run.dir == "abc"
Beispiel #22
0
def test_load_configuration():
    config_loader = ConfigLoader(
        config_search_path=create_search_path(["demos/3_config_file"]),
        strict_cfg=False,
        config_file="config.yaml",
    )
    cfg = config_loader.load_configuration(overrides=["abc=123"])
    del cfg["hydra"]
    assert cfg == OmegaConf.create(
        dict(abc=123, dataset=dict(name="imagenet", path="/datasets/imagenet"))
    )
Beispiel #23
0
def test_default_removal(config_file, overrides):
    config_loader = ConfigLoader(
        config_search_path=create_search_path(["hydra/test_utils/configs"]),
        strict_cfg=False,
        config_file=config_file,
    )
    config_loader.load_configuration(overrides=overrides)
    assert config_loader.get_load_history() == [
        ("hydra.yaml", "pkg://hydra.conf", "hydra"),
        ("hydra/hydra_logging/default.yaml", "pkg://hydra.conf", "hydra"),
        ("hydra/job_logging/default.yaml", "pkg://hydra.conf", "hydra"),
        ("hydra/sweeper/basic.yaml", "pkg://hydra.conf", "hydra"),
        ("hydra/output/default.yaml", "pkg://hydra.conf", "hydra"),
        (config_file, "hydra/test_utils/configs", "test"),
    ]
Beispiel #24
0
def test_override_hydra_config_group_from_config_file():
    config_loader = ConfigLoader(
        config_search_path=create_search_path(["hydra/test_utils/configs"]),
        strict_cfg=False,
        config_file="overriding_logging_default.yaml",
    )

    config_loader.load_configuration(overrides=[])
    assert config_loader.get_load_history() == [
        ("hydra.yaml", "pkg://hydra.conf", "hydra"),
        ("hydra/hydra_logging/hydra_debug.yaml", "pkg://hydra.conf", "hydra"),
        ("hydra/job_logging/disabled.yaml", "pkg://hydra.conf", "hydra"),
        ("hydra/sweeper/basic.yaml", "pkg://hydra.conf", "hydra"),
        ("hydra/output/default.yaml", "pkg://hydra.conf", "hydra"),
        ("overriding_logging_default.yaml", "hydra/test_utils/configs", "test"),
    ]
Beispiel #25
0
def test_default_removal(config_file: str, overrides: List[str]) -> None:
    config_loader = ConfigLoader(
        config_search_path=create_search_path(["hydra/test_utils/configs"]))
    config_loader.load_configuration(config_file=config_file,
                                     overrides=overrides,
                                     strict=False)
    assert config_loader.get_load_history() == [
        ("hydra.yaml", "pkg://hydra.conf", "hydra"),
        ("hydra/hydra_logging/default.yaml", "pkg://hydra.conf", "hydra"),
        ("hydra/job_logging/default.yaml", "pkg://hydra.conf", "hydra"),
        ("hydra/sweeper/basic.yaml", "pkg://hydra.conf", "hydra"),
        ("hydra/output/default.yaml", "pkg://hydra.conf", "hydra"),
        ("hydra/help/default.yaml", "pkg://hydra.conf", "hydra"),
        ("hydra/hydra_help/default.yaml", "pkg://hydra.conf", "hydra"),
        (config_file, "file://hydra/test_utils/configs", "test"),
    ]
Beispiel #26
0
    def test_load_history_with_basic_launcher(self, path):
        config_loader = ConfigLoader(
            config_search_path=create_search_path([path]),
            strict_cfg=False,
            config_file="custom_default_launcher.yaml",
        )
        config_loader.load_configuration(overrides=["hydra/launcher=basic"])

        assert config_loader.get_load_history() == [
            ("hydra.yaml", "pkg://hydra.conf", "hydra"),
            ("hydra/hydra_logging/default.yaml", "pkg://hydra.conf", "hydra"),
            ("hydra/job_logging/default.yaml", "pkg://hydra.conf", "hydra"),
            ("hydra/launcher/basic.yaml", "pkg://hydra.conf", "hydra"),
            ("hydra/sweeper/basic.yaml", "pkg://hydra.conf", "hydra"),
            ("hydra/output/default.yaml", "pkg://hydra.conf", "hydra"),
            ("custom_default_launcher.yaml", path, "test"),
        ]
Beispiel #27
0
 def test_load_history(self, path):
     config_loader = ConfigLoader(
         config_search_path=create_search_path([path]))
     config_loader.load_configuration(
         config_file="missing-optional-default.yaml", strict=False)
     assert config_loader.get_load_history() == [
         ("hydra.yaml", "pkg://hydra.conf", "hydra"),
         ("hydra/hydra_logging/default.yaml", "pkg://hydra.conf", "hydra"),
         ("hydra/job_logging/default.yaml", "pkg://hydra.conf", "hydra"),
         ("hydra/launcher/basic.yaml", "pkg://hydra.conf", "hydra"),
         ("hydra/sweeper/basic.yaml", "pkg://hydra.conf", "hydra"),
         ("hydra/output/default.yaml", "pkg://hydra.conf", "hydra"),
         ("hydra/help/default.yaml", "pkg://hydra.conf", "hydra"),
         ("hydra/hydra_help/default.yaml", "pkg://hydra.conf", "hydra"),
         ("missing-optional-default.yaml", path, "test"),
         ("foo/missing.yaml", None, None),
     ]
Beispiel #28
0
def test_non_config_group_default():
    config_loader = ConfigLoader(config_search_path=create_search_path(
        ["hydra/test_utils/configs"]), )
    config_loader.load_configuration(
        config_file="non_config_group_default.yaml", strict=False)
    assert config_loader.get_load_history() == [
        ("hydra.yaml", "pkg://hydra.conf", "hydra"),
        ("hydra/hydra_logging/default.yaml", "pkg://hydra.conf", "hydra"),
        ("hydra/job_logging/default.yaml", "pkg://hydra.conf", "hydra"),
        ("hydra/launcher/basic.yaml", "pkg://hydra.conf", "hydra"),
        ("hydra/sweeper/basic.yaml", "pkg://hydra.conf", "hydra"),
        ("hydra/output/default.yaml", "pkg://hydra.conf", "hydra"),
        ("hydra/help/default.yaml", "pkg://hydra.conf", "hydra"),
        ("hydra/hydra_help/default.yaml", "pkg://hydra.conf", "hydra"),
        ("non_config_group_default.yaml", "hydra/test_utils/configs", "test"),
        ("some_config.yaml", "hydra/test_utils/configs", "test"),
    ]
Beispiel #29
0
def test_load_history():
    config_loader = ConfigLoader(
        config_search_path=create_search_path(["hydra/test_utils/configs"]),
        strict_cfg=False,
        config_file="missing-optional-default.yaml",
    )
    config_loader.load_configuration()
    assert config_loader.get_load_history() == [
        ("hydra.yaml", "pkg://hydra.conf", "hydra"),
        ("hydra/hydra_logging/default.yaml", "pkg://hydra.conf", "hydra"),
        ("hydra/job_logging/default.yaml", "pkg://hydra.conf", "hydra"),
        ("hydra/launcher/basic.yaml", "pkg://hydra.conf", "hydra"),
        ("hydra/sweeper/basic.yaml", "pkg://hydra.conf", "hydra"),
        ("hydra/output/default.yaml", "pkg://hydra.conf", "hydra"),
        ("missing-optional-default.yaml", "hydra/test_utils/configs", "test"),
        ("foo/missing.yaml", None, None),
    ]
Beispiel #30
0
def test_list_groups():
    config_loader = ConfigLoader(config_search_path=create_search_path(
        ["hydra/test_utils/configs"]), )
    groups = config_loader.list_groups("")
    assert sorted(groups) == [
        "completion_test", "db", "group1", "group2", "hydra"
    ]

    assert sorted(config_loader.list_groups("hydra")) == [
        "help",
        "hydra_help",
        "hydra_logging",
        "job_logging",
        "launcher",
        "output",
        "sweeper",
    ]