示例#1
0
 def test_strict_failure_disabled_on_call(
     self,
     config_dir: str,
     hydra_global_context: TGlobalHydraContext,
     config_file: str,
     overrides: List[str],
     expected: Any,
 ) -> None:
     # default strict true, but call is false
     with hydra_global_context(config_dir=config_dir, strict=True):
         with does_not_raise():
             compose(config_name=config_file, overrides=overrides, strict=False)
示例#2
0
 def test_strict_failure_disabled_on_call(
     self,
     hydra_global_context,  # noqa: F811
     config_dir,
     config_file,
     overrides,
     expected,
 ):
     # default strict true, but call is false
     with hydra_global_context(config_dir=config_dir, strict=True):
         with does_not_raise():
             hydra.experimental.compose(config_file=config_file,
                                        overrides=overrides,
                                        strict=False)
示例#3
0
    def test_strict_failure_call_is_strict(
        self,
        config_dir: str,
        hydra_global_context: TGlobalHydraContext,
        config_file: str,
        overrides: List[str],
        expected: Any,
    ) -> None:
        # default strict false, but call is strict
        with hydra_global_context(config_dir=config_dir, strict=False):
            with pytest.raises(AttributeError):
                compose(config_name=config_file, overrides=overrides, strict=True)

        # default strict true, but call is false
        with hydra_global_context(config_dir=config_dir, strict=True):

            with does_not_raise():
                compose(config_name=config_file, overrides=overrides, strict=False)
示例#4
0
    def test_strict_failure_call_is_strict(
        self,
        hydra_global_context,  # noqa: F811
        config_dir,
        config_file,
        overrides,
        expected,
    ):
        # default strict false, but call is strict
        with hydra_global_context(config_dir=config_dir, strict=False):
            with pytest.raises(KeyError):
                hydra.experimental.compose(config_file=config_file,
                                           overrides=overrides,
                                           strict=True)

        # default strict true, but call is false
        with hydra_global_context(config_dir=config_dir, strict=True):

            with does_not_raise():
                hydra.experimental.compose(config_file=config_file,
                                           overrides=overrides,
                                           strict=False)
示例#5
0
        "hydra.run.dir=" + str(tmpdir),
    ]
    cmd.extend(args)
    result = subprocess.check_output(cmd)
    assert OmegaConf.create(str(result.decode("utf-8"))) == output_conf


@pytest.mark.parametrize(
    "args,expected",
    [
        (
            [],
            does_not_raise(
                OmegaConf.create({
                    "db": {
                        "driver": "mysql",
                        "pass": "******",
                        "user": "******"
                    }
                })),
        ),
        (["dataset.path=abc"], pytest.raises(subprocess.CalledProcessError)),
    ],
)
def test_tutorial_config_file_bad_key(tmpdir, args, expected):
    """ Similar to the previous test, but also tests exception values"""
    with expected:
        cmd = [
            sys.executable,
            "examples/tutorial/2_config_file/my_app.py",
            "hydra.run.dir=" + str(tmpdir),
        ]
示例#6
0
             dataset=dict(name="bespoke", path="/datasets/destiny")))


def test_python_run():
    verify_output(
        subprocess.check_output([
            sys.executable,
            "examples/advanced/hydra_app_example/hydra_app/main.py"
        ]))


def test_installed_run():
    verify_output(subprocess.check_output(["hydra_app"]))


def test_installed_run_with_user_override():
    config_override = 'config_override={}'.format(override_file)
    verify_override(subprocess.check_output(["hydra_app", config_override]))


@pytest.mark.parametrize("env_key",
                         ["HYDRA_MAIN_MODULE", "FB_PAR_MAIN_MODULE"])
@pytest.mark.parametrize(
    "env_value, expectation",
    [("bad_module", pytest.raises(Exception)),
     ("hydra_app.main", does_not_raise())],
)
def test_installed_run_with_env_module_override(env_key, env_value,
                                                expectation):
    verify_output(subprocess.check_output(["hydra_app"]))
示例#7
0
from hydra.test_utils.test_utils import chdir_hydra_root, does_not_raise

chdir_hydra_root()


def verify_output(result):
    assert OmegaConf.create(str(result.decode("utf-8"))) == OmegaConf.create(
        dict(dataset=dict(name="imagenet", path="/datasets/imagenet"))
    )


def test_python_run():
    verify_output(
        subprocess.check_output(
            [sys.executable, "examples/advanced/hydra_app_example/hydra_app/main.py"]
        )
    )


def test_installed_run():
    verify_output(subprocess.check_output(["hydra_app"]))


@pytest.mark.parametrize("env_key", ["HYDRA_MAIN_MODULE", "FB_PAR_MAIN_MODULE"])
@pytest.mark.parametrize(
    "env_value, expectation",
    [("bad_module", pytest.raises(Exception)), ("hydra_app.main", does_not_raise())],
)
def test_installed_run_with_env_module_override(env_key, env_value, expectation):
    verify_output(subprocess.check_output(["hydra_app"]))