Beispiel #1
0
def test_frozen(tmpdir: Any) -> None:
    cmd = [
        sys.executable,
        "examples/patterns/write_protect_config_node/frozen.py",
        "hydra.run.dir=" + str(tmpdir),
        "data_bits=10",
    ]

    err = run_with_error(cmd)
    assert re.search(re.escape("Error merging override data_bits=10"), err) is not None
Beispiel #2
0
def test_multirun_structured_conflict(tmpdir: Any, overrides: List[str],
                                      error: bool, expected: Any) -> None:
    cmd = [
        sys.executable,
        "tests/test_apps/multirun_structured_conflict/my_app.py",
        "hydra.sweep.dir=" + str(tmpdir),
    ]
    cmd.extend(overrides)
    if error:
        ret = run_with_error(cmd)
        assert re.search(re.escape(expected), ret) is not None
    else:
        ret = normalize_newlines(
            str(subprocess.check_output(cmd).decode("utf-8"))).strip()
        assert ret == expected
Beispiel #3
0
    def test_run_with_missing_default(self, cmd_base: List[str], tmpdir: Any,
                                      sweep: bool) -> None:
        cmd = cmd_base + [
            "hydra.sweep.dir=" + str(tmpdir),
            "--config-name=unspecified_mandatory_default",
            "--config-path=../../../hydra/test_utils/configs",
        ]
        if sweep:
            cmd.append("-m")
        expected = """You must specify 'group1', e.g, group1=<OPTION>
Available options:
\tabc.cde
\tfile1
\tfile2"""
        ret = run_with_error(cmd)
        assert re.search(re.escape(expected), ret) is not None
Beispiel #4
0
def test_module_run(tmpdir: Any, directory: str, file: str, module: str,
                    error: Optional[str]) -> None:
    cmd = [
        sys.executable,
        directory + "/" + file,
        "hydra.run.dir=" + str(tmpdir),
    ]
    modified_env = os.environ.copy()
    modified_env["PYTHONPATH"] = directory
    modified_env["HYDRA_MAIN_MODULE"] = module
    if error is not None:
        ret = run_with_error(cmd, modified_env)
        assert re.search(re.escape(error), ret) is not None
    else:
        result = subprocess.check_output(cmd, env=modified_env)
        assert OmegaConf.create(str(result.decode("utf-8"))) == {"x": 10}
Beispiel #5
0
def test_run_with_missing_default(tmpdir: Any, sweep: bool) -> None:
    cmd = [
        sys.executable,
        "tests/test_apps/simple_app/my_app.py",
        "--config-name=unspecified_mandatory_default",
        "--config-path=../../../hydra/test_utils/configs",
        "hydra/hydra_logging=disabled",
        "hydra.sweep.dir=" + str(tmpdir),
    ]
    if sweep:
        cmd.append("-m")
    expected = """You must specify 'group1', e.g, group1=<OPTION>
Available options:
\tabc.cde
\tfile1
\tfile2"""
    ret = run_with_error(cmd)
    assert re.search(re.escape(expected), ret) is not None
Beispiel #6
0
def test_app_with_error_exception_sanitized(tmpdir: Any, monkeypatch: Any) -> None:
    monkeypatch.chdir("tests/test_apps/app_with_runtime_config_error")
    cmd = [
        sys.executable,
        "my_app.py",
        "hydra.sweep.dir=" + str(tmpdir),
    ]
    expected = """Traceback (most recent call last):
  File "my_app.py", line 13, in my_app
    foo(cfg)
  File "my_app.py", line 8, in foo
    cfg.foo = "bar"  # does not exist in the config
omegaconf.errors.ConfigAttributeError: Key 'foo' is not in struct
\tfull_key: foo
\treference_type=Optional[Dict[Any, Any]]
\tobject_type=dict

Set the environment variable HYDRA_FULL_ERROR=1 for a complete stack trace."""

    ret = run_with_error(cmd)
    assert normalize_newlines(expected) == normalize_newlines(ret)