|
14 | 14 | # You should have received a copy of the GNU General Public License
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16 | 16 |
|
| 17 | +import pytest |
| 18 | + |
17 | 19 | from cylc.flow.config import WorkflowConfig
|
18 | 20 | from cylc.flow.taskdef import generate_graph_parents
|
19 | 21 | from cylc.flow.cycling.iso8601 import ISO8601Point
|
|
22 | 24 | from .test_config import tmp_flow_config
|
23 | 25 |
|
24 | 26 |
|
| 27 | +param = pytest.param |
| 28 | + |
| 29 | + |
25 | 30 | def test_generate_graph_parents_1(tmp_flow_config):
|
26 | 31 | """Test that parents are only generated from valid recurrences."""
|
27 | 32 | id_ = 'pan-galactic'
|
28 | 33 | flow_file = tmp_flow_config(
|
29 | 34 | id_,
|
30 |
| - f""" |
| 35 | + """ |
31 | 36 | [scheduler]
|
32 | 37 | UTC mode = True
|
33 | 38 | [scheduling]
|
@@ -68,7 +73,7 @@ def test_generate_graph_parents_2(tmp_flow_config):
|
68 | 73 | id_ = 'gargle-blaster'
|
69 | 74 | flow_file = tmp_flow_config(
|
70 | 75 | id_,
|
71 |
| - f""" |
| 76 | + """ |
72 | 77 | [scheduling]
|
73 | 78 | cycling mode = integer
|
74 | 79 | [[graph]]
|
@@ -98,3 +103,65 @@ def test_generate_graph_parents_2(tmp_flow_config):
|
98 | 103 | )
|
99 | 104 | ]
|
100 | 105 | ]
|
| 106 | + |
| 107 | + |
| 108 | + |
| 109 | +@pytest.mark.parametrize( |
| 110 | + "task, point, expected", |
| 111 | + [ |
| 112 | + param( |
| 113 | + 'foo', |
| 114 | + IntegerPoint("1"), |
| 115 | + ['0/foo'], |
| 116 | + id='it.gets-prerequisites', |
| 117 | + ), |
| 118 | + param( |
| 119 | + 'multiple_pre', |
| 120 | + IntegerPoint("2"), |
| 121 | + ['2/food', '2/fool', '2/foolhardy', '2/foolish'], |
| 122 | + id='it.gets-multiple-prerequisites', |
| 123 | + ), |
| 124 | + param( |
| 125 | + 'foo', |
| 126 | + IntegerPoint("3"), |
| 127 | + [], |
| 128 | + id='it.only-returns-for-valid-points', |
| 129 | + ), |
| 130 | + param( |
| 131 | + 'bar', |
| 132 | + IntegerPoint("2"), |
| 133 | + [], |
| 134 | + id='it.does-not-return-suicide-triggers', |
| 135 | + ), |
| 136 | + ], |
| 137 | +) |
| 138 | +def test_get_prereqs(tmp_flow_config, task, point, expected): |
| 139 | + """Test that get_prereqs() returns the correct prerequisites |
| 140 | + for a task.""" |
| 141 | + id_ = 'gargle-blaster' |
| 142 | + flow_file = tmp_flow_config( |
| 143 | + id_, |
| 144 | + """ |
| 145 | + [scheduler] |
| 146 | + allow implicit tasks = True |
| 147 | + [scheduling] |
| 148 | + final cycle point = 2 |
| 149 | + cycling mode = integer |
| 150 | + [[graph]] |
| 151 | + P1 = ''' |
| 152 | + foo[-P1] => foo |
| 153 | + bar:fail? => !bar |
| 154 | + food & fool => multiple_pre |
| 155 | + foolish | foolhardy => multiple_pre |
| 156 | + ''' |
| 157 | + """ |
| 158 | + ) |
| 159 | + cfg = WorkflowConfig(workflow=id_, fpath=flow_file, options=None) |
| 160 | + taskdef = cfg.taskdefs[task] |
| 161 | + point = IntegerPoint(point) |
| 162 | + res = sorted([ |
| 163 | + condition.task_proxy |
| 164 | + for pre in taskdef.get_prereqs(point) |
| 165 | + for condition in pre.api_dump().conditions |
| 166 | + ]) |
| 167 | + assert res == expected |
0 commit comments