1
+ import importlib .util
2
+ import inspect
1
3
import os
4
+ import sys
2
5
from tempfile import TemporaryDirectory
6
+ import yaml
3
7
4
8
import pytest
5
9
import subprocess_tee
6
10
7
11
from . import _python , obtain_flow_file_paths
8
-
12
+ from metaflow import FlowSpec
9
13
10
14
disabled_test_flows = [
11
15
"aip_flow.py" , # kfp_preceding_component feature has been deprecated.
12
16
]
17
+ sys .path .append ("flows" )
13
18
14
19
15
20
@pytest .mark .parametrize (
@@ -52,6 +57,11 @@ def test_argo_flows(pytestconfig, flow_file_path: str) -> None:
52
57
validation_cmd = f"argo lint { output_path } "
53
58
else :
54
59
validation_cmd = f"argo template lint { output_path } "
60
+ assert_workflow_template_contains_all_parameters (
61
+ flow_base_name = flow_base_name ,
62
+ flow_path = full_path ,
63
+ workflow_template_path = output_path ,
64
+ )
55
65
56
66
assert (
57
67
subprocess_tee .run (
@@ -61,3 +71,31 @@ def test_argo_flows(pytestconfig, flow_file_path: str) -> None:
61
71
).returncode
62
72
== 0
63
73
)
74
+
75
+
76
+ def assert_workflow_template_contains_all_parameters (
77
+ flow_base_name : str , flow_path : str , workflow_template_path : str
78
+ ) -> None :
79
+ spec = importlib .util .spec_from_file_location (flow_base_name , flow_path )
80
+ module = importlib .util .module_from_spec (spec )
81
+ flow = None
82
+ for name in dir (module ):
83
+ var = getattr (module , name )
84
+ if inspect .isclass (var ) and issubclass (var , FlowSpec ) and var != FlowSpec :
85
+ flow = var # Found valid flow class
86
+ assert flow is not None
87
+ flow_parameters = [
88
+ param
89
+ for param in dir (flow )
90
+ if not param .startswith ("_" ) and not callable (getattr (flow , param ))
91
+ ]
92
+ if not flow_parameters :
93
+ # No parameters found. Skipping.
94
+ return
95
+
96
+ with open (workflow_template_path ) as workflow_template_file :
97
+ workflow_output = yaml .safe_load (workflow_template_file )
98
+ output_params = workflow_output ["spec" ]["arguments" ].get ("parameters" )
99
+
100
+ for param in flow_parameters :
101
+ assert param in output_params
0 commit comments