def test_hydra_main_module_override_name(tmpdir: Path) -> None: cfg = OmegaConf.create() integration_test( tmpdir=tmpdir, task_config=cfg, overrides=[], prints="HydraConfig.get().job.name", expected_outputs="Foo", env_override={"HYDRA_MAIN_MODULE": "hydra.test_utils.configs.Foo"}, )
def test_run_dir_microseconds(tmpdir: Path, task_config: DictConfig) -> None: cfg = OmegaConf.create(task_config) assert isinstance(cfg, DictConfig) integration_test( tmpdir=tmpdir, task_config=cfg, overrides=[], prints="str('%f' not in os.getcwd())", expected_outputs="True", )
def test_local_run_workdir(tmpdir, task_config, overrides, expected_dir): cfg = OmegaConf.create(task_config) expected_dir1 = tmpdir / expected_dir integration_test( tmpdir=tmpdir, task_config=cfg, overrides=overrides, prints="os.getcwd()", expected_outputs=str(expected_dir1), )
def test_local_run_workdir(tmpdir: Path, task_config: DictConfig, overrides: List[str], expected_dir: str) -> None: cfg = OmegaConf.create(task_config) assert isinstance(cfg, DictConfig) expected_dir1 = tmpdir / expected_dir integration_test( tmpdir=tmpdir, task_config=cfg, overrides=overrides, prints="os.getcwd()", expected_outputs=str(expected_dir1), )
def test_get_orig_dir_multirun( self, tmpdir: Path, task_launcher_cfg: DictConfig, extra_flags: List[str] ) -> None: overrides = extra_flags task_launcher_cfg = OmegaConf.create(task_launcher_cfg or {}) # type: ignore task_config = OmegaConf.create() cfg = OmegaConf.merge(task_launcher_cfg, task_config) assert isinstance(cfg, DictConfig) integration_test( tmpdir=tmpdir, task_config=cfg, overrides=overrides, prints="hydra.utils.get_original_cwd()", expected_outputs=str(tmpdir), )
def test_get_orig_dir_multirun(self, tmpdir, task_launcher_cfg, extra_flags, plugin_module): self.verify_plugin(plugin_module) overrides = extra_flags task_launcher_cfg = OmegaConf.create(task_launcher_cfg or {}) task_config = OmegaConf.create() cfg = OmegaConf.merge(task_launcher_cfg, task_config) integration_test( tmpdir=tmpdir, task_config=cfg, overrides=overrides, prints="hydra.utils.get_original_cwd()", expected_outputs=str(tmpdir), )
def test_get_orig_dir_multirun( self, tmpdir: Path, task_launcher_cfg: DictConfig, extra_flags: List[str] ) -> None: overrides = extra_flags task_launcher_cfg = OmegaConf.create(task_launcher_cfg or {}) task_config = OmegaConf.create() cfg = OmegaConf.merge(task_launcher_cfg, task_config) assert isinstance(cfg, DictConfig) integration_test( tmpdir=self.get_test_scratch_dir(tmpdir), task_config=cfg, overrides=overrides, prints="hydra.utils.get_original_cwd()", expected_outputs=os.path.realpath(str(self.get_test_scratch_dir(tmpdir))), generate_custom_cmd=self.generate_custom_cmd(), )
def test_custom_sweeper_run_workdir( self, tmpdir: Path, task_config: str, overrides: List[str], expected_dir: str, task_launcher_cfg: DictConfig, extra_flags: List[str], ) -> None: overrides = extra_flags + overrides task_launcher_cfg = OmegaConf.create(task_launcher_cfg or {}) # type: ignore task_config = OmegaConf.create(task_config or {}) # type: ignore cfg = OmegaConf.merge(task_launcher_cfg, task_config) assert isinstance(cfg, DictConfig) integration_test( tmpdir=tmpdir, task_config=cfg, overrides=overrides, prints="os.getcwd()", expected_outputs=str(tmpdir / expected_dir), )
def test_custom_task_name( tmpdir, task_config, overrides, filename, expected_name, hydra_config, extra_flags, plugin_module, ): verify_plugin(plugin_module) overrides = extra_flags + overrides cfg = OmegaConf.merge(hydra_config or OmegaConf.create(), task_config or OmegaConf.create()) integration_test( tmpdir=tmpdir, task_config=cfg, overrides=overrides, prints="HydraConfig().hydra.job.name", expected_outputs=expected_name, filename=filename, )
def test_to_absolute_path_multirun(self, tmpdir: Path, task_launcher_cfg: DictConfig, extra_flags: List[str]) -> None: expected_dir = "cli_dir/cli_dir_0" overrides = extra_flags + [ "hydra.sweep.dir=cli_dir", "hydra.sweep.subdir=cli_dir_${hydra.job.num}", ] task_launcher_cfg = OmegaConf.create(task_launcher_cfg or {}) # type: ignore task_config = OmegaConf.create() cfg = OmegaConf.merge(task_launcher_cfg, task_config) assert isinstance(cfg, DictConfig) path = str(Path("/foo/bar").absolute()) integration_test( tmpdir=self.get_test_scratch_dir(tmpdir), task_config=cfg, overrides=overrides, prints="hydra.utils.to_absolute_path('/foo/bar')", expected_outputs=path, generate_custom_cmd=self.generate_custom_cmd(), ) test_app_dir = self.get_test_app_working_dir() working_dir = test_app_dir if test_app_dir else tmpdir outputs = [ os.path.realpath(str( self.get_test_scratch_dir(tmpdir) / "foo/bar")), str(self.get_test_scratch_dir(working_dir) / expected_dir), ] integration_test( tmpdir=self.get_test_scratch_dir(tmpdir), task_config=cfg, overrides=overrides, prints=["hydra.utils.to_absolute_path('foo/bar')", "os.getcwd()"], expected_outputs=outputs, generate_custom_cmd=self.generate_custom_cmd(), )
def test_custom_sweeper_run_workdir( tmpdir, task_config, overrides, expected_dir, task_launcher_cfg, extra_flags, plugin_module, ): verify_plugin(plugin_module) if task_config is not None: task_config = OmegaConf.create(task_config) overrides = extra_flags + overrides cfg = OmegaConf.merge(task_launcher_cfg, task_config) integration_test( tmpdir=tmpdir, task_config=cfg, overrides=overrides, prints="os.getcwd()", expected_outputs=str(tmpdir / expected_dir), )
def test_custom_task_name( self, tmpdir: Path, task_config: DictConfig, overrides: List[str], filename: str, expected_name: str, task_launcher_cfg: DictConfig, extra_flags: List[str], ) -> None: overrides = extra_flags + overrides task_launcher_cfg = OmegaConf.create(task_launcher_cfg or {}) # type: ignore task_config = OmegaConf.create(task_config or {}) # type: ignore cfg = OmegaConf.merge(task_launcher_cfg, task_config) assert isinstance(cfg, DictConfig) integration_test( tmpdir=tmpdir, task_config=cfg, overrides=overrides, prints="HydraConfig.get().job.name", expected_outputs=expected_name, filename=filename, )
def test_custom_task_name( self, tmpdir, task_config, overrides, filename, expected_name, task_launcher_cfg, extra_flags, plugin_module, ): self.verify_plugin(plugin_module) overrides = extra_flags + overrides task_launcher_cfg = OmegaConf.create(task_launcher_cfg or {}) task_config = OmegaConf.create(task_config or {}) cfg = OmegaConf.merge(task_launcher_cfg, task_config) integration_test( tmpdir=tmpdir, task_config=cfg, overrides=overrides, prints="HydraConfig().hydra.job.name", expected_outputs=expected_name, filename=filename, )