34
34
custom_process ,
35
35
custom_process_from_process_graph ,
36
36
collect ,
37
+ ENV_DRY_RUN_TRACER ,
37
38
)
38
39
from openeo_driver .testing import (
39
40
TEST_USER ,
@@ -4657,9 +4658,11 @@ def custom_process_registry(backend_implementation) -> ProcessRegistry:
4657
4658
)
4658
4659
def test_synchronous_processing_job_options (api , custom_process_registry , post_data_base , expected_job_options ):
4659
4660
"""Test job options handling in synchronous processing in EvalEnv"""
4660
-
4661
+ actual_job_options = []
4661
4662
def i_spy_with_my_little_eye (args : ProcessArgs , env : EvalEnv ):
4662
- assert env .get ("job_options" ) == expected_job_options
4663
+ nonlocal actual_job_options
4664
+ if not env .get (ENV_DRY_RUN_TRACER ):
4665
+ actual_job_options .append (env .get ("job_options" ))
4663
4666
return args .get ("x" )
4664
4667
4665
4668
custom_process_registry .add_function (i_spy_with_my_little_eye , spec = {"id" : "i_spy_with_my_little_eye" })
@@ -4672,6 +4675,71 @@ def i_spy_with_my_little_eye(args: ProcessArgs, env: EvalEnv):
4672
4675
api .ensure_auth_header ()
4673
4676
res = api .post (path = "/result" , json = post_data )
4674
4677
assert res .assert_status_code (200 ).json == 123
4678
+ assert actual_job_options == [expected_job_options ]
4679
+
4680
+
4681
+ @pytest .mark .parametrize (
4682
+ ["default_job_options" , "given_job_options" , "expected_job_options" ],
4683
+ [
4684
+ (None , None , None ),
4685
+ ({}, {}, {}),
4686
+ ({"cpu" : "yellow" }, {}, {"cpu" : "yellow" }),
4687
+ ({}, {"cpu" : "yellow" }, {"cpu" : "yellow" }),
4688
+ ({"cpu" : "yellow" }, {"cpu" : "blue" }, {"cpu" : "blue" }),
4689
+ (
4690
+ {"memory" : "2GB" , "cpu" : "yellow" },
4691
+ {"memory" : "4GB" , "queue" : "fast" },
4692
+ {"cpu" : "yellow" , "memory" : "4GB" , "queue" : "fast" },
4693
+ ),
4694
+ ],
4695
+ )
4696
+ def test_synchronous_processing_job_options_and_defaults_from_remote_process_definition (
4697
+ api , custom_process_registry , requests_mock , default_job_options , given_job_options , expected_job_options
4698
+ ):
4699
+ process_definition = {
4700
+ "id" : "add3" ,
4701
+ "process_graph" : {
4702
+ "add" : {"process_id" : "add" , "arguments" : {"x" : {"from_parameter" : "x" }, "y" : 3 }, "result" : True }
4703
+ },
4704
+ "parameters" : [
4705
+ {"name" : "x" , "schema" : {"type" : "number" }},
4706
+ ],
4707
+ "returns" : {"schema" : {"type" : "number" }},
4708
+ }
4709
+ if default_job_options is not None :
4710
+ process_definition ["default_synchronous_parameters" ] = default_job_options
4711
+ requests_mock .get ("https://share.test/add3.json" , json = process_definition )
4712
+
4713
+ actual_job_options = []
4714
+
4715
+ def i_spy_with_my_little_eye (args : ProcessArgs , env : EvalEnv ):
4716
+ nonlocal actual_job_options
4717
+ if not env .get (ENV_DRY_RUN_TRACER ):
4718
+ actual_job_options .append (env .get ("job_options" ))
4719
+ return args .get ("x" )
4720
+
4721
+ custom_process_registry .add_function (i_spy_with_my_little_eye , spec = {"id" : "i_spy_with_my_little_eye" })
4722
+ custom_process_registry .add_process (name = "add" , function = lambda args , env : args .get ("x" ) + args .get ("y" ))
4723
+
4724
+ pg = {
4725
+ "ispy" : {"process_id" : "i_spy_with_my_little_eye" , "arguments" : {"x" : 123 }},
4726
+ "add3" : {
4727
+ "process_id" : "add3" ,
4728
+ "namespace" : "https://share.test/add3.json" ,
4729
+ "arguments" : {"x" : {"from_node" : "ispy" }},
4730
+ "result" : True ,
4731
+ },
4732
+ }
4733
+ post_data = {
4734
+ "process" : {"process_graph" : pg },
4735
+ }
4736
+ if given_job_options is not None :
4737
+ post_data ["job_options" ] = given_job_options
4738
+
4739
+ api .ensure_auth_header ()
4740
+ res = api .post (path = "/result" , json = post_data )
4741
+ assert res .assert_status_code (200 ).json == 126
4742
+ assert actual_job_options == [expected_job_options ]
4675
4743
4676
4744
4677
4745
def test_load_collection_property_from_parameter (api , udp_registry ):
0 commit comments