-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
167 additions
and
7 deletions.
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
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
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 |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
""" | ||
from .cmd import * | ||
from .expr import * | ||
from .git import * |
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,40 @@ | ||
from typing import Optional | ||
|
||
from .version import VersionInfo | ||
from ...system.git.info import git_info | ||
|
||
__all__ = [ | ||
'is_git_installed', | ||
'git_version', | ||
'is_git_lfs_installed', | ||
'git_lfs_version', | ||
] | ||
|
||
|
||
def is_git_installed(git_path: Optional[str] = None) -> bool: | ||
return git_info(git_path=git_path)['installed'] | ||
|
||
|
||
def git_version(git_path: Optional[str] = None) -> Optional[VersionInfo]: | ||
# note that return value of this function is not guaranteed to be non-None when git is installed | ||
# when git --version output unrecognizable value, this func can also return None | ||
info = git_info(git_path=git_path) | ||
if info['installed'] and info['version']: | ||
return VersionInfo(info['version']) | ||
else: | ||
return None | ||
|
||
|
||
def is_git_lfs_installed(git_path: Optional[str] = None) -> bool: | ||
info = git_info(git_path=git_path) | ||
return bool(info['installed'] and info['lfs']['installed']) | ||
|
||
|
||
def git_lfs_version(git_path: Optional[str] = None) -> Optional[VersionInfo]: | ||
# note that return value of this function is not guaranteed to be non-None when git lfs is installed | ||
# when git lfs version output unrecognizable value, this func can also return None | ||
info = git_info(git_path=git_path) | ||
if info['installed'] and info['lfs']['installed'] and info['lfs']['version']: | ||
return VersionInfo(info['lfs']['version']) | ||
else: | ||
return None |
Empty file.
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 @@ | ||
import shutil | ||
|
||
_GIT_LFS = shutil.which('git_lfs', path='dist') | ||
_GIT_RAW = shutil.which('git_raw', path='dist') |
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,55 @@ | ||
import shutil | ||
from unittest import skipUnless | ||
|
||
import pytest | ||
|
||
from hbutils.system.git.info import git_info | ||
from hbutils.testing import isolated_directory | ||
from .conftest import _GIT_LFS, _GIT_RAW | ||
|
||
|
||
@pytest.mark.unittest | ||
class TestSystemGitInfo: | ||
@skipUnless(shutil.which('git'), 'Git required.') | ||
def test_git_installed(self): | ||
assert git_info()['installed'] | ||
|
||
@skipUnless(not shutil.which('git'), 'No git required.') | ||
def test_git_not_installed(self): | ||
assert not git_info()['installed'] | ||
|
||
def test_git_not_installed_tmp(self): | ||
with isolated_directory(): | ||
assert git_info('git') == { | ||
'exec': None, | ||
'installed': False, | ||
} | ||
|
||
|
||
@pytest.mark.unittest | ||
@skipUnless(_GIT_LFS, 'Pre-compiled git_lfs required') | ||
class TestSystemGitInfoLFS: | ||
def test_git_info(self): | ||
assert git_info(_GIT_LFS) == { | ||
'exec': _GIT_LFS, | ||
'installed': True, | ||
'lfs': { | ||
'installed': True, | ||
'version': '2.13.3', | ||
'version_info': 'git-lfs/2.13.3 (GitHub; linux amd64; go 1.16.2)'}, | ||
'version': '2.30.0', | ||
'version_info': 'git version 2.30.0' | ||
} | ||
|
||
|
||
@pytest.mark.unittest | ||
@skipUnless(_GIT_RAW, 'Pre-compiled git_lfs required') | ||
class TestSystemGitInfoLFS: | ||
def test_git_info(self): | ||
assert git_info(_GIT_RAW) == { | ||
'exec': _GIT_RAW, | ||
'installed': True, | ||
'lfs': {'installed': False}, | ||
'version': '2.28.0', | ||
'version_info': 'git version 2.28.0' | ||
} |
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 @@ | ||
import shutil | ||
|
||
_GIT_LFS = shutil.which('git_lfs', path='dist') | ||
_GIT_RAW = shutil.which('git_raw', path='dist') |
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,58 @@ | ||
import shutil | ||
from unittest import skipUnless | ||
|
||
import pytest | ||
|
||
from hbutils.testing import isolated_directory | ||
from hbutils.testing.requires import is_git_installed, is_git_lfs_installed, git_version, git_lfs_version | ||
from .conftest import _GIT_LFS, _GIT_RAW | ||
|
||
|
||
@pytest.mark.unittest | ||
class TestTestingRequiresGitNative: | ||
@skipUnless(shutil.which('git'), 'Git required.') | ||
def test_is_git_installed(self): | ||
assert is_git_installed() | ||
|
||
@skipUnless(not shutil.which('git'), 'No git required.') | ||
def test_is_git_installed_not_installed(self): | ||
assert not is_git_installed() | ||
|
||
def test_is_git_installed_negative(self): | ||
with isolated_directory(): | ||
assert not is_git_installed('git') | ||
assert git_version('git') is None | ||
assert not is_git_lfs_installed('git') | ||
assert git_lfs_version('git') is None | ||
|
||
|
||
@pytest.mark.unittest | ||
@skipUnless(_GIT_LFS, 'Pre-compiled git_lfs required') | ||
class TestTestingRequiresGitLFS: | ||
def test_is_git_installed(self): | ||
assert is_git_installed(_GIT_LFS) | ||
|
||
def test_git_version(self): | ||
assert git_version(_GIT_LFS) == '2.30.0' | ||
|
||
def test_is_git_lfs_installed(self): | ||
assert is_git_lfs_installed(_GIT_LFS) | ||
|
||
def test_git_lfs_version(self): | ||
assert git_lfs_version(_GIT_LFS) == '2.13.3' | ||
|
||
|
||
@pytest.mark.unittest | ||
@skipUnless(_GIT_RAW, 'Pre-compiled git_raw required') | ||
class TestTestingRequiresGitRAW: | ||
def test_is_git_installed(self): | ||
assert is_git_installed(_GIT_RAW) | ||
|
||
def test_git_version(self): | ||
assert git_version(_GIT_RAW) == '2.28.0' | ||
|
||
def test_is_git_lfs_installed(self): | ||
assert not is_git_lfs_installed(_GIT_RAW) | ||
|
||
def test_git_lfs_version(self): | ||
assert git_lfs_version(_GIT_RAW) is None |