From 3bcf859242358cf7970a279b830a823717e74146 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sun, 13 Oct 2024 05:04:56 -0500 Subject: [PATCH] !squash wip --- src/libvcs/pytest_plugin.py | 38 +++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/src/libvcs/pytest_plugin.py b/src/libvcs/pytest_plugin.py index f2382c45..fdde4d6b 100644 --- a/src/libvcs/pytest_plugin.py +++ b/src/libvcs/pytest_plugin.py @@ -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.""" @@ -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" @@ -129,7 +151,7 @@ def gitconfig( f""" [user] email = {vcs_email} - name = {getpass.getuser()} + name = {vcs_name} [color] diff = auto """, @@ -155,6 +177,7 @@ 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" @@ -162,7 +185,7 @@ def hgconfig( textwrap.dedent( f""" [ui] - username = libvcs tests + username = {vcs_user} merge = internal:merge [trusted] @@ -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