diff --git a/cylc/rose/utilities.py b/cylc/rose/utilities.py index 515356a5..f9b476f5 100644 --- a/cylc/rose/utilities.py +++ b/cylc/rose/utilities.py @@ -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, @@ -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: diff --git a/tests/conftest.py b/tests/conftest.py index be321628..bd81c58a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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') diff --git a/tests/functional/test_reinstall.py b/tests/functional/test_reinstall.py index 7c7b06bc..2fbe3e45 100644 --- a/tests/functional/test_reinstall.py +++ b/tests/functional/test_reinstall.py @@ -124,7 +124,7 @@ 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' @@ -132,7 +132,8 @@ async def test_cylc_validate(fixture_provide_flow, cylc_validate_cli): ) ] ) -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 @@ -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' @@ -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'], @@ -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' @@ -204,6 +207,7 @@ async def test_cylc_reinstall_files2( mod_cylc_reinstall_cli, file_, expect, + version_info, ): """Run ``cylc reinstall``. @@ -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 diff --git a/tests/functional/test_reinstall_clean.py b/tests/functional/test_reinstall_clean.py index e42617bc..1bde1ba5 100644 --- a/tests/functional/test_reinstall_clean.py +++ b/tests/functional/test_reinstall_clean.py @@ -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' @@ -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 @@ -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' @@ -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``. @@ -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( ( diff --git a/tests/unit/test_fileinstall.py b/tests/unit/test_fileinstall.py index 1df20148..62eee563 100644 --- a/tests/unit/test_fileinstall.py +++ b/tests/unit/test_fileinstall.py @@ -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" diff --git a/tests/unit/test_functional_post_install.py b/tests/unit/test_functional_post_install.py index 7ff194ed..fff1a747 100644 --- a/tests/unit/test_functional_post_install.py +++ b/tests/unit/test_functional_post_install.py @@ -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. """ @@ -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')