Skip to content

Commit 8dabb69

Browse files
authored
Merge pull request #64 from wxtim/hilary.set-bad-pre
Add test for get_prereqs
2 parents e2a8afc + 714ba85 commit 8dabb69

File tree

2 files changed

+69
-3
lines changed

2 files changed

+69
-3
lines changed

cylc/flow/taskdef.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,6 @@ def get_prereqs(self, point):
334334
if seq in self.dependencies:
335335
# task has prereqs in this sequence
336336
for dep in self.dependencies[seq]:
337-
# TODO?
338337
if dep.suicide:
339338
continue
340339
prereqs.add(dep.get_prerequisite(point, self))

tests/unit/test_taskdef.py

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
# You should have received a copy of the GNU General Public License
1515
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17+
import pytest
18+
1719
from cylc.flow.config import WorkflowConfig
1820
from cylc.flow.taskdef import generate_graph_parents
1921
from cylc.flow.cycling.iso8601 import ISO8601Point
@@ -22,12 +24,15 @@
2224
from .test_config import tmp_flow_config
2325

2426

27+
param = pytest.param
28+
29+
2530
def test_generate_graph_parents_1(tmp_flow_config):
2631
"""Test that parents are only generated from valid recurrences."""
2732
id_ = 'pan-galactic'
2833
flow_file = tmp_flow_config(
2934
id_,
30-
f"""
35+
"""
3136
[scheduler]
3237
UTC mode = True
3338
[scheduling]
@@ -68,7 +73,7 @@ def test_generate_graph_parents_2(tmp_flow_config):
6873
id_ = 'gargle-blaster'
6974
flow_file = tmp_flow_config(
7075
id_,
71-
f"""
76+
"""
7277
[scheduling]
7378
cycling mode = integer
7479
[[graph]]
@@ -98,3 +103,65 @@ def test_generate_graph_parents_2(tmp_flow_config):
98103
)
99104
]
100105
]
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

Comments
 (0)