Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for failed parse log with invalid git version #10801

Merged
merged 1 commit into from
Feb 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions tests/functional/test_vcs_git.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""
Contains functional tests of the Git class.
"""
import logging
import os
import pathlib
from typing import List, Optional, Tuple
from unittest.mock import patch
from unittest.mock import Mock, patch

import pytest

Expand Down Expand Up @@ -305,7 +306,7 @@ def _initialize_clonetest_server(
repo_path.mkdir()
script.run("git", "init", cwd=str(repo_path))
repo_file = repo_path / "file.txt"
repo_file.write_text(u".")
repo_file.write_text(".")
script.run("git", "add", "file.txt", cwd=str(repo_path))
script.run("git", "commit", "-m", "initial commit", cwd=str(repo_path))

Expand All @@ -319,6 +320,34 @@ def _initialize_clonetest_server(
return repo_file


@pytest.mark.parametrize(
"version_out, expected_message",
(
("git version -2.25.1", "Can't parse git version: git version -2.25.1"),
("git version 2.a.1", "Can't parse git version: git version 2.a.1"),
("git ver. 2.25.1", "Can't parse git version: git ver. 2.25.1"),
),
)
@patch("pip._internal.vcs.versioncontrol.VersionControl.run_command")
def test_git_parse_fail_warning(
mock_run_command: Mock,
caplog: pytest.LogCaptureFixture,
version_out: str,
expected_message: str,
) -> None:
"""Test invalid git version logs adds an explicit warning log."""
mock_run_command.return_value = version_out

caplog.set_level(logging.WARNING)

git_tuple = Git().get_git_version()
# Returns an empty tuple if it is an invalid git version
assert git_tuple == ()

# Check for warning log
assert expected_message in caplog.text.strip()


@pytest.mark.skipif(Git().get_git_version() < (2, 17), reason="git too old")
def test_partial_clone(script: PipTestEnvironment, tmp_path: pathlib.Path) -> None:
"""Test partial clone w/ a git-server that supports it"""
Expand Down Expand Up @@ -347,7 +376,7 @@ def test_partial_clone(script: PipTestEnvironment, tmp_path: pathlib.Path) -> No
)

# Write some additional stuff to git pull
repo_file.write_text(u"..")
repo_file.write_text("..")
script.run("git", "commit", "-am", "second commit", cwd=str(repo_path))

# Make sure git pull works - with server supporting filtering
Expand Down Expand Up @@ -391,7 +420,7 @@ def test_partial_clone_without_server_support(
)

# Write some additional stuff to git pull
repo_file.write_text(u"..")
repo_file.write_text("..")
script.run("git", "commit", "-am", "second commit", cwd=str(repo_path))

# Make sure git pull works - even though server doesn't support filtering
Expand Down Expand Up @@ -424,7 +453,7 @@ def test_clone_without_partial_clone_support(
verbosity=0,
)

repo_file.write_text(u"...")
repo_file.write_text("...")
script.run("git", "commit", "-am", "third commit", cwd=str(repo_path))

# Should work fine w/o attempting to use `--filter` args
Expand Down