-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Conditional parameters (HEXA-1687) #396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
08533b3
8462ee3
2494e78
e6fb57c
c0861b5
5190046
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -154,13 +154,62 @@ def test_pipeline_with_int_param(self): | |
| "help": "Param help", | ||
| "required": True, | ||
| "directory": None, | ||
| "disables": None, | ||
| "disableWhen": True, | ||
| } | ||
| ], | ||
| "timeout": None, | ||
| "functional_type": None, | ||
| }, | ||
| ) | ||
|
|
||
| def test_pipeline_with_disables_param(self): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if we have it but I was expecting a test for the scenario when a required parameter is disabled
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll check again and make sure! I think we do but it's always good to double check 😁 Edit: I'm checking and I think we have them in |
||
| """The @parameter decorator's 'disables' list is parsed from the pipeline code.""" | ||
| with tempfile.TemporaryDirectory() as tmpdirname: | ||
| with open(f"{tmpdirname}/pipeline.py", "w") as f: | ||
| f.write( | ||
| "\n".join( | ||
| [ | ||
| "from openhexa.sdk.pipelines import pipeline, parameter", | ||
| "", | ||
| "@parameter('run_report_only', type=bool, default=False, disables=['data_input'])", | ||
| "@parameter('data_input', type=str)", | ||
| "@pipeline('Test pipeline')", | ||
| "def test_pipeline():", | ||
| " pass", | ||
| "", | ||
| ] | ||
| ) | ||
| ) | ||
| pipeline = get_pipeline(tmpdirname) | ||
| params = {p["code"]: p for p in pipeline.to_dict()["parameters"]} | ||
| self.assertEqual(params["run_report_only"]["disables"], ["data_input"]) | ||
| self.assertEqual(params["run_report_only"]["disableWhen"], True) | ||
| self.assertIsNone(params["data_input"]["disables"]) | ||
|
|
||
| def test_pipeline_with_disable_when_false(self): | ||
| """The @parameter decorator's 'disable_when' is parsed from the pipeline code.""" | ||
| with tempfile.TemporaryDirectory() as tmpdirname: | ||
| with open(f"{tmpdirname}/pipeline.py", "w") as f: | ||
| f.write( | ||
| "\n".join( | ||
| [ | ||
| "from openhexa.sdk.pipelines import pipeline, parameter", | ||
| "", | ||
| "@parameter('enable_advanced', type=bool, default=False, disables=['tuning'], disable_when=False)", | ||
| "@parameter('tuning', type=str)", | ||
| "@pipeline('Test pipeline')", | ||
| "def test_pipeline():", | ||
| " pass", | ||
| "", | ||
| ] | ||
| ) | ||
| ) | ||
| pipeline = get_pipeline(tmpdirname) | ||
| params = {p["code"]: p for p in pipeline.to_dict()["parameters"]} | ||
| self.assertEqual(params["enable_advanced"]["disables"], ["tuning"]) | ||
| self.assertEqual(params["enable_advanced"]["disableWhen"], False) | ||
|
|
||
| def test_pipeline_with_multiple_param(self): | ||
| """The file contains a @pipeline decorator and a @parameter decorator with multiple=True.""" | ||
| with tempfile.TemporaryDirectory() as tmpdirname: | ||
|
|
@@ -198,6 +247,8 @@ def test_pipeline_with_multiple_param(self): | |
| "help": "Param help", | ||
| "required": True, | ||
| "directory": None, | ||
| "disables": None, | ||
| "disableWhen": True, | ||
| } | ||
| ], | ||
| "timeout": None, | ||
|
|
@@ -243,6 +294,8 @@ def test_pipeline_with_dataset(self): | |
| "help": "Dataset", | ||
| "required": False, | ||
| "directory": None, | ||
| "disables": None, | ||
| "disableWhen": True, | ||
| } | ||
| ], | ||
| "timeout": None, | ||
|
|
@@ -287,6 +340,8 @@ def test_pipeline_with_choices(self): | |
| "help": "Param help", | ||
| "required": True, | ||
| "directory": None, | ||
| "disables": None, | ||
| "disableWhen": True, | ||
| } | ||
| ], | ||
| "timeout": None, | ||
|
|
@@ -359,6 +414,8 @@ def test_pipeline_with_bool(self): | |
| "help": "Param help", | ||
| "required": True, | ||
| "directory": None, | ||
| "disables": None, | ||
| "disableWhen": True, | ||
| } | ||
| ], | ||
| "timeout": None, | ||
|
|
@@ -404,6 +461,8 @@ def test_pipeline_with_multiple_parameters(self): | |
| "help": "Param help", | ||
| "required": True, | ||
| "directory": None, | ||
| "disables": None, | ||
| "disableWhen": True, | ||
| }, | ||
| { | ||
| "choices": ["a", "b"], | ||
|
|
@@ -417,6 +476,8 @@ def test_pipeline_with_multiple_parameters(self): | |
| "help": "Param help 2", | ||
| "required": True, | ||
| "directory": None, | ||
| "disables": None, | ||
| "disableWhen": True, | ||
| }, | ||
| ], | ||
| "timeout": None, | ||
|
|
@@ -484,6 +545,8 @@ def test_pipeline_with_connection_parameter_for_dhis2(self): | |
| "help": None, | ||
| "required": True, | ||
| "directory": None, | ||
| "disables": None, | ||
| "disableWhen": True, | ||
| }, | ||
| { | ||
| "code": "data_element_ids", | ||
|
|
@@ -497,6 +560,8 @@ def test_pipeline_with_connection_parameter_for_dhis2(self): | |
| "help": None, | ||
| "required": True, | ||
| "directory": None, | ||
| "disables": None, | ||
| "disableWhen": True, | ||
| }, | ||
| ], | ||
| "timeout": None, | ||
|
|
@@ -546,6 +611,8 @@ def test_pipeline_with_connection_parameter_for_iaso(self): | |
| "help": None, | ||
| "required": True, | ||
| "directory": None, | ||
| "disables": None, | ||
| "disableWhen": True, | ||
| }, | ||
| { | ||
| "code": "org_units", | ||
|
|
@@ -559,6 +626,8 @@ def test_pipeline_with_connection_parameter_for_iaso(self): | |
| "help": None, | ||
| "required": True, | ||
| "directory": None, | ||
| "disables": None, | ||
| "disableWhen": True, | ||
| }, | ||
| { | ||
| "code": "projects", | ||
|
|
@@ -572,6 +641,8 @@ def test_pipeline_with_connection_parameter_for_iaso(self): | |
| "help": None, | ||
| "required": True, | ||
| "directory": None, | ||
| "disables": None, | ||
| "disableWhen": True, | ||
| }, | ||
| { | ||
| "code": "forms", | ||
|
|
@@ -585,6 +656,8 @@ def test_pipeline_with_connection_parameter_for_iaso(self): | |
| "help": None, | ||
| "required": True, | ||
| "directory": None, | ||
| "disables": None, | ||
| "disableWhen": True, | ||
| }, | ||
| ], | ||
| "timeout": None, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor! I was thinking if we matched both the attribute and this serialisation key to snake_case. for the consistency. I don't where I got this but I see mostly people use Camelcase in Javascript 😂. no strong opinion
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh yeah, this is quite weird being code in python 😂 this is actually because the
.dict()is used as values to be sent to our graphQL endpoint, so it is expecting camelCase. Usingsnake_case(which would be the normal thing in python) breaks it.I learned this the hard way, broke it in the other task I did about the dynamic params and @bramj fixed it here: #393