From 9caa2ec97728da594b1af2bca1dd41d3e6d62cba Mon Sep 17 00:00:00 2001 From: ValentinaHutter Date: Fri, 29 Sep 2023 11:07:58 +0200 Subject: [PATCH] add test --- tests/data/graphs/fit_curve.json | 116 +++++++++++++++++++++++++++++++ tests/test_pg_parser.py | 14 ++++ 2 files changed, 130 insertions(+) create mode 100644 tests/data/graphs/fit_curve.json diff --git a/tests/data/graphs/fit_curve.json b/tests/data/graphs/fit_curve.json new file mode 100644 index 0000000..64d5772 --- /dev/null +++ b/tests/data/graphs/fit_curve.json @@ -0,0 +1,116 @@ +{ + "loadcollection1":{ + "process_id":"load_collection", + "arguments":{ + "bands":[ + "B02", + "B03" + ], + "id":"boa_sentinel_2", + "spatial_extent":{ + "west":11.389, + "east":11.39, + "south":46.349, + "north":46.35 + }, + "temporal_extent":[ + "2016-09-01", + "2018-09-01" + ] + } + }, + "apply1":{ + "process_id":"apply", + "arguments":{ + "data":{ + "from_node":"loadcollection1" + }, + "process":{ + "process_graph":{ + "clip1":{ + "process_id":"clip", + "arguments":{ + "max":5000, + "min":0, + "x":{ + "from_parameter":"x" + } + }, + "result":true + } + } + } + } + }, + "fitcurve1":{ + "process_id":"fit_curve", + "arguments":{ + "data":{ + "from_node":"apply1" + }, + "dimension":"time", + "function":{ + "process_graph":{ + "arrayelement1":{ + "process_id":"array_element", + "arguments":{ + "data":{ + "from_parameter":"parameters" + }, + "index":0 + } + }, + "arrayelement2":{ + "process_id":"array_element", + "arguments":{ + "data":{ + "from_parameter":"parameters" + }, + "index":1 + } + }, + "multiply1":{ + "process_id":"multiply", + "arguments":{ + "x":{ + "from_node":"arrayelement2" + }, + "y":{ + "from_parameter":"x" + } + } + }, + "add1":{ + "process_id":"add", + "arguments":{ + "x":{ + "from_node":"arrayelement1" + }, + "y":{ + "from_node":"multiply1" + } + }, + "result":true + } + } + }, + "parameters":[ + 1, + 2 + ] + } + }, + "saveresult1":{ + "process_id":"save_result", + "arguments":{ + "data":{ + "from_node":"fitcurve1" + }, + "format":"NetCDF", + "options":{ + + } + }, + "result":true + } + } diff --git a/tests/test_pg_parser.py b/tests/test_pg_parser.py index 1193559..1e7ef77 100644 --- a/tests/test_pg_parser.py +++ b/tests/test_pg_parser.py @@ -32,6 +32,20 @@ def test_full_parse(process_graph_path): parsed_graph_from_file.plot() +def test_fit_curve_parse(): + flat_process_graph = json.load(open(TEST_DATA_DIR / "graphs" / "fit_curve.json")) + parsed_graph = OpenEOProcessGraph.from_json(json.dumps(flat_process_graph)) + assert isinstance(parsed_graph, OpenEOProcessGraph) + + # Dry-run to_callable after parsing + mock_process_registry = { + process_id: Process({}, lambda process_id: logger.debug(process_id), "predefined") + for process_id in parsed_graph.required_processes + } + callable = parsed_graph.to_callable(mock_process_registry) + + parsed_graph.plot() + def test_from_json_constructor(): flat_process_graph = json.load(open(TEST_DATA_DIR / "graphs" / "fit_rf_pg_0.json"))