Skip to content

Commit

Permalink
Merge pull request #6439 from MetRonnie/log-vc-info
Browse files Browse the repository at this point in the history
`log_vc_info`: add tests for when VCS not installed
  • Loading branch information
oliver-sanders authored Oct 24, 2024
2 parents 5995098 + a5f18ca commit 576170c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
8 changes: 5 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import logging
import re
from pathlib import Path
from shutil import rmtree
from typing import List, Optional, Tuple

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
Expand All @@ -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()

Expand Down
28 changes: 27 additions & 1 deletion tests/unit/post_install/test_log_vc_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,22 @@
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
from unittest.mock import Mock

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
Expand Down Expand Up @@ -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",
)

0 comments on commit 576170c

Please sign in to comment.