Debian Codegraph @

tests/unit/parsec/test_fileparse_templating_clash.py

raw
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 pytest
18
19 from cylc.flow.parsec import fileparse
20 from cylc.flow.parsec.fileparse import read_and_proc
21 from cylc.flow.parsec.exceptions import TemplateVarLanguageClash
22
23
24 @pytest.mark.parametrize(
25 'templating, hashbang',
26 [
27 ['other', 'jinja2'],
28 ['jinja2', 'other']
29 ]
30 )
31 def test_read_and_proc_raises_TemplateVarLanguageClash(
32 monkeypatch, tmp_path, templating, hashbang
33 ):
34 """func fails when diffn't templating engines set in hashbang and plugin.
35 """
36
37 def fake_process_plugins(_, __):
38 extra_vars = {
39 'env': {},
40 'template_variables': {'foo': 52},
41 'templating_detected': templating
42 }
43 return extra_vars
44 monkeypatch.setattr(fileparse, 'process_plugins', fake_process_plugins)
45
46 file_ = tmp_path / 'flow.cylc'
47 file_.write_text(
48 f'#!{hashbang}\nfoo'
49 )
50
51 with pytest.raises(TemplateVarLanguageClash) as exc:
52 read_and_proc(file_)
53
54 assert exc.type == TemplateVarLanguageClash