def test_set_log_file_directory( get_mock_config_path: Path, monkeypatch: MonkeyPatch ) -> None: """ Test that the log file directory is changeable. Parameters ---------- get_mock_config_path : Path The mocked config directory monkeypatch : MonkeyPatch MonkeyPatch from pytest """ config_path = get_mock_config_path original_dir = get_log_file_directory() # Test with empty input monkeypatch.setattr("builtins.input", lambda _: "") set_log_file_directory() config = get_bout_runners_configuration() assert config["log"]["directory"] == str(original_dir) # Test with parameter input log_dir = config_path.joinpath("test_set_log_dir_with_parameter") set_log_file_directory(log_dir) config = get_bout_runners_configuration() assert config["log"]["directory"] == str(log_dir) # Test with non-empty input log_dir = config_path.joinpath("test_set_log_dir_parameter_2") monkeypatch.setattr("builtins.input", lambda _: str(log_dir)) set_log_file_directory() config = get_bout_runners_configuration() assert config["log"]["directory"] == str(log_dir)
def test_set_submitter_config_path( get_mock_config_path: Path, monkeypatch: MonkeyPatch ) -> None: """ Test that the submitter configuration path is changeable. Parameters ---------- get_mock_config_path : Path The mocked config directory monkeypatch : MonkeyPatch MonkeyPatch from pytest """ config_path = get_mock_config_path original_path = get_default_submitters_config_path() # Test with empty input monkeypatch.setattr("builtins.input", lambda _: "") set_submitter_config_path() config = get_bout_runners_configuration() assert config["submitter_config"]["path"] == str(original_path) # Test with parameter input submitter_path = config_path.joinpath( "test_set_submitter_with_parameter", "settings.ini" ) set_submitter_config_path(submitter_path) config = get_bout_runners_configuration() assert config["submitter_config"]["path"] == str(submitter_path) # Test with non-empty input submitter_path = config_path.joinpath( "test_set_submitter_with_parameter", "settings_2.ini" ) monkeypatch.setattr("builtins.input", lambda _: str(submitter_path)) set_submitter_config_path() config = get_bout_runners_configuration() assert config["submitter_config"]["path"] == str(submitter_path) # Test raises new_path = config_path.joinpath("test_set_submitter_raises", "settings.ini") new_path.parent.mkdir(parents=True, exist_ok=True) shutil.copy(original_path, new_path) new_config = configparser.ConfigParser() new_config.read(new_path) new_config.remove_option("local", "number_of_processors") with new_path.open("w") as configfile: new_config.write(configfile) with pytest.raises(ValueError): set_submitter_config_path(new_path) new_config.remove_section("local") with new_path.open("w") as configfile: new_config.write(configfile) with pytest.raises(ValueError): set_submitter_config_path(new_path)
def set_log_file_directory(log_dir: Optional[Path] = None) -> None: """ Set the directory of the log files. Parameters ---------- log_dir : None or Path The directory to keep the log files If None the caller will be prompted """ config = get_bout_runners_configuration() if log_dir is None: current_dir = get_log_file_directory() question = ( f"Please entering the directory for log files:\n" f"Empty input will reuse the current directory " f"{current_dir}\n" ) answer = input(question) print(f"Your answered: '{answer}'") if answer == "": config["log"]["directory"] = str(current_dir) else: config["log"]["directory"] = answer else: config["log"]["directory"] = str(log_dir) with get_bout_runners_config_path().open("w") as configfile: config.write(configfile) print(f"Setting logging dir to {config['log']['directory']}") set_up_logger() logging.debug("Logging directory set to %s", config["log"]["directory"]) print("")
def test_set_bout_directory( get_mock_config_path: Path, monkeypatch: MonkeyPatch ) -> None: """ Test that the BOUT++ directory is changeable. Parameters ---------- get_mock_config_path : Path The mocked config directory monkeypatch : MonkeyPatch MonkeyPatch from pytest """ _ = get_mock_config_path original_dir = get_bout_directory() # Test with empty input monkeypatch.setattr("builtins.input", lambda _: "") set_bout_directory() config = get_bout_runners_configuration() assert config["bout++"]["directory"] == str(original_dir) # Test with incorrect input with pytest.raises(ValueError): set_bout_directory(original_dir.joinpath("not", "a", "dir")) # Test with parameter input bout_dir = original_dir.parent set_bout_directory(bout_dir) config = get_bout_runners_configuration() assert config["bout++"]["directory"] == str(bout_dir) # Test with non-empty input monkeypatch.setattr("builtins.input", lambda _: str(original_dir)) set_bout_directory() config = get_bout_runners_configuration() assert config["bout++"]["directory"] == str(original_dir)
def set_bout_directory(bout_dir: Optional[Path] = None) -> None: """ Set the path to the BOUT++ directory. Parameters ---------- bout_dir : None or Path The path to the BOUT++ directory If None, the caller will be prompted Raises ------ ValueError If BOUT++ not found in the directory """ config = get_bout_runners_configuration() if bout_dir is None: suggested_dir = get_bout_directory() question = ( f"Please entering the directory for the root of BOUT++:\n" f"Empty input use the directory " f"{suggested_dir}\n" ) answer = input(question) print(f"Your answered: '{answer}'") if answer != "": config["bout++"]["directory"] = answer else: config["bout++"]["directory"] = str(suggested_dir) else: config["bout++"]["directory"] = str(bout_dir) if not Path(config["bout++"]["directory"]).is_dir(): msg = f'BOUT++ not found in {config["bout++"]["directory"]}' raise ValueError(msg) with get_bout_runners_config_path().open("w") as configfile: config.write(configfile) print(f"Setting BOUT++ directory to {config['bout++']['directory']}") set_up_logger() logging.debug("BOUT++ directory set to %s", config["bout++"]["directory"]) print("")
def set_submitter_config_path( submitter_config_path: Optional[Path] = None) -> None: """ Set the path to the submitter configuration. Parameters ---------- submitter_config_path : None or Path The path to the submitter config file If None, the caller will be prompted """ config = get_bout_runners_configuration() default_path = get_default_submitters_config_path() if submitter_config_path is None: question = ( f"Please enter the path to the submitter configuration file:\n" f"Empty input use the path " f"{default_path}\n") answer = input(question) print(f"Your answered: '{answer}'") if answer != "": config["submitter_config"]["path"] = answer else: config["submitter_config"]["path"] = str(default_path) else: config["submitter_config"]["path"] = str(submitter_config_path) set_up_logger() submitter_config_path = Path(config["submitter_config"]["path"]) check_submitter_config(submitter_config_path, default_path) with get_bout_runners_config_path().open("w") as configfile: config.write(configfile) print(f"Setting submitter configuration file to {submitter_config_path}") logging.debug("submitter configuration file set to %s", submitter_config_path) print("")