Skip to content

Commit

Permalink
added functional tests to check dealing with optional configs set by …
Browse files Browse the repository at this point in the history
…ENV or rose-suite.conf:opts=

tests for rose fileinstall

added skips for tests of rose.cylc if rose-cylc not installed
  • Loading branch information
wxtim committed Nov 18, 2020
1 parent 3f0e0f8 commit 36a20a0
Show file tree
Hide file tree
Showing 20 changed files with 341 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test_functional.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
- name: Install
run: |
pip install git+https://github.com/metomi/rose@master
pip install --no-deps git+https://github.com/wxtim/cylc-rose.git@c49a2cbbf7f86de924a5591d81b8089aa3b1f001
pip install ."[all]"
mkdir "$HOME/cylc-run"
Expand Down
12 changes: 10 additions & 2 deletions cylc/flow/parsec/fileparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
import sys
import re

import pkg_resources
from ast import literal_eval
from copy import copy
from pathlib import Path

from cylc.flow import LOG
from cylc.flow.parsec.exceptions import ParsecError, FileParseError
from cylc.flow.parsec.rose_utils import get_rose_vars
from cylc.flow.parsec.OrderedDict import OrderedDictWithDefaults
from cylc.flow.parsec.include import inline
from cylc.flow.parsec.util import itemstr
Expand Down Expand Up @@ -234,7 +234,15 @@ def read_and_proc(fpath, template_vars=None, viewcfg=None, asedit=False):
template_vars = {}

# Load Rose Vars, if a ``rose-suite.conf`` file is present.
rose_vars = get_rose_vars(Path(fpath).parent)
rose_vars = {
'env': None,
'empy:suite.rc': None,
'jinja2:suite.rc': None
}
for entry_point in pkg_resources.iter_entry_points(
'cylc.configure'
):
rose_vars = entry_point.resolve()(Path(fpath).parent)

if viewcfg:
if not viewcfg['empy']:
Expand Down
1 change: 1 addition & 0 deletions cylc/flow/parsec/rose_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def rose_fileinstall(dir_=None, opts=None, dest_root=None):
dir_(string or pathlib.Path):
Search for a ``rose-suite.conf`` file in this location.
dest_root (string or pathlib.Path)
"""
if not rose_config_exists(dir_):
return False
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ cylc.command =
get-suite-version = cylc.flow.scripts.get_suite_version:main
graph = cylc.flow.scripts.graph:main
hold = cylc.flow.scripts.hold:main
install = cylc.flow.scripts.install:main
jobs-kill = cylc.flow.scripts.jobs_kill:main
jobs-poll = cylc.flow.scripts.jobs_poll:main
jobs-submit = cylc.flow.scripts.jobs_submit:main
Expand Down
4 changes: 4 additions & 0 deletions tests/functional/rose-conf/00-jinja2.t
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
# Test jinja2 from rose-suite.conf file is processed into a suite.
. "$(dirname "$0")/test_header"
#-------------------------------------------------------------------------------
python -c "import cylc.rose" > /dev/null 2>&1 ||
skip_all "cylc.rose not installed in environment."

set_test_number 1

install_suite "${TEST_NAME_BASE}" "${TEST_NAME_BASE}"

cylc view -p --stdout "${SUITE_NAME}" > processed.conf.test
Expand Down
3 changes: 3 additions & 0 deletions tests/functional/rose-conf/01-empy.t
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
# Test jinja2 from rose-suite.conf file is processed into a suite.
. "$(dirname "$0")/test_header"
#-------------------------------------------------------------------------------
python -c "import cylc.rose" > /dev/null 2>&1 ||
skip_all "cylc.rose not installed in environment."

set_test_number 1
install_suite "${TEST_NAME_BASE}" "${TEST_NAME_BASE}"

Expand Down
3 changes: 3 additions & 0 deletions tests/functional/rose-conf/02-env.t
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
# Test jinja2 from rose-suite.conf file is processed into a suite.
. "$(dirname "$0")/test_header"
#-------------------------------------------------------------------------------
python -c "import cylc.rose" > /dev/null 2>&1 ||
skip_all "cylc.rose not installed in environment."

set_test_number 1
install_suite "${TEST_NAME_BASE}" "${TEST_NAME_BASE}"

Expand Down
34 changes: 34 additions & 0 deletions tests/functional/rose-conf/04-opts-set-from-env.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash
# THIS FILE IS PART OF THE CYLC SUITE ENGINE.
# Copyright (C) NIWA & British Crown (Met Office) & Contributors.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#-------------------------------------------------------------------------------
# Test jinja2 from rose-suite.conf file is processed into a suite.
. "$(dirname "$0")/test_header"
#-------------------------------------------------------------------------------
python -c "import cylc.rose" > /dev/null 2>&1 ||
skip_all "cylc.rose not installed in environment."

set_test_number 1
install_suite "${TEST_NAME_BASE}" "${TEST_NAME_BASE}"

export ROSE_SUITE_OPT_CONF_KEYS=Gaelige

cylc view -p --stdout "${SUITE_NAME}" > processed.conf.test

cmp_ok processed.conf.test processed.conf.control

purge
exit
36 changes: 36 additions & 0 deletions tests/functional/rose-conf/04-opts-set-from-env/flow.cylc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!jinja2
[meta]
title = "Add jinja2 vars from a rose-suite.conf"
description = """
Natively, in Cylc!
"""

[scheduling]
initial cycle point = {{ICP}}
final cycle point = {{FCP}}
cycling mode = integer
[[graph]]
{% for member in MEMBERS %}
P1 = {{TASK1}} => {{TASK2}}_{{member}} => {{TASK3}}
{% endfor %}
{% for key, value in SAMUELJOHNSON.items() %}
P1 = {{TASK3}} => {{value}}_auf_deutsch_ist_{{key}} => fin
{% endfor %}

[runtime]
[[root]]
script = echo "This task is ${CYLC_TASK_ID}"

[[{{ TASK1 }}]]

{% for member in MEMBERS %}
[[{{ TASK2 }}_{{member}}]]
{% endfor %}

[[{{ TASK3 }}]]

{% for key, value in SAMUELJOHNSON.items() %}
[[{{value}}_auf_deutsch_ist_{{key}}]]
{% endfor %}

[[fin]]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[jinja2:suite.rc]
ICP=1
FCP=1
TASK1="mynd"
TASK2="bwyta"
TASK3="prynu"
MEMBERS=["control", "un", "dau", "tri"]
SAMUELJOHNSON={"ein": 1, "zwei": 2, "drei": 3}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[jinja2:suite.rc]
ICP=1
FCP=1
TASK1="cuir" # to put
TASK2="tog" # to lift
TASK3="gabh" # to take
MEMBERS=["control", "aon", "dhà", "trì"]
SAMUELJOHNSON={"ein": 1, "zwei": 2, "drei": 3}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[meta]
title = "Add jinja2 vars from a rose-suite.conf"
description = """
Natively, in Cylc!
"""
[scheduling]
initial cycle point = 1
final cycle point = 1
cycling mode = integer
[[graph]]
P1 = cuir => tog_control => gabh
P1 = cuir => tog_aon => gabh
P1 = cuir => tog_dhà => gabh
P1 = cuir => tog_trì => gabh
P1 = gabh => 1_auf_deutsch_ist_ein => fin
P1 = gabh => 2_auf_deutsch_ist_zwei => fin
P1 = gabh => 3_auf_deutsch_ist_drei => fin
[runtime]
[[root]]
script = echo "This task is ${CYLC_TASK_ID}"
[[cuir]]
[[tog_control]]
[[tog_aon]]
[[tog_dhà]]
[[tog_trì]]
[[gabh]]
[[1_auf_deutsch_ist_ein]]
[[2_auf_deutsch_ist_zwei]]
[[3_auf_deutsch_ist_drei]]
[[fin]]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[jinja2:suite.rc]
ICP=1
FCP=1
TASK1="respond"
TASK2="plunge"
TASK3="allow"
MEMBERS=["control", "yan", "tan", "tethera"]
SAMUELJOHNSON={"ein": 1, "zwei": 2, "drei": 3}
34 changes: 34 additions & 0 deletions tests/functional/rose-conf/05-opts-set-from-rose-suite.conf.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash
# THIS FILE IS PART OF THE CYLC SUITE ENGINE.
# Copyright (C) NIWA & British Crown (Met Office) & Contributors.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#-------------------------------------------------------------------------------
# Test jinja2 from rose-suite.conf file is processed into a suite.
. "$(dirname "$0")/test_header"
#-------------------------------------------------------------------------------
python -c "import cylc.rose" > /dev/null 2>&1 ||
skip_all "cylc.rose not installed in environment."

set_test_number 1
install_suite "${TEST_NAME_BASE}" "${TEST_NAME_BASE}"

export ROSE_SUITE_OPT_CONF_KEYS=""

cylc view -p --stdout "${SUITE_NAME}" > processed.conf.test

cmp_ok processed.conf.test processed.conf.control

purge
exit
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!jinja2
[meta]
title = "Add jinja2 vars from a rose-suite.conf"
description = """
Natively, in Cylc!
"""

[scheduling]
initial cycle point = {{ICP}}
final cycle point = {{FCP}}
cycling mode = integer
[[graph]]
{% for member in MEMBERS %}
P1 = {{TASK1}} => {{TASK2}}_{{member}} => {{TASK3}}
{% endfor %}
{% for key, value in SAMUELJOHNSON.items() %}
P1 = {{TASK3}} => {{value}}_auf_deutsch_ist_{{key}} => fin
{% endfor %}

[runtime]
[[root]]
script = echo "This task is ${CYLC_TASK_ID}"

[[{{ TASK1 }}]]

{% for member in MEMBERS %}
[[{{ TASK2 }}_{{member}}]]
{% endfor %}

[[{{ TASK3 }}]]

{% for key, value in SAMUELJOHNSON.items() %}
[[{{value}}_auf_deutsch_ist_{{key}}]]
{% endfor %}

[[fin]]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[jinja2:suite.rc]
ICP=1
FCP=1
TASK1="mynd"
TASK2="bwyta"
TASK3="prynu"
MEMBERS=["control", "un", "dau", "tri"]
SAMUELJOHNSON={"ein": 1, "zwei": 2, "drei": 3}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[jinja2:suite.rc]
ICP=1
FCP=1
TASK1="cuir" # to put
TASK2="tog" # to lift
TASK3="gabh" # to take
MEMBERS=["control", "aon", "dhà", "trì"]
SAMUELJOHNSON={"ein": 1, "zwei": 2, "drei": 3}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[meta]
title = "Add jinja2 vars from a rose-suite.conf"
description = """
Natively, in Cylc!
"""
[scheduling]
initial cycle point = 1
final cycle point = 1
cycling mode = integer
[[graph]]
P1 = mynd => bwyta_control => prynu
P1 = mynd => bwyta_un => prynu
P1 = mynd => bwyta_dau => prynu
P1 = mynd => bwyta_tri => prynu
P1 = prynu => 1_auf_deutsch_ist_ein => fin
P1 = prynu => 2_auf_deutsch_ist_zwei => fin
P1 = prynu => 3_auf_deutsch_ist_drei => fin
[runtime]
[[root]]
script = echo "This task is ${CYLC_TASK_ID}"
[[mynd]]
[[bwyta_control]]
[[bwyta_un]]
[[bwyta_dau]]
[[bwyta_tri]]
[[prynu]]
[[1_auf_deutsch_ist_ein]]
[[2_auf_deutsch_ist_zwei]]
[[3_auf_deutsch_ist_drei]]
[[fin]]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
opts=Cymraeg
[jinja2:suite.rc]
ICP=1
FCP=1
TASK1="respond"
TASK2="plunge"
TASK3="allow"
MEMBERS=["control", "yan", "tan", "tethera"]
SAMUELJOHNSON={"ein": 1, "zwei": 2, "drei": 3}
Loading

0 comments on commit 36a20a0

Please sign in to comment.