Exemplo n.º 1
0
def _git_info() -> Optional[str]:
    """Return git current commit information if possible else None."""
    gitdir = os.path.realpath(
        os.path.join(os.path.realpath(__file__), os.pardir, os.pardir))
    if not os.path.isdir(os.path.join(gitdir, ".git")):
        return None

    try:
        commit = run_qprocess(
            "git",
            "describe",
            "--match=NoMaTcH",
            "--always",
            "--abbrev=40",
            "--dirty",
            cwd=gitdir,
        )
        date = run_qprocess("git",
                            "show",
                            "-s",
                            "--format=%cd",
                            "--date=short",
                            "HEAD",
                            cwd=gitdir)
    except OSError:
        return None
    return f"Git: {commit} ({date})"
def test_run_qprocess_in_other_dir(tmp_path):
    directory = tmp_path / "directory"
    directory.mkdir()
    dirname = str(directory)
    assert utils.run_qprocess("pwd", cwd=dirname) == dirname
def test_fail_run_qprocess_raises_oserror(command, args):
    with pytest.raises(OSError):
        utils.run_qprocess(command, *args)
def test_run_qprocess():
    assert utils.run_qprocess("pwd") == os.getcwd()