From 6f3d32613b0d62a214b57670af8a99b74adc577c Mon Sep 17 00:00:00 2001 From: "Jessica Zhang (NY)" Date: Thu, 24 Oct 2024 17:38:23 -0400 Subject: [PATCH] Fix windows tests failing due to ~ in directory --- .../tests/test_installed_app.py | 4 +- .../tests/test_ax_sweeper_plugin.py | 18 +++--- tests/test_basic_sweeper.py | 6 +- tests/test_callbacks.py | 14 ++--- tests/test_env_defaults.py | 2 +- .../test_advanced_config_search_path.py | 8 +-- .../test_advanced_package_overrides.py | 8 +-- tests/test_examples/test_basic_sweep.py | 6 +- tests/test_examples/test_configure_hydra.py | 10 +-- tests/test_examples/test_experimental.py | 2 +- .../test_instantiate_examples.py | 16 ++--- tests/test_examples/test_patterns.py | 16 ++--- .../test_structured_configs_tutorial.py | 24 +++---- tests/test_examples/test_tutorials_basic.py | 28 ++++----- tests/test_hydra.py | 62 +++++++++---------- tools/configen/tests/test_generate.py | 32 +++++----- 16 files changed, 128 insertions(+), 128 deletions(-) diff --git a/examples/advanced/hydra_app_example/tests/test_installed_app.py b/examples/advanced/hydra_app_example/tests/test_installed_app.py index 633410099af..b4fbd005f2e 100644 --- a/examples/advanced/hydra_app_example/tests/test_installed_app.py +++ b/examples/advanced/hydra_app_example/tests/test_installed_app.py @@ -16,7 +16,7 @@ def test_python_run(self, tmpdir: str) -> None: [ sys.executable, "hydra_app/main.py", - f"hydra.run.dir={tmpdir}", + f'hydra.run.dir="{tmpdir}"', "app.user=test_user", ] ) @@ -26,7 +26,7 @@ def test_python_run(self, tmpdir: str) -> None: def test_installed_run(self, tmpdir: str) -> None: self.verify_output( subprocess.check_output( - ["hydra_app", f"hydra.run.dir={tmpdir}", "app.user=test_user"] + ["hydra_app", f'hydra.run.dir="{tmpdir}"', "app.user=test_user"] ) ) diff --git a/plugins/hydra_ax_sweeper/tests/test_ax_sweeper_plugin.py b/plugins/hydra_ax_sweeper/tests/test_ax_sweeper_plugin.py index e8dda25e281..ba1b6abd830 100644 --- a/plugins/hydra_ax_sweeper/tests/test_ax_sweeper_plugin.py +++ b/plugins/hydra_ax_sweeper/tests/test_ax_sweeper_plugin.py @@ -7,14 +7,14 @@ from hydra.core.plugins import Plugins from hydra.plugins.sweeper import Sweeper from hydra.test_utils.test_utils import ( - TSweepRunner, chdir_plugin_root, run_python_script, + TSweepRunner, ) -from omegaconf import DictConfig, OmegaConf -from pytest import mark, raises from hydra_plugins.hydra_ax_sweeper.ax_sweeper import AxSweeper +from omegaconf import DictConfig, OmegaConf +from pytest import mark, raises chdir_plugin_root() @@ -216,7 +216,7 @@ def test_ax_logging(tmpdir: Path, cmd_arg: str, expected_str: str) -> None: cmd = [ "tests/apps/polynomial.py", "-m", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", "polynomial.x=interval(-5, -2)", "polynomial.z=10", @@ -239,7 +239,7 @@ def test_search_space_exhausted_exception(tmpdir: Path, cmd_args: List[str]) -> cmd = [ "tests/apps/polynomial.py", "-m", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", "hydra.sweeper.ax_config.max_trials=2", ] + cmd_args @@ -260,7 +260,7 @@ def test_search_space_with_constraint_metric(tmpdir: Path, cmd_args: List[str]) cmd = [ "tests/apps/polynomial_with_constraint.py", "-m", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", "hydra.sweeper.ax_config.max_trials=2", ] + cmd_args @@ -294,7 +294,7 @@ def test_jobs_using_choice_between_lists( cmd = [ "tests/apps/polynomial_with_list_coefficients.py", "-m", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", "hydra.sweeper.ax_config.max_trials=3", ] + [cmd_arg] @@ -331,7 +331,7 @@ def test_jobs_using_choice_between_dicts( cmd = [ "tests/apps/polynomial_with_dict_coefficients.py", "-m", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", "hydra.sweeper.ax_config.max_trials=3", ] + [cmd_arg] @@ -345,7 +345,7 @@ def test_example_app(tmpdir: Path) -> None: cmd = [ "example/banana.py", "-m", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", "banana.x=int(interval(-5, 5))", "banana.y=interval(-5, 10.1)", diff --git a/tests/test_basic_sweeper.py b/tests/test_basic_sweeper.py index d7464ec10bc..7688512bef7 100644 --- a/tests/test_basic_sweeper.py +++ b/tests/test_basic_sweeper.py @@ -4,12 +4,12 @@ from textwrap import dedent from typing import Any, List, Optional -from pytest import mark, param - from hydra._internal.core_plugins.basic_sweeper import BasicSweeper from hydra.core.override_parser.overrides_parser import OverridesParser from hydra.test_utils.test_utils import assert_multiline_regex_search, run_process +from pytest import mark, param + @mark.parametrize( "args,max_batch_size,expected", @@ -70,7 +70,7 @@ def test_partial_failure( "tests/test_apps/app_can_fail/my_app.py", "--multirun", "+divisor=1,0", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", "hydra.hydra_logging.formatters.simple.format='[HYDRA] %(message)s'", ] diff --git a/tests/test_callbacks.py b/tests/test_callbacks.py index 992b70c1e27..ea9560b8913 100644 --- a/tests/test_callbacks.py +++ b/tests/test_callbacks.py @@ -7,9 +7,6 @@ from textwrap import dedent from typing import Any, List -from omegaconf import open_dict, read_write -from pytest import mark, param - from hydra.core.utils import JobReturn, JobStatus from hydra.test_utils.test_utils import ( assert_regex_match, @@ -18,6 +15,9 @@ run_python_script, ) +from omegaconf import open_dict, read_write +from pytest import mark, param + chdir_hydra_root() @@ -98,7 +98,7 @@ def test_app_with_callbacks( ) -> None: cmd = [ app_path, - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", "hydra.hydra_logging.formatters.simple.format='[HYDRA] %(message)s'", "hydra.job_logging.formatters.simple.format='[JOB] %(message)s'", @@ -120,7 +120,7 @@ def test_experimental_save_job_info_callback(tmpdir: Path, multirun: bool) -> No cmd = [ app_path, - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.sweep.dir=" + str(tmpdir), "hydra.job.chdir=True", ] @@ -167,7 +167,7 @@ def test_save_job_return_callback(tmpdir: Path, multirun: bool) -> None: cmd = [ sys.executable, app_path, - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.sweep.dir=" + str(tmpdir), "hydra.job.chdir=True", ] @@ -202,7 +202,7 @@ def test_experimental_rerun( cmd = [ app_path, - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.sweep.dir=" + str(tmpdir), "hydra.job.chdir=False", "hydra.hydra_logging.formatters.simple.format='[HYDRA] %(message)s'", diff --git a/tests/test_env_defaults.py b/tests/test_env_defaults.py index 796bffc0b70..94bdeeb90da 100644 --- a/tests/test_env_defaults.py +++ b/tests/test_env_defaults.py @@ -9,7 +9,7 @@ def test_env_defaults(tmpdir: Path) -> None: cmd = [ "tests/test_apps/custom_env_defaults/my_app.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", ] run_python_script(cmd) diff --git a/tests/test_examples/test_advanced_config_search_path.py b/tests/test_examples/test_advanced_config_search_path.py index 64d4508f329..7d6719be3d2 100644 --- a/tests/test_examples/test_advanced_config_search_path.py +++ b/tests/test_examples/test_advanced_config_search_path.py @@ -3,15 +3,15 @@ from pathlib import Path from typing import List, Optional -from omegaconf import OmegaConf -from pytest import mark - from hydra.test_utils.test_utils import ( chdir_hydra_root, run_python_script, run_with_error, ) +from omegaconf import OmegaConf +from pytest import mark + chdir_hydra_root() @@ -36,7 +36,7 @@ def test_config_search_path( ) -> None: cmd = [ "examples/advanced/config_search_path/my_app.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", ] cmd.extend(args) diff --git a/tests/test_examples/test_advanced_package_overrides.py b/tests/test_examples/test_advanced_package_overrides.py index 5c393704eb1..b9db1ebd3dd 100644 --- a/tests/test_examples/test_advanced_package_overrides.py +++ b/tests/test_examples/test_advanced_package_overrides.py @@ -1,17 +1,17 @@ # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved from pathlib import Path -from omegaconf import OmegaConf - from hydra.test_utils.test_utils import chdir_hydra_root, run_python_script +from omegaconf import OmegaConf + chdir_hydra_root() def test_advanced_package_override_simple(tmpdir: Path) -> None: cmd = [ "examples/advanced/package_overrides/simple.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", ] result, _err = run_python_script(cmd) @@ -23,7 +23,7 @@ def test_advanced_package_override_simple(tmpdir: Path) -> None: def test_advanced_package_override_two_packages(tmpdir: Path) -> None: cmd = [ "examples/advanced/package_overrides/two_packages.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", ] result, _err = run_python_script(cmd) diff --git a/tests/test_examples/test_basic_sweep.py b/tests/test_examples/test_basic_sweep.py index 899412d477a..dc20cf7621f 100644 --- a/tests/test_examples/test_basic_sweep.py +++ b/tests/test_examples/test_basic_sweep.py @@ -3,14 +3,14 @@ from textwrap import dedent from typing import List -from pytest import mark - from hydra.test_utils.test_utils import ( assert_regex_match, chdir_hydra_root, run_python_script, ) +from pytest import mark + chdir_hydra_root() @@ -70,7 +70,7 @@ def test_basic_sweep_example( cmd = [ app_path, "--multirun", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", "hydra.hydra_logging.formatters.simple.format='[HYDRA] %(message)s'", "hydra.job_logging.formatters.simple.format='[JOB] %(message)s'", diff --git a/tests/test_examples/test_configure_hydra.py b/tests/test_examples/test_configure_hydra.py index 27a3e35fe4b..e7795ae79df 100644 --- a/tests/test_examples/test_configure_hydra.py +++ b/tests/test_examples/test_configure_hydra.py @@ -16,7 +16,7 @@ def test_custom_help(tmpdir: Path) -> None: result, _err = run_python_script( [ "examples/configure_hydra/custom_help/my_app.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", "--help", ] @@ -55,7 +55,7 @@ def test_custom_help(tmpdir: Path) -> None: def test_job_name_no_config_override(tmpdir: Path) -> None: cmd = [ "examples/configure_hydra/job_name/no_config_file_override.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", ] result, _err = run_python_script(cmd) @@ -65,7 +65,7 @@ def test_job_name_no_config_override(tmpdir: Path) -> None: def test_job_name_with_config_override(tmpdir: Path) -> None: cmd = [ "examples/configure_hydra/job_name/with_config_file_override.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", ] result, _err = run_python_script(cmd) @@ -90,7 +90,7 @@ def test_job_override_dirname(tmpdir: Path) -> None: def test_logging(tmpdir: Path) -> None: cmd = [ "examples/configure_hydra/logging/my_app.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", ] result, _err = run_python_script(cmd) @@ -100,7 +100,7 @@ def test_logging(tmpdir: Path) -> None: def test_disabling_logging(tmpdir: Path) -> None: cmd = [ "examples/configure_hydra/logging/my_app.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", "hydra/job_logging=none", "hydra/hydra_logging=none", diff --git a/tests/test_examples/test_experimental.py b/tests/test_examples/test_experimental.py index f3f903d4556..1ad7e3f6ad9 100644 --- a/tests/test_examples/test_experimental.py +++ b/tests/test_examples/test_experimental.py @@ -8,7 +8,7 @@ def test_rerun(tmpdir: Path) -> None: cmd = [ "examples/experimental/rerun/my_app.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", "hydra.hydra_logging.formatters.simple.format='[HYDRA] %(message)s'", "hydra.job_logging.formatters.simple.format='[JOB] %(message)s'", diff --git a/tests/test_examples/test_instantiate_examples.py b/tests/test_examples/test_instantiate_examples.py index 324bb0b425c..908ba317c69 100644 --- a/tests/test_examples/test_instantiate_examples.py +++ b/tests/test_examples/test_instantiate_examples.py @@ -3,14 +3,14 @@ from textwrap import dedent from typing import List -from pytest import mark, param - from hydra.test_utils.test_utils import ( assert_text_same, chdir_hydra_root, run_python_script, ) +from pytest import mark, param + chdir_hydra_root() @@ -24,7 +24,7 @@ def test_instantiate_object(tmpdir: Path, overrides: List[str], output: str) -> None: cmd = [ "examples/instantiate/object/my_app.py", - f"hydra.run.dir={tmpdir}", + f'hydra.run.dir="{tmpdir}"', "hydra.job.chdir=True", ] + overrides result, _err = run_python_script(cmd) @@ -46,7 +46,7 @@ def test_instantiate_object_recursive( ) -> None: cmd = [ "examples/instantiate/object_recursive/my_app.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", ] + overrides result, _err = run_python_script(cmd) @@ -56,7 +56,7 @@ def test_instantiate_object_recursive( def test_instantiate_object_partial(tmpdir: Path) -> None: cmd = [ "examples/instantiate/partial/my_app.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", ] result, _err = run_python_script(cmd) @@ -73,7 +73,7 @@ def test_instantiate_object_partial(tmpdir: Path) -> None: def test_instantiate_schema(tmpdir: Path, overrides: List[str], output: str) -> None: cmd = [ "examples/instantiate/schema/my_app.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", ] + overrides result, _err = run_python_script(cmd) @@ -102,7 +102,7 @@ def test_instantiate_schema_recursive( ) -> None: cmd = [ "examples/instantiate/schema_recursive/my_app.py", - f"hydra.run.dir={tmpdir}", + f'hydra.run.dir="{tmpdir}"', "hydra.job.chdir=True", ] + overrides result, _err = run_python_script(cmd) @@ -141,7 +141,7 @@ def test_instantiate_docs_example( ) -> None: cmd = [ "examples/instantiate/docs_example/my_app.py", - f"hydra.run.dir={tmpdir}", + f'hydra.run.dir="{tmpdir}"', "hydra.job.chdir=True", ] + overrides result, _err = run_python_script(cmd) diff --git a/tests/test_examples/test_patterns.py b/tests/test_examples/test_patterns.py index 5bb60f23af1..dbd8f96daa4 100644 --- a/tests/test_examples/test_patterns.py +++ b/tests/test_examples/test_patterns.py @@ -3,18 +3,18 @@ from textwrap import dedent from typing import Any, List -from omegaconf import OmegaConf -from pytest import mark, param - from hydra.test_utils.test_utils import ( - TTaskRunner, assert_text_same, chdir_hydra_root, run_python_script, run_with_error, + TTaskRunner, verify_dir_outputs, ) +from omegaconf import OmegaConf +from pytest import mark, param + chdir_hydra_root() @@ -39,7 +39,7 @@ def test_specializing_config_example( def test_write_protect_config_node(tmpdir: Any) -> None: cmd = [ "examples/patterns/write_protect_config_node/frozen.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", "data_bits=10", ] @@ -71,7 +71,7 @@ def test_extending_configs( monkeypatch.chdir("examples/patterns/extending_configs") cmd = [ "my_app.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", ] + overrides result, _err = run_python_script(cmd) @@ -112,7 +112,7 @@ def test_configuring_experiments( monkeypatch.chdir("examples/patterns/configuring_experiments") cmd = [ "my_app.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", ] + overrides result, _err = run_python_script(cmd) @@ -183,7 +183,7 @@ def test_multi_select( monkeypatch.chdir("examples/patterns/multi-select") cmd = [ "my_app.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", ] + overrides result, _err = run_python_script(cmd) diff --git a/tests/test_examples/test_structured_configs_tutorial.py b/tests/test_examples/test_structured_configs_tutorial.py index 19022d2d76b..49a5ca2c797 100644 --- a/tests/test_examples/test_structured_configs_tutorial.py +++ b/tests/test_examples/test_structured_configs_tutorial.py @@ -4,15 +4,15 @@ from textwrap import dedent from typing import Any -from omegaconf import OmegaConf -from pytest import mark - from hydra.test_utils.test_utils import ( chdir_hydra_root, run_python_script, run_with_error, ) +from omegaconf import OmegaConf +from pytest import mark + chdir_hydra_root() @@ -20,7 +20,7 @@ def test_1_basic_run(tmpdir: Path) -> None: result, _err = run_python_script( [ "examples/tutorials/structured_configs/1_minimal/my_app.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", ] ) @@ -37,7 +37,7 @@ def test_1_basic_run_with_override_error(tmpdir: Path) -> None: err = run_with_error( [ "examples/tutorials/structured_configs/1_minimal/my_app_type_error.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", ] ) @@ -48,7 +48,7 @@ def test_1_basic_override(tmpdir: Path) -> None: result, _err = run_python_script( [ "examples/tutorials/structured_configs/1_minimal/my_app.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", "port=9090", ] @@ -59,7 +59,7 @@ def test_1_basic_override(tmpdir: Path) -> None: def test_1_basic_override_type_error(tmpdir: Path) -> None: cmd = [ "examples/tutorials/structured_configs/1_minimal/my_app.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", "port=foo", ] @@ -79,7 +79,7 @@ def test_2_static_complex(tmpdir: Path) -> None: result, _err = run_python_script( [ "examples/tutorials/structured_configs/2_static_complex/my_app.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", ] ) @@ -99,7 +99,7 @@ def test_2_static_complex(tmpdir: Path) -> None: def test_3_config_groups(tmpdir: Path, overrides: Any, expected: Any) -> None: cmd = [ "examples/tutorials/structured_configs/3_config_groups/my_app.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", ] cmd.extend(overrides) @@ -134,7 +134,7 @@ def test_3_config_groups_with_inheritance( ) -> None: cmd = [ "examples/tutorials/structured_configs/3_config_groups/my_app_with_inheritance.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", ] + overrides result, _err = run_python_script(cmd) @@ -145,7 +145,7 @@ def test_3_config_groups_with_inheritance( def test_4_defaults(tmpdir: Path) -> None: cmd = [ "examples/tutorials/structured_configs/4_defaults/my_app.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", ] result, _err = run_python_script(cmd) @@ -168,7 +168,7 @@ def test_4_defaults(tmpdir: Path) -> None: ], ) def test_5_structured_config_schema(tmpdir: Path, path: str) -> None: - cmd = [path, "hydra.run.dir=" + str(tmpdir), "hydra.job.chdir=True"] + cmd = [path, f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True"] result, _err = run_python_script(cmd) assert OmegaConf.create(result) == { "db": { diff --git a/tests/test_examples/test_tutorials_basic.py b/tests/test_examples/test_tutorials_basic.py index 05e2bf047a5..9527dde42c5 100644 --- a/tests/test_examples/test_tutorials_basic.py +++ b/tests/test_examples/test_tutorials_basic.py @@ -7,16 +7,16 @@ from typing import Any, List from _pytest.python_api import RaisesContext -from omegaconf import DictConfig, OmegaConf -from pytest import mark, raises from hydra.test_utils.test_utils import ( - TSweepRunner, - TTaskRunner, chdir_hydra_root, run_python_script, + TSweepRunner, + TTaskRunner, verify_dir_outputs, ) +from omegaconf import DictConfig, OmegaConf +from pytest import mark, raises chdir_hydra_root() @@ -38,7 +38,7 @@ def test_tutorial_simple_cli_app( ) -> None: cmd = [ "examples/tutorials/basic/your_first_hydra_app/1_simple_cli/my_app.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", ] cmd.extend(args) @@ -49,7 +49,7 @@ def test_tutorial_simple_cli_app( def test_tutorial_working_directory(tmpdir: Path) -> None: cmd = [ "examples/tutorials/basic/running_your_hydra_app/3_working_directory/my_app.py", - f"hydra.run.dir={tmpdir}", + f'hydra.run.dir="{tmpdir}"', "hydra.job.chdir=True", ] result, _err = run_python_script(cmd) @@ -60,7 +60,7 @@ def test_tutorial_working_directory(tmpdir: Path) -> None: def test_tutorial_working_directory_original_cwd(tmpdir: Path) -> None: cmd = [ "examples/tutorials/basic/running_your_hydra_app/3_working_directory/original_cwd.py", - f"hydra.run.dir={tmpdir}", + f'hydra.run.dir="{tmpdir}"', "hydra.job.chdir=True", ] result, _err = run_python_script(cmd) @@ -87,7 +87,7 @@ def test_tutorial_working_directory_original_cwd(tmpdir: Path) -> None: def test_tutorial_logging(tmpdir: Path, args: List[str], expected: List[str]) -> None: cmd = [ "examples/tutorials/basic/running_your_hydra_app/4_logging/my_app.py", - f"hydra.run.dir={tmpdir}", + f'hydra.run.dir="{tmpdir}"', "hydra.job.chdir=True", ] cmd.extend(args) @@ -112,7 +112,7 @@ def test_tutorial_logging(tmpdir: Path, args: List[str], expected: List[str]) -> def test_tutorial_config_file(tmpdir: Path, args: List[str], output_conf: Any) -> None: cmd = [ "examples/tutorials/basic/your_first_hydra_app/2_config_file/my_app.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", ] cmd.extend(args) @@ -139,7 +139,7 @@ def test_tutorial_config_file_bad_key( cmd = [ "examples/tutorials/basic/your_first_hydra_app/2_config_file/my_app.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", ] cmd.extend(args) @@ -175,7 +175,7 @@ def test_tutorial_config_groups( ) -> None: cmd = [ "examples/tutorials/basic/your_first_hydra_app/4_config_groups/my_app.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", ] cmd.extend(args) @@ -214,7 +214,7 @@ def test_tutorial_config_groups( def test_tutorial_defaults(tmpdir: Path, args: List[str], expected: DictConfig) -> None: cmd = [ "examples/tutorials/basic/your_first_hydra_app/5_defaults/my_app.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", ] cmd.extend(args) @@ -316,7 +316,7 @@ def test_advanced_ad_hoc_composition( monkeypatch.setenv("USER", "test_user") cmd = [ "examples/advanced/ad_hoc_composition/hydra_compose_example.py", - f"hydra.run.dir={tmpdir}", + f'hydra.run.dir="{tmpdir}"', "hydra.job.chdir=True", ] result, _err = run_python_script(cmd) @@ -326,7 +326,7 @@ def test_advanced_ad_hoc_composition( def test_examples_using_the_config_object(tmpdir: Path) -> None: cmd = [ "examples/tutorials/basic/your_first_hydra_app/3_using_config/my_app.py", - f"hydra.run.dir={tmpdir}", + f'hydra.run.dir="{tmpdir}"', "hydra.job.chdir=True", ] diff --git a/tests/test_hydra.py b/tests/test_hydra.py index 2dd0232a529..3780a8627b4 100644 --- a/tests/test_hydra.py +++ b/tests/test_hydra.py @@ -8,13 +8,8 @@ from textwrap import dedent from typing import Any, List, Optional, Set -from omegaconf import DictConfig, OmegaConf -from pytest import mark, param, raises - from hydra import MissingConfigException, version from hydra.test_utils.test_utils import ( - TSweepRunner, - TTaskRunner, assert_multiline_regex_search, assert_regex_match, assert_text_same, @@ -23,9 +18,14 @@ normalize_newlines, run_python_script, run_with_error, + TSweepRunner, + TTaskRunner, verify_dir_outputs, ) +from omegaconf import DictConfig, OmegaConf +from pytest import mark, param, raises + chdir_hydra_root() @@ -374,7 +374,7 @@ def test_app_with_sweep_cfg__override_to_basic_launcher( def test_short_module_name(tmpdir: Path) -> None: cmd = [ "examples/tutorials/basic/your_first_hydra_app/2_config_file/my_app.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", ] out, _err = run_python_script(cmd) @@ -404,7 +404,7 @@ def test_module_env_override(tmpdir: Path, env_name: str) -> None: """ cmd = [ "examples/tutorials/basic/your_first_hydra_app/2_config_file/my_app.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", ] modified_env = os.environ.copy() @@ -421,7 +421,7 @@ def test_module_env_override(tmpdir: Path, env_name: str) -> None: def test_cfg(tmpdir: Path, flag: str, resolve: bool, expected_keys: List[str]) -> None: cmd = [ "examples/tutorials/basic/your_first_hydra_app/5_defaults/my_app.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", flag, ] @@ -481,7 +481,7 @@ def test_cfg_with_package( ) -> None: cmd = [ "examples/tutorials/basic/your_first_hydra_app/5_defaults/my_app.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", ] + flags if resolve: @@ -539,7 +539,7 @@ def test_cfg_resolve_interpolation( ) -> None: cmd = [ script, - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", "--cfg=job", ] + flags @@ -570,7 +570,7 @@ def test_pass_callable_class_to_hydra_main( ) -> None: cmd = [ script, - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", ] @@ -585,7 +585,7 @@ def test_pass_callable_class_to_hydra_main( def test_resolve_flag_errmsg(tmpdir: Path, other_flag: Optional[str]) -> None: cmd = [ "examples/tutorials/basic/your_first_hydra_app/3_using_config/my_app.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", "--resolve", ] @@ -834,7 +834,7 @@ def test_sweep_complex_defaults( def test_help( tmpdir: Path, script: str, flags: List[str], overrides: List[str], expected: Any ) -> None: - cmd = [script, "hydra.run.dir=" + str(tmpdir), "hydra.job.chdir=True"] + cmd = [script, f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True"] cmd.extend(overrides) cmd.extend(flags) result, _err = run_python_script(cmd) @@ -864,7 +864,7 @@ def test_help( def test_searchpath_config(tmpdir: Path, overrides: List[str], expected: str) -> None: cmd = ["examples/advanced/config_search_path/my_app.py"] cmd.extend(overrides) - cmd.extend(["hydra.run.dir=" + str(tmpdir), "hydra.job.chdir=True"]) + cmd.extend([f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True"]) result, _err = run_python_script(cmd) assert re.match(expected, result, re.DOTALL) @@ -900,7 +900,7 @@ def test_sys_exit(tmpdir: Path) -> None: sys.executable, "-Werror", "tests/test_apps/sys_exit/my_app.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", ] assert subprocess.run(cmd).returncode == 42 @@ -1047,7 +1047,7 @@ def test_config_name_and_path_overrides( ) -> None: cmd = [ "tests/test_apps/app_with_multiple_config_dirs/my_app.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", f"--config-name={config_name}", f"--config-path={config_path}", @@ -1113,7 +1113,7 @@ def test_module_run( ) -> None: cmd = [ directory + "/" + file, - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", ] modified_env = os.environ.copy() @@ -1340,7 +1340,7 @@ def test_config_dir_argument( monkeypatch.chdir("tests/test_apps/user-config-dir") cmd = [ "my_app.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", ] cmd.extend(overrides) @@ -1352,7 +1352,7 @@ def test_schema_overrides_hydra(monkeypatch: Any, tmpdir: Path) -> None: monkeypatch.chdir("tests/test_apps/schema_overrides_hydra") cmd = [ "my_app.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", ] result, _err = run_python_script(cmd) @@ -1363,7 +1363,7 @@ def test_defaults_pkg_with_dot(monkeypatch: Any, tmpdir: Path) -> None: monkeypatch.chdir("tests/test_apps/defaults_pkg_with_dot") cmd = [ "my_app.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", ] result, _err = run_python_script(cmd) @@ -1414,7 +1414,7 @@ def test_job_exception( ret = run_with_error( [ "tests/test_apps/app_exception/my_app.py", - f"hydra.run.dir={tmpdir}", + f'hydra.run.dir="{tmpdir}"', "hydra.job.chdir=True", ] ) @@ -1425,7 +1425,7 @@ def test_job_exception_full_error(tmpdir: Any) -> None: ret = run_with_error( [ "tests/test_apps/app_exception/my_app.py", - f"hydra.run.dir={tmpdir}", + f'hydra.run.dir="{tmpdir}"', "hydra.job.chdir=True", ], env={**os.environ, "HYDRA_FULL_ERROR": "1"}, @@ -1439,7 +1439,7 @@ def test_structured_with_none_list(monkeypatch: Any, tmpdir: Path) -> None: monkeypatch.chdir("tests/test_apps/structured_with_none_list") cmd = [ "my_app.py", - "hydra.run.dir=" + str(tmpdir), + f'hydra.run.dir="{str(tmpdir)}"', "hydra.job.chdir=True", ] result, _err = run_python_script(cmd) @@ -1471,7 +1471,7 @@ def test_job_id_and_num_in_sweep(tmpdir: Path) -> None: def test_hydra_main_without_config_path(tmpdir: Path) -> None: cmd = [ "tests/test_apps/hydra_main_without_config_path/my_app.py", - f"hydra.run.dir={tmpdir}", + f'hydra.run.dir="{tmpdir}"', "hydra.job.chdir=True", ] _, err = run_python_script(cmd, allow_warnings=True) @@ -1500,7 +1500,7 @@ def test_hydra_main_without_config_path(tmpdir: Path) -> None: def test_job_chdir_not_specified(tmpdir: Path) -> None: cmd = [ "tests/test_apps/app_with_no_chdir_override/my_app.py", - f"hydra.run.dir={tmpdir}", + f'hydra.run.dir="{tmpdir}"', ] out, err = run_python_script(cmd, allow_warnings=True) @@ -1522,7 +1522,7 @@ def test_job_chdir_not_specified(tmpdir: Path) -> None: def test_app_with_unicode_config(tmpdir: Path) -> None: cmd = [ "tests/test_apps/app_with_unicode_in_config/my_app.py", - f"hydra.run.dir={tmpdir}", + f'hydra.run.dir="{tmpdir}"', "hydra.job.chdir=True", ] out, _ = run_python_script(cmd) @@ -1546,7 +1546,7 @@ def test_frozen_primary_config( ) -> None: cmd = [ "examples/patterns/write_protect_config_node/frozen.py", - f"hydra.run.dir={tmpdir}", + f'hydra.run.dir="{tmpdir}"', "hydra.job.chdir=True", ] cmd.extend(overrides) @@ -1586,7 +1586,7 @@ def test_hydra_deprecation_warning( ) -> None: cmd = [ "tests/test_apps/deprecation_warning/my_app.py", - f"hydra.run.dir={tmpdir}", + f'hydra.run.dir="{tmpdir}"', "hydra.job.chdir=True", ] env = os.environ.copy() @@ -1608,7 +1608,7 @@ def test_hydra_deprecation_warning( def test_disable_chdir(tmpdir: Path, multirun: bool, expected: List[str]) -> None: cmd = [ "examples/tutorials/basic/running_your_hydra_app/3_working_directory/my_app.py", - f"hydra.run.dir={tmpdir}", + f'hydra.run.dir="{tmpdir}"', f"hydra.sweep.dir={tmpdir}", "hydra.job.chdir=False", ] @@ -1628,7 +1628,7 @@ def test_disable_chdir(tmpdir: Path, multirun: bool, expected: List[str]) -> Non def test_disable_chdir_with_app_chdir(tmpdir: Path, chdir: bool) -> None: cmd = [ "tests/test_apps/app_change_dir/my_app.py", - f"hydra.run.dir={tmpdir}", + f'hydra.run.dir="{tmpdir}"', f"hydra.job.chdir={chdir}", ] result, _err = run_python_script(cmd) @@ -1643,7 +1643,7 @@ def test_disable_chdir_with_app_chdir(tmpdir: Path, chdir: bool) -> None: def test_hydra_verbose_1897(tmpdir: Path, multirun: bool) -> None: cmd = [ "tests/test_apps/hydra_verbose/my_app.py", - f"hydra.run.dir={tmpdir}", + f'hydra.run.dir="{tmpdir}"', "hydra.job.chdir=False", ] if multirun: diff --git a/tools/configen/tests/test_generate.py b/tools/configen/tests/test_generate.py index 701d5195a25..e59c2917f7f 100644 --- a/tools/configen/tests/test_generate.py +++ b/tools/configen/tests/test_generate.py @@ -1,36 +1,36 @@ # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import sys -from textwrap import dedent from difflib import unified_diff from pathlib import Path +from textwrap import dedent from typing import Any -from pytest import mark, param +from configen.config import ConfigenConf, Flags, ModuleConf +from configen.configen import generate_module +from hydra.test_utils.test_utils import chdir_hydra_root, run_python_script -from hydra.utils import get_class, instantiate, ConvertMode +from hydra.utils import ConvertMode, get_class, instantiate from omegaconf import OmegaConf -from configen.config import ConfigenConf, ModuleConf, Flags -from configen.configen import generate_module -from hydra.test_utils.test_utils import chdir_hydra_root, run_python_script +from pytest import mark, param from tests.test_modules import ( - User, Color, + DictValues, Empty, - UntypedArg, + IncompatibleDataclass, + IncompatibleDataclassArg, IntArg, - UnionArg, - WithLibraryClassArg, LibraryClass, - IncompatibleDataclassArg, - IncompatibleDataclass, - WithStringDefault, - WithUntypedStringDefault, ListValues, - DictValues, PeskySentinelUsage, Tuples, + UnionArg, + UntypedArg, + User, + WithLibraryClassArg, + WithStringDefault, + WithUntypedStringDefault, ) from tests.test_modules.generated import PeskySentinelUsageConf @@ -288,7 +288,7 @@ def test_example_application(monkeypatch: Any, tmpdir: Path): monkeypatch.chdir("example") cmd = [ "my_app.py", - f"hydra.run.dir={tmpdir}", + f'hydra.run.dir="{tmpdir}"', "hydra.job.chdir=True", "user.name=Batman", ]