From 979df83567f057d558ba63bc18a45b9569e5b423 Mon Sep 17 00:00:00 2001 From: Madeline Scyphers Date: Fri, 19 Jul 2024 11:19:29 -0400 Subject: [PATCH] Fix tests to point to new CLI entry func from dunder main --- tests/conftest.py | 12 ++++++------ .../{test_dunder_main.py => test_cli.py} | 12 ++++++------ tests/integration_tests/test_storage.py | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) rename tests/integration_tests/{test_dunder_main.py => test_cli.py} (92%) diff --git a/tests/conftest.py b/tests/conftest.py index 6983ab7..4ef90c1 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,10 +5,10 @@ import pytest -import boa.__main__ as dunder_main import boa.scripts.moo as run_moo import boa.scripts.run_branin as run_branin from boa import BOAConfig, cd_and_cd_back, split_shell_command +from boa.cli import main as cli_main from boa.definitions import ROOT, TEST_SCRIPTS_DIR logger = logging.getLogger(__file__) @@ -192,7 +192,7 @@ def denormed_custom_wrapper_run(tmp_path_factory, cd_to_root_and_back_session): config_path = temp_dir / "different_name_config.json" with open(Path(config_path), "w") as file: json.dump(config, file) - scheduler = dunder_main.main(split_shell_command(f"--config-path {config_path} -td"), standalone_mode=False) + scheduler = cli_main(split_shell_command(f"--config-path {config_path} -td"), standalone_mode=False) os.remove(config_path) yield scheduler @@ -211,25 +211,25 @@ def moo_main_run(tmp_path_factory, cd_to_root_and_back_session): def stand_alone_opt_package_run(tmp_path_factory, cd_to_root_and_back_session): config_path = TEST_DIR / "scripts/stand_alone_opt_package/stand_alone_pkg_config.yaml" args = f"--config-path {config_path} -td" - yield dunder_main.main(split_shell_command(args), standalone_mode=False) + yield cli_main(split_shell_command(args), standalone_mode=False) @pytest.fixture(scope="session") def r_full(tmp_path_factory, cd_to_root_and_back_session): config_path = TEST_DIR / f"scripts/other_langs/r_package_full/config.yaml" - yield dunder_main.main(split_shell_command(f"--config-path {config_path} -td"), standalone_mode=False) + yield cli_main(split_shell_command(f"--config-path {config_path} -td"), standalone_mode=False) @pytest.fixture(scope="session") def r_light(tmp_path_factory, cd_to_root_and_back_session): config_path = TEST_DIR / f"scripts/other_langs/r_package_light/config.yaml" - yield dunder_main.main(split_shell_command(f"--config-path {config_path} -td"), standalone_mode=False) + yield cli_main(split_shell_command(f"--config-path {config_path} -td"), standalone_mode=False) @pytest.fixture(scope="session") def r_streamlined(tmp_path_factory, cd_to_root_and_back_session): config_path = TEST_DIR / f"scripts/other_langs/r_package_streamlined/config.yaml" - yield dunder_main.main(split_shell_command(f"--config-path {config_path} -td"), standalone_mode=False) + yield cli_main(split_shell_command(f"--config-path {config_path} -td"), standalone_mode=False) diff --git a/tests/integration_tests/test_dunder_main.py b/tests/integration_tests/test_cli.py similarity index 92% rename from tests/integration_tests/test_dunder_main.py rename to tests/integration_tests/test_cli.py index 009bd3f..7f0fe2c 100644 --- a/tests/integration_tests/test_dunder_main.py +++ b/tests/integration_tests/test_cli.py @@ -5,7 +5,6 @@ import pytest from ax.service.scheduler import FailureRateExceededError -import boa.__main__ as dunder_main from boa import ( BaseWrapper, BOAConfig, @@ -16,6 +15,7 @@ scheduler_to_json_file, split_shell_command, ) +from boa.cli import main as cli_main from boa.definitions import ROOT try: @@ -110,14 +110,14 @@ def test_calling_command_line_r_test_scripts(r_scripts_run, request): def test_cli_interface_with_failing_test_that_sends_back_failed_trial_status(): with pytest.raises(FailureRateExceededError): config_path = ROOT / "tests" / f"scripts/other_langs/r_package_streamlined/config_fail.yaml" - dunder_main.main(split_shell_command(f"--config-path {config_path} -td"), standalone_mode=False) + cli_main(split_shell_command(f"--config-path {config_path} -td"), standalone_mode=False) @pytest.mark.skipif(not R_INSTALLED, reason="requires R to be installed") def test_cli_interface_with_failing_test_that_sends_back_failed_trial_status(): with pytest.raises(FailureRateExceededError): config_path = ROOT / "tests" / f"scripts/other_langs/r_pass_back_fail_trial_status/config.yaml" - dunder_main.main(split_shell_command(f"--config-path {config_path} -td"), standalone_mode=False) + cli_main(split_shell_command(f"--config-path {config_path} -td"), standalone_mode=False) def test_wrapper_with_custom_load_config(): @@ -125,7 +125,7 @@ def test_wrapper_with_custom_load_config(): config_path = ROOT / "tests" / f"scripts/other_langs/r_package_streamlined/config_fail.yaml" # But we override the failing config in our wrapper with a working one in a custom load_config wrapper_path = Path(__file__) - dunder_main.main( + cli_main( split_shell_command( f"--config-path {config_path}" f" --wrapper-path {wrapper_path}" @@ -153,10 +153,10 @@ def test_parallelism(r_light, caplog): def test_non_zero_exit_code_fails_trial(): with pytest.raises(FailureRateExceededError): config_path = ROOT / "tests" / f"scripts/other_langs/r_failure_exit_code/config.yaml" - dunder_main.main(split_shell_command(f"--config-path {config_path} -td"), standalone_mode=False) + cli_main(split_shell_command(f"--config-path {config_path} -td"), standalone_mode=False) def test_return_nan_fails_trial(): with pytest.raises(FailureRateExceededError): config_path = ROOT / "tests" / f"scripts/other_langs/r_failure_nan/config.yaml" - dunder_main.main(split_shell_command(f"--config-path {config_path} -td"), standalone_mode=False) + cli_main(split_shell_command(f"--config-path {config_path} -td"), standalone_mode=False) diff --git a/tests/integration_tests/test_storage.py b/tests/integration_tests/test_storage.py index 265c5ad..9e23f72 100644 --- a/tests/integration_tests/test_storage.py +++ b/tests/integration_tests/test_storage.py @@ -15,7 +15,6 @@ CORE_ENCODER_REGISTRY, ) -import boa.__main__ as dunder_main from boa import ( BaseWrapper, BOAConfig, @@ -31,6 +30,7 @@ split_shell_command, ) from boa.__version__ import __version__ +from boa.cli import main as cli_main from boa.definitions import ROOT TEST_DIR = ROOT / "tests" @@ -200,7 +200,7 @@ def test_can_pass_custom_wrapper_path_when_loading_scheduler_from_cli(stand_alon pre_num_trials = len(scheduler.experiment.trials) - scheduler = dunder_main.main( + scheduler = cli_main( split_shell_command(f"--scheduler-path {file_out} --wrapper-path {orig_wrapper_path} -td"), standalone_mode=False, )