Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver-sanders committed Feb 20, 2024
1 parent 35e98e6 commit 7a648a4
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 41 deletions.
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,14 @@ async def _inner(srcpath, workflow_name=None, opts=None):
"""
nonlocal capsys, caplog, test_dir
if not workflow_name:
workflow_name = str(test_dir.relative_to(CYLC_RUN_DIR))
workflow_name = str((test_dir / str(uuid4())[:4]).relative_to(CYLC_RUN_DIR))
options = Options(
install_gop(), opts or {}
)(workflow_name=workflow_name)
output = SimpleNamespace()
if not options.workflow_name:
options.workflow_name = workflow_name
if not args or not args.get('no_run_name', ''):
if not opts or not opts.get('no_run_name', ''):
options.no_run_name = True

try:
Expand All @@ -210,7 +210,6 @@ async def _inner(srcpath, workflow_name=None, opts=None):
output.exc = exc
output.logging = '\n'.join([i.message for i in caplog.records])
output.out, output.err = capsys.readouterr()
output.run_dir = get_workflow_run_dir(output.id)
return output
return _inner

Expand Down Expand Up @@ -241,6 +240,7 @@ async def _inner(workflow_id=None, opts=None):
output.ret = 0
output.exc = ''
except Exception as exc:
# raise
output.ret = 1
output.exc = exc
output.logging = '\n'.join([i.message for i in caplog.records])
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_ROSE_ORIG_HOST.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ async def test_cylc_validate_rundir(
):
"""Sanity check that workflow validates:
"""
flowpath = fixture_install_flow['flowpath'] / 'runN'
flowpath = fixture_install_flow['flowpath']
result = await mod_cylc_validate_cli(flowpath)
assert 'ROSE_ORIG_HOST (env) is:' in result.logging

Expand Down
29 changes: 17 additions & 12 deletions tests/functional/test_reinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,8 @@ async def fixture_reinstall_flow(
"""
monkeymodule.delenv('ROSE_SUITE_OPT_CONF_KEYS', raising=False)
result = await mod_cylc_reinstall_cli(
f'{fixture_install_flow["fixture_provide_flow"]["test_flow_name"]}'
'/run1',
{
'opt_conf_keys': ['d']
}
fixture_install_flow['result'].id,
{'opt_conf_keys': ['d']},
)
yield {
'fixture_install_flow': fixture_install_flow,
Expand Down Expand Up @@ -202,7 +199,7 @@ def test_cylc_reinstall_files(fixture_reinstall_flow, file_, expect):

@pytest.fixture(scope='module')
async def fixture_reinstall_flow2(
fixture_provide_flow, monkeymodule, mod_cylc_reinstall_cli
fixture_install_flow, monkeymodule, mod_cylc_reinstall_cli
):
"""Run ``cylc reinstall``.
Expand All @@ -217,14 +214,17 @@ async def fixture_reinstall_flow2(
``fixture_install_flow['result'].stderr`` may help with debugging.
"""
monkeymodule.delenv('ROSE_SUITE_OPT_CONF_KEYS', raising=False)
(fixture_provide_flow['srcpath'] / 'rose-suite.conf').write_text(
'opts=z\n'
)
(
fixture_install_flow
['fixture_provide_flow']
['srcpath']
/ 'rose-suite.conf'
).write_text('opts=z\n')
result = await mod_cylc_reinstall_cli(
f'{fixture_provide_flow["test_flow_name"]}/run1'
fixture_install_flow['result'].id,
)
yield {
'fixture_provide_flow': fixture_provide_flow,
'fixture_install_flow': fixture_install_flow,
'result': result
}

Expand Down Expand Up @@ -254,7 +254,12 @@ def test_cylc_reinstall_run2(fixture_reinstall_flow2):
]
)
def test_cylc_reinstall_files2(fixture_reinstall_flow2, file_, expect):
fpath = fixture_reinstall_flow2['fixture_provide_flow']['flowpath']
fpath = (
fixture_reinstall_flow2
['fixture_install_flow']
['fixture_provide_flow']
['flowpath']
)
assert (fpath / file_).read_text() == expect


Expand Down
1 change: 0 additions & 1 deletion tests/functional/test_reinstall_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ async def fixture_reinstall_flow(
result = await mod_cylc_reinstall_cli(
(
fixture_install_flow['fixture_provide_flow']['test_flow_name']
+ '/run1'
),
{
'opt_conf_keys': ['baz'],
Expand Down
15 changes: 8 additions & 7 deletions tests/functional/test_rose_fileinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import pytest

from cylc.flow.pathutil import get_workflow_run_dir


# @pytest.fixture(scope='module')
@pytest.fixture
Expand Down Expand Up @@ -50,20 +52,19 @@ def workflow_source_dir(tmp_path):
async def installed_workflow(
workflow_source_dir,
cylc_install_cli,
test_dir,
run_dir,
):
srcpath, datapath = workflow_source_dir
result = await cylc_install_cli(srcpath)
assert result.ret == 0 # ensure the workflow installed successfully
workflow_id = test_dir.relative_to(run_dir)
yield datapath, workflow_id, result, test_dir
workflow_id = result.id
run_dir = Path(get_workflow_run_dir(workflow_id))
yield datapath, workflow_id, result, run_dir


async def test_rose_fileinstall_subfolders(installed_workflow, test_dir):
async def test_rose_fileinstall_subfolders(installed_workflow):
"""It should perform file installation creating directories as needed."""
datapath, _, _, destpath = installed_workflow
assert (destpath / 'runN/lib/python/lion.py').read_text() == (
assert (destpath / 'lib/python/lion.py').read_text() == (
(datapath / 'lion.py').read_text()
)

Expand All @@ -74,7 +75,7 @@ def test_rose_fileinstall_concatenation(installed_workflow):
Note source contains wildcard.
"""
datapath, _, _, destpath = installed_workflow
assert (destpath / 'runN/data').read_text() == (
assert (destpath / 'data').read_text() == (
(datapath / 'randoms1.data').read_text()
+ (datapath / 'randoms3.data').read_text()
)
Expand Down
38 changes: 21 additions & 17 deletions tests/functional/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
"""Unit tests for utilities."""

from pathlib import Path
from textwrap import dedent

from cylc.rose.entry_points import copy_config_file

from cylc.flow.pathutil import get_workflow_run_dir


def test_basic(tmp_path):
# Create files
Expand All @@ -38,7 +41,7 @@ def test_basic(tmp_path):
)


def test_global_config_environment_validate(
async def test_global_config_environment_validate(
monkeypatch, tmp_path, cylc_validate_cli
):
"""It should reload the global config after exporting env variables.
Expand Down Expand Up @@ -69,34 +72,34 @@ def test_global_config_environment_validate(
""")

# Validate the config:
output = cylc_validate_cli(tmp_path)
output = await cylc_validate_cli(tmp_path)
assert output.ret == 0

# CYLC_SYMLINKS == None the first time the global.cylc
# is loaded and "Foo" the second time.
assert output.logging.split('\n')[-1] == '"Foo"'


def test_global_config_environment_validate2(
async def test_global_config_environment_validate2(
monkeypatch, tmp_path, cylc_install_cli
):
"""It should reload the global config after exporting env variables.
See: https://github.com/cylc/cylc-rose/issues/237
"""
# Setup global config:
global_conf = (
'#!jinja2\n'
'[install]\n'
' [[symlink dirs]]\n'
' [[[localhost]]]\n'
'{% set cylc_symlinks = environ.get(\'CYLC_SYMLINKS\', None) %}\n'
'{% if cylc_symlinks == "foo" %}\n'
f'log = {str(tmp_path)}/foo\n'
'{% else %}\n'
f'log = {str(tmp_path)}/bar\n'
'{% endif %}\n'
)
global_conf = dedent(f'''
#!jinja2
[install]
[[symlink dirs]]
[[[localhost]]]
{{% set cylc_symlinks = environ.get(\'CYLC_SYMLINKS\', None) %}}
{{% if cylc_symlinks == "foo" %}}
log = {str(tmp_path)}/foo
{{% else %}}
log = {str(tmp_path)}/bar
{{% endif %}}
''').strip()
glbl_conf_path = tmp_path / 'conf'
glbl_conf_path.mkdir()
(glbl_conf_path / 'global.cylc').write_text(global_conf)
Expand All @@ -115,15 +118,16 @@ def test_global_config_environment_validate2(
""")

# Install the config:
output = cylc_install_cli(tmp_path)
output = await cylc_install_cli(tmp_path)
import sys
for i in output.logging.split('\n'):
print(i, file=sys.stderr)
assert output.ret == 0

# Assert symlink created back to test_path/foo:
run_dir = get_workflow_run_dir(output.id)
expected_msg = (
f'Symlink created: {output.run_dir}/log -> '
f'Symlink created: {run_dir}/log -> '
f'{tmp_path}/foo/cylc-run/{output.id}/log'
)
assert expected_msg in output.logging.split('\n')[0]

0 comments on commit 7a648a4

Please sign in to comment.