Skip to content

Commit

Permalink
test(git): support running tests outside of gitdir (#443)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheKevJames authored May 15, 2024
1 parent f41dca5 commit b566fc3
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/git_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 'me@here.com'
Expand All @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down

0 comments on commit b566fc3

Please sign in to comment.