-
-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #294 from alaws-scottlogic/git-version-check
Check for Git > 2.38
- Loading branch information
Showing
4 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from pydriller.utils.check_git_version import CheckGitVersion | ||
|
||
|
||
CheckGitVersion().check_git_version() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import subprocess | ||
import re | ||
|
||
|
||
class GitVersion(Exception): | ||
def __init__(self, message): | ||
super().__init__(message) | ||
|
||
|
||
class CheckGitVersion: | ||
def check_git_version(self): | ||
git_version = ( | ||
subprocess.check_output(["git", "--version"]).decode("ascii").strip() | ||
) | ||
version_number = re.findall(r"[0-9]+\.[0-9]+", git_version)[0] | ||
if float(version_number) < 2.38: | ||
raise GitVersion( | ||
f"Current git version is {version_number}. Minimum supported version is 2.38." | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
mock | ||
types-mock | ||
pytest | ||
psutil | ||
psutil | ||
pytest-mock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from unittest.mock import patch | ||
from pydriller.utils.check_git_version import CheckGitVersion, GitVersion | ||
from contextlib import nullcontext as does_not_raise | ||
|
||
import pytest | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"version_number,expectation", | ||
[ | ||
("3.2.0", does_not_raise()), | ||
("2.38.1", does_not_raise()), | ||
("2.0.0", pytest.raises(GitVersion)), | ||
], | ||
) | ||
def test_extracts_correct_version(version_number, expectation): | ||
with patch( | ||
"pydriller.utils.check_git_version.subprocess.check_output" | ||
) as mock_git_version: | ||
mock_git_version().decode.return_value.strip.return_value = ( | ||
f"git version {version_number}" | ||
) | ||
with expectation: | ||
CheckGitVersion().check_git_version() |