-
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(git): support running tests outside of gitdir (#443)
- Loading branch information
1 parent
f41dca5
commit b566fc3
Showing
1 changed file
with
16 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,12 @@ | |
import unittest | ||
from unittest import mock | ||
|
||
import pytest | ||
|
||
import coveralls.git | ||
from coveralls.exception import CoverallsException | ||
from coveralls.git import run_command | ||
|
||
|
||
GIT_COMMIT_MSG = 'first commit' | ||
GIT_EMAIL = '[email protected]' | ||
|
@@ -15,6 +19,14 @@ | |
GIT_URL = 'https://github.com/username/Hello-World.git' | ||
|
||
|
||
def in_git_dir() -> bool: | ||
try: | ||
run_command('git', 'rev-parse') | ||
return True | ||
except Exception: | ||
return False | ||
|
||
|
||
class GitTest(unittest.TestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
|
@@ -76,6 +88,7 @@ def test_git(self): | |
|
||
|
||
class GitLogTest(GitTest): | ||
@pytest.mark.skipif(not in_git_dir(), reason='requires .git directory') | ||
def test_gitlog(self): | ||
git_info = coveralls.git.gitlog('%H') | ||
assert re.match(r'^[a-f0-9]{40}$', git_info) | ||
|
@@ -143,6 +156,7 @@ def test_gitinfo_not_a_git_repo(self): | |
|
||
|
||
class GitInfoOverridesTest(unittest.TestCase): | ||
@pytest.mark.skipif(not in_git_dir(), reason='requires .git directory') | ||
@mock.patch.dict( | ||
os.environ, { | ||
'GITHUB_ACTIONS': 'true', | ||
|
@@ -155,6 +169,7 @@ def test_gitinfo_github_pr(self): | |
git_info = coveralls.git.git_info() | ||
assert git_info['git']['branch'] == 'fixup-branch' | ||
|
||
@pytest.mark.skipif(not in_git_dir(), reason='requires .git directory') | ||
@mock.patch.dict( | ||
os.environ, { | ||
'GITHUB_ACTIONS': 'true', | ||
|
@@ -167,6 +182,7 @@ def test_gitinfo_github_branch(self): | |
git_info = coveralls.git.git_info() | ||
assert git_info['git']['branch'] == 'master' | ||
|
||
@pytest.mark.skipif(not in_git_dir(), reason='requires .git directory') | ||
@mock.patch.dict( | ||
os.environ, { | ||
'GITHUB_ACTIONS': 'true', | ||
|