Skip to content

Commit

Permalink
!squash wip
Browse files Browse the repository at this point in the history
  • Loading branch information
tony committed Oct 13, 2024
1 parent 96ee264 commit 3bcf859
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions src/libvcs/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,29 @@ def __init__(self, attempts: int, *args: object) -> None:
)


DEFAULT_VCS_NAME = "Test user"
DEFAULT_VCS_EMAIL = "test@example.com"
DEFAULT_VCS_USER = f"{DEFAULT_VCS_NAME} <{DEFAULT_VCS_EMAIL}>"


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


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


@pytest.fixture
def vcs_user(vcs_name: str, vcs_email: str) -> str:
"""Return default VCS user."""
return f"{vcs_name} <{vcs_email}>"


class RandomStrSequence:
"""Create a random string sequence."""

Expand Down Expand Up @@ -110,13 +133,12 @@ def set_home(
monkeypatch.setenv("HOME", str(user_path))


vcs_email = "libvcs@git-pull.com"


@pytest.fixture(scope="session")
@skip_if_git_missing
def gitconfig(
user_path: pathlib.Path,
vcs_email: str,
vcs_name: str,
) -> pathlib.Path:
"""Return git configuration, pytest fixture."""
gitconfig = user_path / ".gitconfig"
Expand All @@ -129,7 +151,7 @@ def gitconfig(
f"""
[user]
email = {vcs_email}
name = {getpass.getuser()}
name = {vcs_name}
[color]
diff = auto
""",
Expand All @@ -155,14 +177,15 @@ def set_gitconfig(
@skip_if_hg_missing
def hgconfig(
user_path: pathlib.Path,
vcs_user: str,
) -> pathlib.Path:
"""Return Mercurial configuration."""
hgrc = user_path / ".hgrc"
hgrc.write_text(
textwrap.dedent(
f"""
[ui]
username = libvcs tests <libvcs@git-pull.com>
username = {vcs_user}
merge = internal:merge
[trusted]
Expand Down Expand Up @@ -424,7 +447,10 @@ def git_remote_repo(
git_remote_repo_single_commit_post_init(
remote_repo_path=repo_path,
env={
"GITCONFIG": str(gitconfig),
"GIT_AUTHOR_NAME": "libvcs tests",
"GIT_COMMITTER_NAME": "libvcs tests",
"GIT_COMMITTER_EMAIL": vcs_email,
"GIT_AUTHOR_EMAIL": vcs_email,
},
)
return repo_path
Expand Down

0 comments on commit 3bcf859

Please sign in to comment.