Skip to content

Commit

Permalink
fix tests, try again with utf-8
Browse files Browse the repository at this point in the history
  • Loading branch information
radoering committed Jan 27, 2024
1 parent b6bc27e commit 35bfa95
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/poetry/core/vcs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def get_vcs(directory: Path) -> Git | None:
[executable(), "rev-parse", "--show-toplevel"],
stderr=subprocess.STDOUT,
text=True,
encoding="utf-8",
).strip()

vcs = Git(Path(git_dir))
Expand Down
38 changes: 16 additions & 22 deletions tests/vcs/test_vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,22 @@
from poetry.core.vcs.git import GitUrl
from poetry.core.vcs.git import ParsedUrl
from poetry.core.vcs.git import _reset_executable
from poetry.core.vcs.git import executable


if TYPE_CHECKING:
from pytest_mock import MockerFixture


@pytest.fixture
def reset_git() -> None:
_reset_executable()
try:
yield
finally:
_reset_executable()


@pytest.mark.parametrize(
"url, normalized",
[
Expand Down Expand Up @@ -437,51 +447,35 @@ def test_git_rev_parse_raises_error_on_invalid_repository() -> None:
" reasons"
),
)
def test_ensure_absolute_path_to_git(mocker: MockerFixture) -> None:
_reset_executable()

def test_ensure_absolute_path_to_git(reset_git: None, mocker: MockerFixture) -> None:
def checkout_output(cmd: list[str], *args: Any, **kwargs: Any) -> str | bytes:
if Path(cmd[0]).name == "where.exe":
return "\n".join([
str(Path.cwd().joinpath("git.exe")),
"C:\\Git\\cmd\\git.exe",
])
return "\n".join(
[str(Path.cwd().joinpath("git.exe")), r"C:\Git\cmd\git.exe"]
)

return b""

mock = mocker.patch.object(subprocess, "check_output", side_effect=checkout_output)

Git().run("config")

assert mock.call_args_list[-1][0][0] == [
"C:\\Git\\cmd\\git.exe",
"config",
]

assert mock.call_args_list[-1][0][0] == [r"C:\Git\cmd\git.exe", "config"]

@pytest.mark.skipif(
not WINDOWS,
reason=(
"Retrieving the complete path to git is only necessary on Windows, for security"
" reasons"
),
)
def test_ensure_existing_git_executable_is_found(mocker: MockerFixture) -> None:
mock = mocker.patch.object(subprocess, "check_output", return_value=b"")

Git().run("config")

cmd = Path(mock.call_args_list[-1][0][0][0])

assert cmd.is_absolute()
assert cmd.name == "git.exe"


def test_get_vcs_encoding(tmp_path: Path) -> None:
repo_path = tmp_path / "répö"
repo_path.mkdir()
assert repo_path.exists()
assert subprocess.check_call(["git", "init"], cwd=repo_path) == 0
assert subprocess.check_call([executable(), "init"], cwd=repo_path) == 0
vcs = get_vcs(repo_path)
assert vcs is not None
assert vcs._work_dir is not None
Expand Down

0 comments on commit 35bfa95

Please sign in to comment.