Skip to content

Commit

Permalink
Log versions of Cylc, Rose and CylcRose in the rose-suite-cylc-instal…
Browse files Browse the repository at this point in the history
…l.conf
  • Loading branch information
wxtim committed May 8, 2024
1 parent 69f321c commit e3df1d2
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 10 deletions.
7 changes: 7 additions & 0 deletions cylc/rose/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
from cylc.flow.hostuserutil import get_host
from metomi.isodatetime.datetimeoper import DateTimeOperator
from metomi.rose import __version__ as ROSE_VERSION
from cylc.flow import __version__ as CYLC_VERSION
from cylc.rose import __version__ as CYLC_ROSE_VERSION
from metomi.rose.config import (
ConfigDumper,
ConfigLoader,
Expand Down Expand Up @@ -957,6 +959,11 @@ def record_cylc_install_options(
]

cli_config.comments = [' This file records CLI Options.']
cli_config.comments += [
' Installed with:',
f' * Cylc Rose: {CYLC_ROSE_VERSION}',
f' * Rose : {ROSE_VERSION}',
f' * Cylc : {CYLC_VERSION}']
dumper.dump(cli_config, str(conf_filepath))

# Merge the opts section of the rose-suite.conf with those set by CLI:
Expand Down
13 changes: 13 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,21 @@
rose_stem as _rose_stem,
)

from metomi.rose import __version__ as ROSE_VERSION
from cylc.rose import __version__ as CYLC_ROSE_VERSION

CYLC_RUN_DIR = Path(get_cylc_run_dir())
VERSIONINFO = f"""
# Installed with:
# * Cylc Rose: {CYLC_ROSE_VERSION}
# * Rose : {ROSE_VERSION}
# * Cylc : {CYLC_VERSION}
"""


@pytest.fixture
def version_info():
return VERSIONINFO


@pytest.fixture(scope='module')
Expand Down
13 changes: 9 additions & 4 deletions tests/functional/test_reinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,16 @@ async def test_cylc_validate(fixture_provide_flow, cylc_validate_cli):
),
(
'opt/rose-suite-cylc-install.conf', (
'# This file records CLI Options.\n\n'
'# This file records CLI Options.{version_info}\n'
'!opts=b c\n'
f'\n[env]\n#{ROHIOS}\nROSE_ORIG_HOST={HOST}\n'
f'\n[template variables]\n#{ROHIOS}\nROSE_ORIG_HOST={HOST}\n'
)
)
]
)
def test_cylc_install_files(fixture_install_flow, file_, expect):
def test_cylc_install_files(fixture_install_flow, file_, expect, version_info):
expect = expect.format(version_info=version_info)
fpath = fixture_install_flow['fixture_provide_flow']['flowpath']
assert (fpath / file_).read_text() == expect

Expand All @@ -149,7 +150,7 @@ def test_cylc_install_files(fixture_install_flow, file_, expect):
),
(
'opt/rose-suite-cylc-install.conf', (
'# This file records CLI Options.\n\n'
'# This file records CLI Options.{version_info}\n'
'!opts=b c d\n'
f'\n[env]\n#{ROHIOS}\nROSE_ORIG_HOST={HOST}\n'
f'\n[template variables]\n#{ROHIOS}\nROSE_ORIG_HOST={HOST}\n'
Expand All @@ -163,12 +164,14 @@ async def test_cylc_reinstall_files(
mod_cylc_reinstall_cli,
file_,
expect,
version_info,
):
"""Run ``cylc reinstall``.
By running in a fixture with modular scope we
can run tests on different aspects of its output as separate tests.
"""
expect = expect.format(version_info=version_info)
monkeymodule.delenv('ROSE_SUITE_OPT_CONF_KEYS', raising=False)
assert await mod_cylc_reinstall_cli(
fixture_install_flow['id'],
Expand All @@ -190,7 +193,7 @@ async def test_cylc_reinstall_files(
),
(
'opt/rose-suite-cylc-install.conf', (
'# This file records CLI Options.\n\n'
'# This file records CLI Options.{version_info}\n'
'!opts=b c d\n'
f'\n[env]\n#{ROHIOS}\nROSE_ORIG_HOST={HOST}\n'
f'\n[template variables]\n#{ROHIOS}\nROSE_ORIG_HOST={HOST}\n'
Expand All @@ -204,6 +207,7 @@ async def test_cylc_reinstall_files2(
mod_cylc_reinstall_cli,
file_,
expect,
version_info,
):
"""Run ``cylc reinstall``.
Expand All @@ -217,6 +221,7 @@ async def test_cylc_reinstall_files2(
If a test fails using ``pytest --pdb then``
``fixture_install_flow['result'].stderr`` may help with debugging.
"""
expect = expect.format(version_info=version_info)
monkeymodule.delenv('ROSE_SUITE_OPT_CONF_KEYS', raising=False)
(
fixture_install_flow
Expand Down
9 changes: 6 additions & 3 deletions tests/functional/test_reinstall_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async def fixture_install_flow(
[
(
'opt/rose-suite-cylc-install.conf', (
'# This file records CLI Options.\n\n'
'# This file records CLI Options.{version_info}\n'
'!opts=bar\n\n'
'[env]\n'
f'FOO=1\n#{ROHIOS}\n'
Expand All @@ -115,7 +115,8 @@ async def fixture_install_flow(
),
]
)
def test_cylc_install_files(fixture_install_flow, file_, expect):
def test_cylc_install_files(fixture_install_flow, file_, expect, version_info):
expect = expect.format(version_info=version_info)
fpath = fixture_install_flow['fixture_provide_flow']['flowpath']
assert (fpath / file_).read_text() == expect

Expand All @@ -125,7 +126,7 @@ def test_cylc_install_files(fixture_install_flow, file_, expect):
[
(
'opt/rose-suite-cylc-install.conf', (
'# This file records CLI Options.\n\n'
'# This file records CLI Options.{version_info}\n'
'!opts=baz\n\n'
'[env]\n'
f'BAR=2\n#{ROHIOS}\n'
Expand All @@ -141,6 +142,7 @@ async def test_cylc_reinstall_files(
mod_cylc_reinstall_cli,
file_,
expect,
version_info,
):
"""Run ``cylc reinstall --clear-rose-install-options``.
Expand All @@ -150,6 +152,7 @@ async def test_cylc_reinstall_files(
By running in a fixture with modular scope we
can run tests on different aspects of its output as separate tests.
"""
expect = expect.format(version_info=version_info)
monkeymodule.delenv('ROSE_SUITE_OPT_CONF_KEYS', raising=False)
assert await mod_cylc_reinstall_cli(
(
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/test_fileinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,15 @@ def test_rose_fileinstall_rose_conf(fixture_install_flow):
)


def test_rose_fileinstall_rose_suite_cylc_install_conf(fixture_install_flow):
def test_rose_fileinstall_rose_suite_cylc_install_conf(
fixture_install_flow,
version_info,
):
destpath = fixture_install_flow
host = get_host()
assert (destpath / 'opt/rose-suite-cylc-install.conf').read_text() == (
"# This file records CLI Options.\n\n"
"# This file records CLI Options."
f"{version_info}\n"
"!opts=A B\n\n"
"[env]\n"
"FOO=42\n"
Expand Down
11 changes: 10 additions & 1 deletion tests/unit/test_functional_post_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def test_rose_fileinstall_uses_rose_template_vars(tmp_path):
]
)
def test_functional_record_cylc_install_options(
monkeypatch, tmp_path, opts, files, env_inserts
monkeypatch, tmp_path, opts, files, env_inserts, request
):
"""It works the way the proposal says it should.
"""
Expand Down Expand Up @@ -264,6 +264,15 @@ def fake(*arg, **kwargs):
no_ignore=False
)

# Test comments dumped:
# Do this for just one case:
if request.node.callspec.id == 'opts0-files0-env_inserts0':
filetext = (testdir / 'opt/rose-suite-cylc-install.conf').read_text()
assert "Installed with" in filetext
assert "Cylc Rose: 1." in filetext
assert "Cylc : 8." in filetext
assert "Rose : 2." in filetext


def test_functional_rose_database_dumped_correctly(tmp_path):
srcdir = (tmp_path / 'srcdir')
Expand Down

0 comments on commit e3df1d2

Please sign in to comment.