| 1 |
# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE. |
| 2 |
# Copyright (C) NIWA & British Crown (Met Office) & Contributors. |
| 3 |
# |
| 4 |
# This program is free software: you can redistribute it and/or modify |
| 5 |
# it under the terms of the GNU General Public License as published by |
| 6 |
# the Free Software Foundation, either version 3 of the License, or |
| 7 |
# (at your option) any later version. |
| 8 |
# |
| 9 |
# This program is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License |
| 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
|
| 17 |
import importlib |
| 18 |
|
| 19 |
from pathlib import Path |
| 20 |
|
| 21 |
|
| 22 |
# Fake up the module. |
| 23 |
path = Path(__file__).parent.parent.parent / 'etc/bin/syntax_generator.py' |
| 24 |
loader = importlib.machinery.SourceFileLoader( |
| 25 |
'syntaxgenerator', str(path) |
| 26 |
) |
| 27 |
syntax = loader.load_module() |
| 28 |
|
| 29 |
|
| 30 |
def test_get_keywords_from_workflow_cfg(): |
| 31 |
"""It gets a list of config items. |
| 32 |
|
| 33 |
Not a thorough check, but ensure type is sensible and some unlikely-to |
| 34 |
change items are present. |
| 35 |
""" |
| 36 |
result = syntax.get_keywords_from_workflow_cfg() |
| 37 |
assert isinstance(result, list) |
| 38 |
assert 'meta' in result |
| 39 |
assert 'scheduling' in result |
| 40 |
assert 'cycle point format' in result |
| 41 |
|
| 42 |
|
| 43 |
def test_update_cylc_lang_new_section(tmp_path): |
| 44 |
test_file = tmp_path / 'testfile' |
| 45 |
test_file.write_text(( |
| 46 |
"<!--TAG_FOR_AUTO_UPDATE-->\n" |
| 47 |
"some stuff" |
| 48 |
"<!--END_TAG_FOR_AUTO_UPDATE-->" |
| 49 |
)) |
| 50 |
syntax.update_cylc_lang( |
| 51 |
['gamma', 'nu'], test_file, '#kword#{word}#kword# - ' |
| 52 |
) |
| 53 |
assert test_file.read_text() == ( |
| 54 |
"<!--TAG_FOR_AUTO_UPDATE-->\n#kword#gamma#kword#" |
| 55 |
" - #kword#nu#kword# - " |
| 56 |
"<!--END_TAG_FOR_AUTO_UPDATE-->" |
| 57 |
) |