From 5313f15aa7f819aecc379fe12e7cc376a877273e Mon Sep 17 00:00:00 2001 From: Ronnie Dutta <61982285+MetRonnie@users.noreply.github.com> Date: Tue, 22 Oct 2024 15:07:31 +0100 Subject: [PATCH 1/2] `log_vc_info`: add tests for when VCS not installed --- tests/unit/post_install/test_log_vc_info.py | 28 ++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/tests/unit/post_install/test_log_vc_info.py b/tests/unit/post_install/test_log_vc_info.py index 1fb12dd822d..59511db5461 100644 --- a/tests/unit/post_install/test_log_vc_info.py +++ b/tests/unit/post_install/test_log_vc_info.py @@ -19,6 +19,7 @@ from pathlib import Path import pytest from pytest import MonkeyPatch, TempPathFactory +from secrets import token_hex import shutil import subprocess from typing import Any, Callable, Tuple @@ -26,13 +27,14 @@ from cylc.flow.install_plugins.log_vc_info import ( INFO_FILENAME, + VCSNotInstalledError, _get_git_commit, + _run_cmd, get_status, get_vc_info, main, write_diff, ) - from cylc.flow.workflow_files import WorkflowFiles Fixture = Any @@ -284,3 +286,27 @@ def test_untracked_svn_subdir( source_dir.mkdir() assert get_vc_info(source_dir) is None assert log_filter(caplog, level=logging.WARNING, contains="$ svn info") + + +def test_not_installed( + tmp_path, + monkeypatch: pytest.MonkeyPatch, + caplog: pytest.LogCaptureFixture, + log_filter, +): + """Test what happens if version control software is not installed.""" + fake_vcs = token_hex(8) + with pytest.raises(VCSNotInstalledError): + _run_cmd(fake_vcs, [], cwd=tmp_path) + + monkeypatch.setattr( + 'cylc.flow.install_plugins.log_vc_info.INFO_COMMANDS', + {fake_vcs: []} + ) + caplog.set_level(logging.DEBUG) + assert get_vc_info(tmp_path) is None + assert log_filter( + caplog, + level=logging.DEBUG, + contains=f"{fake_vcs} does not appear to be installed", + ) From a5f18ca62579b7356163d19ef7ba4f235601b027 Mon Sep 17 00:00:00 2001 From: Ronnie Dutta <61982285+MetRonnie@users.noreply.github.com> Date: Tue, 22 Oct 2024 17:37:55 +0100 Subject: [PATCH 2/2] Reset Cylc logger level before every test --- tests/conftest.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index a7b1d19ca2c..d07f788ba0b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import logging import re from pathlib import Path from shutil import rmtree @@ -21,7 +22,7 @@ import pytest -from cylc.flow import flags +from cylc.flow import LOG, flags from cylc.flow.cfgspec.glbl_cfg import glbl_cfg from cylc.flow.cfgspec.globalcfg import SPEC from cylc.flow.graphnode import GraphNodeParser @@ -30,10 +31,11 @@ @pytest.fixture(autouse=True) -def test_reset(): - """Reset global state before all tests.""" +def before_each(): + """Reset global state before every test.""" flags.verbosity = 0 flags.cylc7_back_compat = False + LOG.setLevel(logging.NOTSET) # Reset graph node parser singleton: GraphNodeParser.get_inst().clear()