예제 #1
0
def test_app_without_config___no_overrides(
    task_runner, calling_file, calling_module  # noqa: F811
):
    with task_runner(
        calling_file=calling_file, calling_module=calling_module, config_path=""
    ) as task:
        assert task.job_ret.cfg == {}
예제 #2
0
def test_missing_conf_file(task_runner, calling_file, calling_module):  # noqa: F811
    with pytest.raises(MissingConfigException):
        with task_runner(
            calling_file=calling_file,
            calling_module=calling_module,
            config_path="not_found.yaml",
        ):
            pass
예제 #3
0
def test_objects_example(tmpdir, task_runner, args, output_conf):  # noqa: F811
    with task_runner(
            calling_file="examples/patterns/objects/my_app.py",
            calling_module=None,
            config_path="conf/config.yaml",
            overrides=[],
    ) as task:
        assert task.job_ret.cfg == output_conf
        verify_dir_outputs(task.job_ret, overrides=task.overrides)
예제 #4
0
파일: test_hydra.py 프로젝트: zimaxeg/hydra
def test_app_without_config___no_overrides(
        task_runner: TTaskRunner,
        calling_file: str,
        calling_module: str  # noqa: F811
) -> None:
    with task_runner(calling_file=calling_file,
                     calling_module=calling_module,
                     config_path=None) as task:
        assert task.job_ret is not None
        assert task.job_ret.cfg == {}
예제 #5
0
def test_app_with_config_groups__override_all_configs(
    task_runner, calling_file, calling_module  # noqa: F811
):
    with task_runner(
        calling_file=calling_file,
        calling_module=calling_module,
        config_path="conf",
        overrides=["optimizer=adam", "optimizer.lr=10"],
    ) as task:
        assert task.job_ret.cfg == dict(optimizer=dict(type="adam", lr=10, beta=0.01))
        verify_dir_outputs(task.job_ret, overrides=task.overrides)
예제 #6
0
def test_app_with_split_config(task_runner, calling_file, calling_module):  # noqa: F811
    with task_runner(
        calling_file=calling_file,
        calling_module=calling_module,
        config_path="config.yaml",
    ) as task:
        assert task.job_ret.cfg == dict(
            dataset=dict(name="imagenet", path="/datasets/imagenet"),
            optimizer=dict(lr=0.001, type="nesterov"),
        )
        verify_dir_outputs(task.job_ret)
예제 #7
0
def test_app_without_config__with_overrides(
    task_runner, calling_file, calling_module  # noqa: F811
):
    with task_runner(
        calling_file=calling_file,
        calling_module=calling_module,
        config_path="",
        overrides=["abc=123", "a.b=1", "a.a=2"],
    ) as task:
        assert task.job_ret.cfg == dict(abc=123, a=dict(b=1, a=2))
        verify_dir_outputs(task.job_ret, task.overrides)
예제 #8
0
def test_specializing_config_example(task_runner):  # noqa: F811
    with task_runner(
            calling_file="examples/patterns/specializing_config/example.py",
            calling_module=None,
            config_path="conf/config.yaml",
            overrides=["dataset=cifar10"],
    ) as task:
        assert task.job_ret.cfg == dict(
            dataset=dict(name="cifar10", path="/datasets/cifar10"),
            model=dict(num_layers=5, type="alexnet"),
        )
        verify_dir_outputs(task.job_ret, overrides=task.overrides)
예제 #9
0
def test_composition_config_example(
        task_runner: TTaskRunner) -> None:  # noqa: F811
    with task_runner(
            calling_file="examples/tutorial/5_composition/my_app.py",
            calling_module=None,
            config_path="conf",
            config_name="config.yaml",
            overrides=["schema=school"],
    ) as task:
        assert task.job_ret is not None
        assert task.job_ret.cfg == {
            "db": {
                "driver": "mysql",
                "user": "******",
                "pass": "******"
            },
            "ui": {
                "windows": {
                    "create_db": True,
                    "view": True
                }
            },
            "schema": {
                "database":
                "school",
                "tables": [
                    {
                        "name": "students",
                        "fields": [{
                            "name": "string"
                        }, {
                            "class": "int"
                        }],
                    },
                    {
                        "name":
                        "exams",
                        "fields": [
                            {
                                "profession": "string"
                            },
                            {
                                "time": "data"
                            },
                            {
                                "class": "int"
                            },
                        ],
                    },
                ],
            },
        }
        verify_dir_outputs(task.job_ret, overrides=task.overrides)
예제 #10
0
def test_interpolating_dir_hydra_to_app(
    task_runner, calling_file, calling_module  # noqa: F811
):
    basedir = "foo"
    with task_runner(
        calling_file=calling_file,
        calling_module=calling_module,
        config_path="config.yaml",
        overrides=["experiment.base_dir=" + basedir],
    ) as task:
        path = Path(task.temp_dir) / basedir
        assert path.exists()
예제 #11
0
def test_app_with_config_groups__override_dataset__wrong(
    task_runner, calling_file, calling_module  # noqa: F811
):
    with pytest.raises(MissingConfigException) as ex:
        with task_runner(
            calling_file=calling_file,
            calling_module=calling_module,
            config_path="conf",
            overrides=["optimizer=wrong_name"],
        ):
            pass
    assert sorted(ex.value.options) == sorted(["adam", "nesterov"])
예제 #12
0
파일: test_hydra.py 프로젝트: zimaxeg/hydra
def test_missing_conf_dir(
        task_runner: TTaskRunner,
        calling_file: str,
        calling_module: str  # noqa: F811
) -> None:
    with pytest.raises(MissingConfigException):
        with task_runner(
                calling_file=calling_file,
                calling_module=calling_module,
                config_path="dir_not_found",
        ):
            pass
예제 #13
0
def test_app_with_config_file__no_overrides(
    task_runner, calling_file, calling_module  # noqa: F811
):
    with task_runner(
        calling_file=calling_file,
        calling_module=calling_module,
        config_path="config.yaml",
    ) as task:
        assert task.job_ret.cfg == dict(
            dataset=dict(name="imagenet", path="/datasets/imagenet")
        )

        verify_dir_outputs(task.job_ret)
예제 #14
0
파일: test_hydra.py 프로젝트: zimaxeg/hydra
def test_app_with_config_file__with_overide(
        task_runner: TTaskRunner,
        calling_file: str,
        calling_module: str  # noqa: F811
) -> None:
    with task_runner(
            calling_file=calling_file,
            calling_module=calling_module,
            config_path="config.yaml",
            overrides=["dataset.path=/datasets/imagenet2"],
    ) as task:
        assert task.job_ret is not None and task.job_ret.cfg == dict(
            dataset=dict(name="imagenet", path="/datasets/imagenet2"))
        verify_dir_outputs(task.job_ret, task.overrides)
예제 #15
0
def test_app_with_sweep_cfg__override_to_basic_launcher(
        task_runner,
        calling_file,
        calling_module  # noqa: F811
):
    with task_runner(
            calling_file=calling_file,
            calling_module=calling_module,
            config_path="config.yaml",
            overrides=["hydra/launcher=basic"],
    ) as task:
        hydra_cfg = task.job_ret.hydra_cfg
        assert (hydra_cfg.hydra.launcher["class"] ==
                "hydra._internal.core_plugins.basic_launcher.BasicLauncher")
        assert task.job_ret.hydra_cfg.hydra.launcher.params or {} == {}
예제 #16
0
def test_objects_example(
    tmpdir: Path,
    task_runner: TTaskRunner,  # noqa: F811
    args: List[str],
    output_conf: DictConfig,
) -> None:
    with task_runner(
            calling_file="examples/patterns/objects/my_app.py",
            calling_module=None,
            config_path="conf/config.yaml",
            overrides=[],
    ) as task:
        assert task.job_ret is not None
        assert task.job_ret.cfg == output_conf
        verify_dir_outputs(task.job_ret, overrides=task.overrides)
예제 #17
0
파일: test_hydra.py 프로젝트: zimaxeg/hydra
def test_app_with_sweep_cfg__override_to_basic_launcher(
        task_runner: TTaskRunner,
        calling_file: str,
        calling_module: str  # noqa: F811
) -> None:
    with task_runner(
            calling_file=calling_file,
            calling_module=calling_module,
            config_path="config.yaml",
            overrides=["hydra/launcher=basic"],
    ) as task:
        assert task.job_ret is not None
        assert task.job_ret.hydra_cfg is not None
        hydra_cfg = task.job_ret.hydra_cfg
        assert (hydra_cfg.hydra.launcher["class"] ==
                "hydra._internal.core_plugins.basic_launcher.BasicLauncher")
        assert "params" not in task.job_ret.hydra_cfg.hydra.launcher