From dbfba3211bc9f7f61c881ddd0c934105a3cc313c Mon Sep 17 00:00:00 2001 From: Theofilos Manitaras Date: Fri, 4 Sep 2020 10:02:41 +0200 Subject: [PATCH 1/2] Make 'git_repo_hash' work if git is not installed * Catch the exception thrown in case git is not installed * Add a unittest --- reframe/utility/os_ext.py | 2 +- unittests/test_utility.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/reframe/utility/os_ext.py b/reframe/utility/os_ext.py index c5aa2e5995..212e42de77 100644 --- a/reframe/utility/os_ext.py +++ b/reframe/utility/os_ext.py @@ -357,7 +357,7 @@ def git_repo_hash(branch='HEAD', short=True, wd=None): completed = run_command('git rev-parse %s' % branch, check=True, log=False) - except SpawnedProcessError: + except (SpawnedProcessError, FileNotFoundError): return None hash = completed.stdout.strip() diff --git a/unittests/test_utility.py b/unittests/test_utility.py index 37c2a13fae..1696287944 100644 --- a/unittests/test_utility.py +++ b/unittests/test_utility.py @@ -187,13 +187,17 @@ def test_is_url(): assert not os_ext.is_url(repo_ssh) -def test_git_repo_hash(): - # A git branch hash consists of 8(short) or 40 characters. +def test_git_repo_hash(monkeypatch): + # a git branch hash consists of 8(short) or 40 characters. assert len(os_ext.git_repo_hash()) == 8 assert len(os_ext.git_repo_hash(short=False)) == 40 assert os_ext.git_repo_hash(branch='invalid') is None assert os_ext.git_repo_hash(branch='') is None + # imitate a system with no git installed by emptying the PATH + monkeypatch.setenv('PATH', '') + assert os_ext.git_repo_hash() is None + def test_git_repo_exists(): assert os_ext.git_repo_exists('https://github.com/eth-cscs/reframe.git', From a85f04675044f05088d39ac71562b97ca7016054 Mon Sep 17 00:00:00 2001 From: Theofilos Manitaras Date: Fri, 4 Sep 2020 15:33:27 +0200 Subject: [PATCH 2/2] Address PR comments --- unittests/test_utility.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unittests/test_utility.py b/unittests/test_utility.py index 1696287944..90e8f52b87 100644 --- a/unittests/test_utility.py +++ b/unittests/test_utility.py @@ -188,13 +188,13 @@ def test_is_url(): def test_git_repo_hash(monkeypatch): - # a git branch hash consists of 8(short) or 40 characters. + # A git branch hash consists of 8(short) or 40 characters. assert len(os_ext.git_repo_hash()) == 8 assert len(os_ext.git_repo_hash(short=False)) == 40 assert os_ext.git_repo_hash(branch='invalid') is None assert os_ext.git_repo_hash(branch='') is None - # imitate a system with no git installed by emptying the PATH + # Imitate a system with no git installed by emptying the PATH monkeypatch.setenv('PATH', '') assert os_ext.git_repo_hash() is None