Skip to content

Commit

Permalink
Limit check_requirement test for certain version of git
Browse files Browse the repository at this point in the history
(refs #15968)
  • Loading branch information
aeslaughter committed Nov 4, 2020
1 parent d1a884b commit 6492363
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 3 deletions.
3 changes: 2 additions & 1 deletion python/MooseDocs/test/commands/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import moosesqa
from MooseDocs.commands import check

@unittest.skipIf(mooseutils.git_version() < (2,11,4), "Git version must at least 2.11.4")
class TestCheckScript(unittest.TestCase):
def testCheck(self, *args):
cmd = ['python', 'moosedocs.py', 'check', '--config', 'sqa_test_reports.yml']
Expand All @@ -24,7 +25,7 @@ def testCheck(self, *args):
self.assertIn('moose_test', out)
self.assertIn('OK', out)


@unittest.skipIf(mooseutils.git_version() < (2,11,4), "Git version must at least 2.11.4")
class TestCheck(unittest.TestCase):
def setUp(self):
# Change to the test/doc directory
Expand Down
2 changes: 2 additions & 0 deletions python/moosesqa/test/test_SQADocumentReport.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
import logging

import MooseDocs
import mooseutils
from moosesqa import SQAReport, SQADocumentReport, LogHelper

@unittest.skipIf(mooseutils.git_version() < (2,11,4), "Git version must at least 2.11.4")
class TestSQADocumentReport(unittest.TestCase):
def setUp(self):
SQADocumentReport.FILE_CACHE = MooseDocs.PROJECT_FILES
Expand Down
2 changes: 2 additions & 0 deletions python/moosesqa/test/test_SQARequirementReport.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
import mock
import logging
import pyhit
import mooseutils
from moosesqa import SQAReport, SQARequirementReport


@unittest.skipIf(mooseutils.git_version() < (2,11,4), "Git version must at least 2.11.4")
class TestSQARequirementReport(unittest.TestCase):

@mock.patch('mooseutils.colorText', side_effect=lambda t, c, **kwargs: t)
Expand Down
4 changes: 3 additions & 1 deletion python/moosesqa/test/test_check_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
import mock
import logging
import moosesqa
import mooseutils

logging.basicConfig()

@unittest.skipIf(mooseutils.git_version() < (2,11,4), "Git version must at least 2.11.4")
class TestCheckRequirements(unittest.TestCase):

def setUp(self):
self._patcher = mock.patch('mooseutils.colorText', side_effect=lambda t, c: t)
self._patcher = mock.patch('mooseutils.colorText', side_effect=lambda t, c, **kwargs: t)
self._patcher.start()

def testDeprecated(self):
Expand Down
2 changes: 1 addition & 1 deletion python/mooseutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from .mooseutils import touch, unique_list, gold, make_chunks, camel_to_space
from .mooseutils import text_diff, unidiff, text_unidiff, run_profile, list_files, check_output, run_time
from .mooseutils import generate_filebase, recursive_update, fuzzyEqual, fuzzyAbsoluteEqual
from .gitutils import is_git_repo, git_commit, git_commit_message, git_merge_commits, git_ls_files, git_root_dir, git_init_submodule, git_submodule_status
from .gitutils import is_git_repo, git_commit, git_commit_message, git_merge_commits, git_ls_files, git_root_dir, git_init_submodule, git_submodule_status, git_version
from .message import mooseDebug, mooseWarning, mooseMessage, mooseError
from .MooseException import MooseException
from .eval_path import eval_path
Expand Down
10 changes: 10 additions & 0 deletions python/mooseutils/gitutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,13 @@ def git_init_submodule(path, working_dir=os.getcwd()):
if (submodule == path) and (status == '-'):
subprocess.call(['git', 'submodule', 'update', '--init', path], cwd=working_dir)
break

def git_version():
"""
Return the version number as a tuple (major, minor, patch)
"""
out = check_output(['git', '--version'], encoding='utf-8')
match = re.search(r'(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)', out)
if match is None:
raise SystemError("git --version failed to return correctly formatted version number")
return (int(match.group('major')), int(match.group('minor')), int(match.group('patch')))
13 changes: 13 additions & 0 deletions python/mooseutils/tests/test_gitutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,18 @@ def testGitInitSubmodule(self, status_func, call_func):
status_func.assert_called_with(root)
call_func.assert_called_with(['git', 'submodule', 'update', '--init', 'test'], cwd=root)

def testGitVersion(self):
ver = mooseutils.git_version()
self.assertEqual(len(ver), 3)
self.assertIsInstance(ver[0], int)
self.assertIsInstance(ver[1], int)
self.assertIsInstance(ver[2], int)

@mock.patch('re.search')
def testGitVersion2(self, re_func):
re_func.return_value = None
with self.assertRaises(SystemError):
ver = mooseutils.git_version()

if __name__ == '__main__':
unittest.main(verbosity=2, buffer=True)

0 comments on commit 6492363

Please sign in to comment.