Skip to content

Commit

Permalink
tests: remove defunct cli wrappers (#297)
Browse files Browse the repository at this point in the history
* The install/reinstall commands used to be called via the CLI.
* They were converted to run via the Python API, but some of the CLI
  wrapper legacy remained.
* This strips away the CLI wrapper to make native Python testing
  easier.
  • Loading branch information
oliver-sanders authored Feb 26, 2024
1 parent 7a68b1c commit 4b24c03
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 208 deletions.
52 changes: 15 additions & 37 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ async def _inner(srcpath, args=None):
return _inner


def _cylc_install_cli(capsys, caplog, test_dir):
def _cylc_install_cli(test_dir):
"""Access the install CLI"""
async def _inner(srcpath, workflow_name=None, opts=None):
"""Install a workflow.
Expand All @@ -189,34 +189,23 @@ async def _inner(srcpath, workflow_name=None, opts=None):
Dictionary of arguments for cylc install.
"""
nonlocal capsys, caplog, test_dir
nonlocal test_dir
if not workflow_name:
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 opts or not opts.get('no_run_name', ''):
options.no_run_name = True

try:
output.name, output.id = await cylc_install(options, str(srcpath))
output.ret = 0
output.exc = ''
except Exception as exc:
output.ret = 1
output.exc = exc
output.logging = '\n'.join([i.message for i in caplog.records])
output.out, output.err = capsys.readouterr()
return output
return await cylc_install(options, str(srcpath))
return _inner


def _cylc_reinstall_cli(capsys, caplog, test_dir):
def _cylc_reinstall_cli(test_dir):
"""Access the reinstall CLI"""
async def _inner(workflow_id=None, opts=None):
"""Install a workflow.
Expand All @@ -231,44 +220,33 @@ async def _inner(workflow_id=None, opts=None):
Dictionary of arguments for cylc reinstall.
"""
nonlocal capsys, caplog, test_dir
nonlocal test_dir
if not workflow_id:
workflow_id = str(test_dir.relative_to(CYLC_RUN_DIR))
options = Options(reinstall_gop(), opts or {})()
output = SimpleNamespace()

try:
await cylc_reinstall(options, workflow_id)
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])
output.out, output.err = capsys.readouterr()
return output
options.skip_interactive = True
return await cylc_reinstall(options, workflow_id)
return _inner


@pytest.fixture
def cylc_install_cli(capsys, caplog, test_dir):
return _cylc_install_cli(capsys, caplog, test_dir)
def cylc_install_cli(test_dir):
return _cylc_install_cli(test_dir)


@pytest.fixture(scope='module')
def mod_cylc_install_cli(mod_capsys, mod_caplog):
return _cylc_install_cli(mod_capsys, mod_caplog, mod_test_dir)
def mod_cylc_install_cli(mod_test_dir):
return _cylc_install_cli(mod_test_dir)


@pytest.fixture
def cylc_reinstall_cli(capsys, caplog, test_dir):
return _cylc_reinstall_cli(capsys, caplog, test_dir)
def cylc_reinstall_cli(test_dir):
return _cylc_reinstall_cli(test_dir)


@pytest.fixture(scope='module')
def mod_cylc_reinstall_cli(mod_capsys, mod_caplog, mod_test_dir):
return _cylc_reinstall_cli(mod_capsys, mod_caplog, mod_test_dir)
def mod_cylc_reinstall_cli(mod_test_dir):
return _cylc_reinstall_cli(mod_test_dir)


@pytest.fixture
Expand Down
14 changes: 3 additions & 11 deletions tests/functional/test_ROSE_ORIG_HOST.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ async def fixture_install_flow(
If a test fails then using ``pytest --pdb`` and
``fixture_install_flow['result'].stderr`` may help with debugging.
"""
result = await mod_cylc_install_cli(
await mod_cylc_install_cli(
fixture_provide_flow['srcpath'],
fixture_provide_flow['test_flow_name'],
)
Expand All @@ -126,16 +126,14 @@ async def fixture_install_flow(
install_conf_path.write_text(text)
yield {
**fixture_provide_flow,
'result': result
}


async def test_cylc_validate_srcdir(
fixture_install_flow,
mod_cylc_validate_cli,
):
"""Sanity check that workflow validates:
"""
"""Sanity check that workflow validates."""
srcpath = fixture_install_flow['srcpath']
result = await mod_cylc_validate_cli(srcpath)
search = re.findall(r'ROSE_ORIG_HOST \(.*\) is: (.*)', result.logging)
Expand All @@ -146,13 +144,7 @@ async def test_cylc_validate_rundir(
fixture_install_flow,
mod_cylc_validate_cli,
):
"""Sanity check that workflow validates:
"""
"""Sanity check that workflow validates."""
flowpath = fixture_install_flow['flowpath']
result = await mod_cylc_validate_cli(flowpath)
assert 'ROSE_ORIG_HOST (env) is:' in result.logging


def test_cylc_install_run(fixture_install_flow):
"""install flow works."""
assert fixture_install_flow['result'].ret == 0
114 changes: 43 additions & 71 deletions tests/functional/test_reinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ async def fixture_install_flow(
``fixture_install_flow['result'].stderr`` may help with debugging.
"""
monkeymodule.setenv('ROSE_SUITE_OPT_CONF_KEYS', 'b')
result = await mod_cylc_install_cli(
name, id_ = await mod_cylc_install_cli(
fixture_provide_flow['srcpath'],
fixture_provide_flow['test_flow_name'],
{
Expand All @@ -100,7 +100,8 @@ async def fixture_install_flow(

yield {
'fixture_provide_flow': fixture_provide_flow,
'result': result
'name': name,
'id': id_,
}


Expand All @@ -111,10 +112,6 @@ async def test_cylc_validate(fixture_provide_flow, cylc_validate_cli):
assert (await cylc_validate_cli(str(srcpath))).ret == 0


def test_cylc_install_run(fixture_install_flow):
assert fixture_install_flow['result'].ret == 0


@pytest.mark.parametrize(
'file_, expect',
[
Expand All @@ -140,31 +137,45 @@ def test_cylc_install_files(fixture_install_flow, file_, expect):
assert (fpath / file_).read_text() == expect


@pytest.fixture(scope='module')
async def fixture_reinstall_flow(
fixture_install_flow, monkeymodule, mod_cylc_reinstall_cli
@pytest.mark.parametrize(
'file_, expect',
[
(
'rose-suite.conf', (
'# Config Options \'b c d (cylc-install)\' from CLI appended '
'to options already in `rose-suite.conf`.\n'
'opts=a b c d (cylc-install)\n'
)
),
(
'opt/rose-suite-cylc-install.conf', (
'# This file records CLI Options.\n\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'
)
)
]
)
async def test_cylc_reinstall_files(
fixture_install_flow,
monkeymodule,
mod_cylc_reinstall_cli,
file_,
expect,
):
"""Run ``cylc reinstall``.
By running in a fixture with modular scope we
can run tests on different aspects of its output as separate tests.
If a test fails using ``pytest --pdb then``
``fixture_install_flow['result'].stderr`` may help with debugging.
"""
monkeymodule.delenv('ROSE_SUITE_OPT_CONF_KEYS', raising=False)
result = await mod_cylc_reinstall_cli(
fixture_install_flow['result'].id,
assert await mod_cylc_reinstall_cli(
fixture_install_flow['id'],
{'opt_conf_keys': ['d']},
)
yield {
'fixture_install_flow': fixture_install_flow,
'result': result,
}


def test_cylc_reinstall_run(fixture_reinstall_flow):
assert fixture_reinstall_flow['result'].ret == 0
fpath = fixture_install_flow['fixture_provide_flow']['flowpath']
assert (fpath / file_).read_text() == expect


@pytest.mark.parametrize(
Expand All @@ -174,7 +185,7 @@ def test_cylc_reinstall_run(fixture_reinstall_flow):
'rose-suite.conf', (
'# Config Options \'b c d (cylc-install)\' from CLI appended '
'to options already in `rose-suite.conf`.\n'
'opts=a b c d (cylc-install)\n'
'opts=z b c d (cylc-install)\n'
)
),
(
Expand All @@ -187,19 +198,12 @@ def test_cylc_reinstall_run(fixture_reinstall_flow):
)
]
)
def test_cylc_reinstall_files(fixture_reinstall_flow, file_, expect):
fpath = (
fixture_reinstall_flow
['fixture_install_flow']
['fixture_provide_flow']
['flowpath']
)
assert (fpath / file_).read_text() == expect


@pytest.fixture(scope='module')
async def fixture_reinstall_flow2(
fixture_install_flow, monkeymodule, mod_cylc_reinstall_cli
async def test_cylc_reinstall_files2(
fixture_install_flow,
monkeymodule,
mod_cylc_reinstall_cli,
file_,
expect,
):
"""Run ``cylc reinstall``.
Expand All @@ -220,43 +224,11 @@ async def fixture_reinstall_flow2(
['srcpath']
/ 'rose-suite.conf'
).write_text('opts=z\n')
result = await mod_cylc_reinstall_cli(
fixture_install_flow['result'].id,
assert await mod_cylc_reinstall_cli(
fixture_install_flow['id'],
)
yield {
'fixture_install_flow': fixture_install_flow,
'result': result
}


def test_cylc_reinstall_run2(fixture_reinstall_flow2):
assert fixture_reinstall_flow2['result'].ret == 0


@pytest.mark.parametrize(
'file_, expect',
[
(
'rose-suite.conf', (
'# Config Options \'b c d (cylc-install)\' from CLI appended '
'to options already in `rose-suite.conf`.\n'
'opts=z b c d (cylc-install)\n'
)
),
(
'opt/rose-suite-cylc-install.conf', (
'# This file records CLI Options.\n\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'
)
)
]
)
def test_cylc_reinstall_files2(fixture_reinstall_flow2, file_, expect):
fpath = (
fixture_reinstall_flow2
['fixture_install_flow']
fixture_install_flow
['fixture_provide_flow']
['flowpath']
)
Expand Down
Loading

0 comments on commit 4b24c03

Please sign in to comment.