Skip to content

Commit

Permalink
!squash more
Browse files Browse the repository at this point in the history
  • Loading branch information
tony committed Oct 13, 2024
1 parent 3bcf859 commit dec09ed
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
29 changes: 20 additions & 9 deletions src/libvcs/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ def __init__(self, attempts: int, *args: object) -> None:
DEFAULT_VCS_USER = f"{DEFAULT_VCS_NAME} <{DEFAULT_VCS_EMAIL}>"


@pytest.fixture
@pytest.fixture(scope="session")
def vcs_name() -> str:
"""Return default VCS name."""
return DEFAULT_VCS_NAME


@pytest.fixture
@pytest.fixture(scope="session")
def vcs_email() -> str:
"""Return default VCS email."""
return DEFAULT_VCS_EMAIL


@pytest.fixture
@pytest.fixture(scope="session")
def vcs_user(vcs_name: str, vcs_email: str) -> str:
"""Return default VCS user."""
return f"{vcs_name} <{vcs_email}>"
Expand Down Expand Up @@ -260,7 +260,11 @@ def unique_repo_name(remote_repos_path: pathlib.Path, max_retries: int = 15) ->
class CreateRepoPostInitFn(Protocol):
"""Typing for VCS repo creation callback."""

def __call__(self, remote_repo_path: pathlib.Path) -> None:
def __call__(
self,
remote_repo_path: pathlib.Path,
env: "_ENV | None" = None,
) -> None:
"""Ran after creating a repo from pytest fixture."""
...

Expand Down Expand Up @@ -440,17 +444,19 @@ def git_remote_repo_single_commit_post_init(
def git_remote_repo(
create_git_remote_repo: CreateRepoPytestFixtureFn,
gitconfig: pathlib.Path,
vcs_email: str,
vcs_name: str,
) -> pathlib.Path:
"""Copy the session-scoped Git repository to a temporary directory."""
# TODO: Cache the effect of of this in a session-based repo
repo_path = create_git_remote_repo()
git_remote_repo_single_commit_post_init(
remote_repo_path=repo_path,
env={
"GIT_AUTHOR_NAME": "libvcs tests",
"GIT_COMMITTER_NAME": "libvcs tests",
"GIT_COMMITTER_EMAIL": vcs_email,
"GIT_AUTHOR_NAME": vcs_name,
"GIT_AUTHOR_EMAIL": vcs_email,
"GIT_COMMITTER_NAME": vcs_name,
"GIT_COMMITTER_EMAIL": vcs_email,
},
)
return repo_path
Expand Down Expand Up @@ -626,6 +632,7 @@ def empty_hg_repo(
def create_hg_remote_repo(
remote_repos_path: pathlib.Path,
empty_hg_repo: pathlib.Path,
hgconfig: pathlib.Path,
) -> CreateRepoPytestFixtureFn:
"""Pre-made hg repo, bare, used as a file:// remote to checkout and commit to."""

Expand All @@ -642,7 +649,10 @@ def fn(
shutil.copytree(empty_hg_repo, remote_repo_path)

if remote_repo_post_init is not None and callable(remote_repo_post_init):
remote_repo_post_init(remote_repo_path=remote_repo_path)
remote_repo_post_init(
remote_repo_path=remote_repo_path,
env={"HGRCPATH": str(hgconfig)},
)

assert empty_hg_repo.exists()

Expand All @@ -663,7 +673,8 @@ def hg_remote_repo(
"""Pre-made, file-based repo for push and pull."""
repo_path = create_hg_remote_repo()
hg_remote_repo_single_commit_post_init(
remote_repo_path=repo_path, env={"HGRCPATH": str(hgconfig)}
remote_repo_path=repo_path,
env={"HGRCPATH": str(hgconfig)},
)
return repo_path

Expand Down
3 changes: 2 additions & 1 deletion tests/test_pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pytest

from libvcs._internal.run import run
from libvcs.pytest_plugin import CreateRepoPytestFixtureFn, vcs_email
from libvcs.pytest_plugin import CreateRepoPytestFixtureFn


@pytest.mark.skipif(not shutil.which("git"), reason="git is not available")
Expand Down Expand Up @@ -115,6 +115,7 @@ def test_repo_git_remote_checkout(
def test_gitconfig(
gitconfig: pathlib.Path,
set_gitconfig: pathlib.Path,
vcs_email: str,
) -> None:
"""Test gitconfig fixture."""
output = run(["git", "config", "--get", "user.email"])
Expand Down

0 comments on commit dec09ed

Please sign in to comment.