Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wxtim committed Nov 5, 2024
1 parent 4819436 commit 8fdb310
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cylc/rose/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,7 @@ def retrieve_installed_cli_opts(srcdir, opts):

# Set ROSE_ORIG_HOST to ignored, and choose not to ignore it
# if this is a validation against source:
no_ignore = False
if rundir:
no_ignore = True
for keys, node in cli_config.walk():
Expand Down Expand Up @@ -1086,7 +1087,7 @@ def sanitize_opts(opts):
for (section, item), (var_name, replace) in itertools.product(
options, STANDARD_VARS
):
if re.match(rf'{var_name}=', item):
if re.match(rf'.*{var_name}=', item):
LOG.warning(
f'{section}:{item} from command line args'
f' will be ignored: {var_name} will be: {replace}'
Expand Down
24 changes: 24 additions & 0 deletions tests/functional/test_pre_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import pytest
from pytest import param

from cylc.rose.entry_points import pre_configure
from cylc.rose.utilities import NotARoseSuiteException, load_rose_config


Expand Down Expand Up @@ -255,3 +256,26 @@ async def test_validate_against_source(
)
assert clear_install_validate.ret != 0
assert 'Jinja2 Assertion Error' in str(clear_install_validate.exc.args[0])


def test_invalid_cli_opts(tmp_path, caplog):
"""Ensure that CLI options which won't be used because
they are variables set by Rose raise a warning."""
(tmp_path / 'flow.cylc').touch()
(tmp_path / 'rose-suite.conf').touch()

opts = SimpleNamespace(
rose_template_vars=['ROSE_ORIG_HOST=42'],
opt_conf_keys=[],
defines=[],
against_source=tmp_path,
)

pre_configure(tmp_path, opts)
# Assert we have the warning that we need:
assert (
"ROSE_ORIG_HOST=42 from command line args will be ignored"
in caplog.messages[0]
)
# Assert we haven't got any unwanted dupicate warnings:
assert len(caplog.messages) == 1
65 changes: 65 additions & 0 deletions tests/unit/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# THIS FILE IS PART OF THE ROSE-CYLC PLUGIN FOR THE CYLC WORKFLOW ENGINE.
# Copyright (C) NIWA & British Crown (Met Office) & Contributors.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""Tests for CLI Specific functionality"""

import pytest
from types import SimpleNamespace

from cylc.rose.utilities import sanitize_opts


@pytest.mark.parametrize(
"rose_template_vars, defines, expect_warning",
(
(
["ROSE_ORIG_HOST=3"],
[],
"rose_template_vars:ROSE_ORIG_HOST=3"
" from command line args will be ignored:",
),
(
[],
["[env]ROSE_ORIG_HOST=3"],
"defines:[env]ROSE_ORIG_HOST=3"
" from command line args will be ignored:",
),
(
["ROSE_ORIG_HOST=3"],
["[env]ROSE_ORIG_HOST=3"],
[
"defines:[env]ROSE_ORIG_HOST=3"
" from command line args will be ignored:",
"rose_template_vars:ROSE_ORIG_HOST=3"
" from command line args will be ignored:",
],
),
([], [], False)
),
)
def test_sanitzie_opts(caplog, rose_template_vars, defines, expect_warning):
opts = SimpleNamespace(
rose_template_vars=rose_template_vars,
defines=defines,
)
sanitize_opts(opts)
if expect_warning and isinstance(expect_warning, list):
for warning in expect_warning:
assert any(warning in w for w in caplog.messages)
elif expect_warning:
assert any(expect_warning in w for w in caplog.messages)
else:
assert not caplog.messages

0 comments on commit 8fdb310

Please sign in to comment.