Skip to content

Commit

Permalink
tested install
Browse files Browse the repository at this point in the history
  • Loading branch information
wxtim committed Dec 11, 2023
1 parent 9098006 commit 1ebd3b6
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 7 deletions.
24 changes: 18 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from types import SimpleNamespace
from uuid import uuid4

from cylc.flow import __version__ as CYLC_VERSION
from cylc.flow.option_parsers import Options
from cylc.flow.pathutil import get_workflow_run_dir
from cylc.flow.scripts.install import get_option_parser as install_gop
from cylc.flow.scripts.install import install_cli as cylc_install
from cylc.flow.scripts.reinstall import get_option_parser as reinstall_gop
Expand All @@ -27,6 +29,11 @@
import pytest


@pytest.fixture
def generate_workflow_name():
return 'cylc-rose-test-' + str(uuid4())[:8]


@pytest.fixture(scope='module')
def mod_capsys(request):
from _pytest.capture import SysCapture
Expand Down Expand Up @@ -108,7 +115,7 @@ def _inner(srcpath, args=None):
return _inner


def _cylc_install_cli(capsys, caplog):
def _cylc_install_cli(capsys, caplog, generate_workflow_name):
"""Access the install CLI"""
def _inner(srcpath, args=None):
"""Install a workflow.
Expand All @@ -119,16 +126,21 @@ def _inner(srcpath, args=None):
"""
options = Options(install_gop(), args)()
output = SimpleNamespace()
if not options.workflow_name:
options.workflow_name = generate_workflow_name
if not args or args and not args.get('no_run_name', ''):
options.no_run_name = True

try:
cylc_install(options, str(srcpath))
output.name, output.id = 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()
output.run_dir = get_workflow_run_dir(output.id)
return output
return _inner

Expand Down Expand Up @@ -159,13 +171,13 @@ def _inner(workflow_id, opts=None):


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


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


@pytest.fixture
Expand Down
49 changes: 48 additions & 1 deletion tests/functional/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_basic(tmp_path):
)


def test_CYLC_SYMLINKS(monkeypatch, tmp_path, cylc_validate_cli):
def test_CYLC_SYMLINKS_validate(monkeypatch, tmp_path, cylc_validate_cli):
"""We reload the global config after exporting env variables."""
# Setup global config:
global_conf = """#!jinja2
Expand Down Expand Up @@ -70,3 +70,50 @@ def test_CYLC_SYMLINKS(monkeypatch, tmp_path, cylc_validate_cli):
# CYLC_SYMLINKS == None the first time the global.cylc
# is loaded and "Foo" the second time.
assert output.logging == 'None\n"Foo"'


def test_CYLC_SYMLINKS_install(monkeypatch, tmp_path, cylc_install_cli):
"""We reload the global config after exporting env variables."""
# 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'
)
glbl_conf_path = tmp_path / 'conf'
glbl_conf_path.mkdir()
(glbl_conf_path / 'global.cylc').write_text(global_conf)
monkeypatch.setenv('CYLC_CONF_PATH', glbl_conf_path)

# Setup workflow config:
(tmp_path / 'rose-suite.conf').write_text(
'[env]\nCYLC_SYMLINKS=foo\n')
(tmp_path / 'flow.cylc').write_text("""
[scheduling]
initial cycle point = now
[[graph]]
R1 = x
[runtime]
[[x]]
""")

# Install the config:
output = 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:
expected_msg = (
f'Symlink created: {output.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 1ebd3b6

Please sign in to comment.