コード例 #1
0
def fixture_yield_bout_path() -> Iterator[Path]:
    """
    Yield the BOUT++ path.

    Yields
    ------
    bout_path : Path
        Path to the BOUT++ repository
    """
    bout_path = get_bout_directory()

    yield bout_path
コード例 #2
0
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("")
コード例 #3
0
def get_file_modification(project_path: Path, makefile_path: Path,
                          exec_name: str) -> Dict[str, str]:
    """
    Return the file modification info.

    Parameters
    ----------
    project_path : Path
        Path to the project
    makefile_path : Path
            Path to the project makefile
    exec_name : str
        Name of the executable

    Returns
    -------
    file_modification : dict
        The file modification on the form

        >>> {'project_makefile_modified': str,
        ...  'project_executable_modified': str,
        ...  'project_git_sha': str,
        ...  'bout_lib_modified': str,
        ...  'bout_git_sha': str,}
    """
    file_modification = dict()
    file_modification["project_makefile_modified"] = get_modified_time(
        makefile_path)

    project_executable = makefile_path.parent.joinpath(exec_name)
    file_modification["project_executable_modified"] = get_modified_time(
        project_executable)

    file_modification["project_git_sha"] = get_git_sha(project_path)

    bout_path = get_bout_directory()
    file_modification["bout_lib_modified"] = get_modified_time(
        bout_path.joinpath("lib", "libbout++.a"))
    file_modification["bout_git_sha"] = get_git_sha(bout_path)

    return file_modification
コード例 #4
0
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)