def test_warn_if_root_dir_set(root_dir_config, tmp_path, caplog): """Test using unsupported root-dir config raises error.""" (tmp_path / 'rose-suite.conf').write_text(root_dir_config) get_rose_vars(srcdir=tmp_path) assert caplog.records[0].msg == ( 'You have set "root-dir", which is not supported at Cylc 8. Use ' '`[install] symlink dirs` in global.cylc instead.')
def test_warn_if_root_dir_set(tmp_path, caplog): (tmp_path / 'rose-suite.conf' ).write_text('root-dir="/the/only/path/ive/ever/known"\n') get_rose_vars(srcdir=tmp_path) assert caplog.records[0].msg == ( 'You have set "root-dir", which at Cylc 8 does nothing. ' 'See Cylc Install documentation.')
def test_get_rose_vars_fail_if_empy_AND_jinja2(tmp_path): """It should raise an error if both empy and jinja2 sections defined.""" (tmp_path / 'rose-suite.conf').write_text( "[jinja2:suite.rc]\n" "[empy:suite.rc]\n" ) with pytest.raises(MultipleTemplatingEnginesError): get_rose_vars(tmp_path)
def test_get_rose_vars(rose_config_template, override, section, exp_ANOTHER_JINJA2_ENV, exp_JINJA2_VAR): """Test reading of empy or jinja2 vars Scenarios tested: - Read in a basic rose-suite.conf file. Ensure we don't return env, just jinja2/empy. - Get optional config name from an environment variable. - Get optional config name from command line option. - Get optional config name from an explicit over-ride string. """ options = SimpleNamespace(opt_conf_keys=[], defines=[], rose_template_vars=[]) if override == 'environment': os.environ['ROSE_SUITE_OPT_CONF_KEYS'] = "gravy" else: # Prevent externally set environment var breaking tests. os.environ['ROSE_SUITE_OPT_CONF_KEYS'] = "" if override == 'CLI': options.opt_conf_keys = ["chips"] elif override == 'override': options.opt_conf_keys = ["chips"] options.defines = [ f"[{section}:suite.rc]Another_Jinja2_var='Variable overridden'" ] suite_path = rose_config_template(section) result = get_rose_vars(suite_path, options)['template_variables'] assert result['Another_Jinja2_var'] == exp_ANOTHER_JINJA2_ENV assert result['JINJA2_VAR'] == exp_JINJA2_VAR
def test_get_rose_vars_ROSE_VARS(tmp_path): """Test that rose variables are available in the environment section..""" (tmp_path / "rose-suite.conf").touch() rose_vars = get_rose_vars(tmp_path) assert list(rose_vars['env'].keys()) == [ 'ROSE_ORIG_HOST', 'ROSE_VERSION', 'ROSE_SITE' ]
def test_get_rose_vars_jinja2_ROSE_VARS(tmp_path): """Test that ROSE_SUITE_VARIABLES are available to jinja2.""" (tmp_path / "rose-suite.conf").write_text("[jinja2:suite.rc]") rose_vars = get_rose_vars(tmp_path) assert list(rose_vars['template_variables'] ['ROSE_SUITE_VARIABLES'].keys()).sort() == [ 'ROSE_VERSION', 'ROSE_ORIG_HOST', 'ROSE_SUITE_VARIABLES' ].sort()
def test_get_rose_vars_env_section(tmp_path): with open(tmp_path / 'rose-suite.conf', 'w+') as testfh: testfh.write( "[env]\n" "DOG_TYPE = Spaniel \n" ) assert ( get_rose_vars(tmp_path)['env']['DOG_TYPE'] ) == 'Spaniel'
def test_get_rose_vars_expansions(tmp_path): """Check that variables are expanded correctly.""" os.environ['XYZ'] = "xyz" (tmp_path / "rose-suite.conf").write_text("[env]\n" "FOO=a\n" "[jinja2:suite.rc]\n" 'BAR="${FOO}b"\n' 'LOCAL_ENV="$XYZ"\n' 'ESCAPED_ENV="\\$HOME"\n' "INT=42\n" "BOOL=True\n" 'LIST=["a", 1, True]\n') rose_vars = get_rose_vars(tmp_path) assert rose_vars['template_variables']['LOCAL_ENV'] == 'xyz' assert rose_vars['template_variables']['BAR'] == 'ab' assert rose_vars['template_variables']['ESCAPED_ENV'] == '$HOME' assert rose_vars['template_variables']['INT'] == 42 assert rose_vars['template_variables']['BOOL'] is True assert rose_vars['template_variables']['LIST'] == ["a", 1, True]
def test_fail_if_options_but_no_rose_suite_conf(opts, tmp_path): """Tests for rose only options being used in a Cylc workflow which is not a rose-suite.conf """ with pytest.raises(NotARoseSuiteException, match='^Cylc-Rose CLI'): get_rose_vars(tmp_path, opts)
def test_warn_if_old_templating_set(rose_config, tmp_path, caplog): """Test using unsupported root-dir config raises error.""" (tmp_path / 'rose-suite.conf').write_text(rose_config) get_rose_vars(srcdir=tmp_path) msg = "is deprecated. Use [template variables]" assert msg in caplog.records[0].message