|
| 1 | +import inspect |
| 2 | + |
1 | 3 | import pytest |
2 | 4 |
|
3 | | -from openeo import DataCube, VectorCube |
4 | | -from openeo.internal.documentation import assert_same_param_docs, extract_params |
| 5 | +from openeo import BatchJob, Connection, DataCube, VectorCube |
| 6 | +from openeo.internal.documentation import ( |
| 7 | + assert_same_param_docs, |
| 8 | + assert_same_return_docs, |
| 9 | + extract_params, |
| 10 | + extract_return, |
| 11 | +) |
5 | 12 | from openeo.rest.mlmodel import MlModel |
6 | 13 | from openeo.rest.stac_resource import StacResource |
7 | 14 |
|
8 | 15 |
|
9 | 16 | def test_extract_params(): |
10 | | - assert ( |
11 | | - extract_params( |
12 | | - """ |
13 | | - The description |
| 17 | + doc = """ |
| 18 | + The description |
| 19 | +
|
| 20 | + and more |
| 21 | +
|
| 22 | + :param a: description of a |
| 23 | + :param b_b : multi-line description |
| 24 | + of b |
| 25 | +
|
| 26 | + That's it! |
| 27 | + """ |
| 28 | + assert extract_params(doc) == { |
| 29 | + "a": "description of a", |
| 30 | + "b_b": "multi-line description\n of b", |
| 31 | + } |
14 | 32 |
|
15 | | - and more |
16 | 33 |
|
17 | | - :param a: description of a |
18 | | - :param b_b : multi-line description |
19 | | - of b |
| 34 | +def test_extract_return(): |
| 35 | + doc = """ |
| 36 | + The description |
20 | 37 |
|
21 | | - That's it! |
22 | | - """ |
23 | | - ) |
24 | | - == { |
25 | | - "a": "description of a", |
26 | | - "b_b": "multi-line description\n of b", |
27 | | - } |
28 | | - ) |
| 38 | + and more |
29 | 39 |
|
| 40 | + :param a: description of a |
30 | 41 |
|
| 42 | + :return: the result |
| 43 | + of the operation |
| 44 | +
|
| 45 | + That's it! |
| 46 | + """ |
| 47 | + |
| 48 | + assert extract_return(doc) == "the result\n of the operation" |
31 | 49 |
|
32 | 50 |
|
33 | 51 | @pytest.mark.parametrize( |
34 | | - ["method_a", "method_b", "only_intersection"], |
| 52 | + ["method_a", "method_b"], |
35 | 53 | [ |
| 54 | + # Connection vs DataCube |
| 55 | + (Connection.download, DataCube.download), |
| 56 | + (Connection.create_job, DataCube.create_job), |
36 | 57 | # Compare DataCube methods internally |
37 | | - (DataCube.download, DataCube.create_job, True), |
38 | | - (DataCube.download, DataCube.execute_batch, True), |
39 | | - (DataCube.create_job, DataCube.execute_batch, True), |
| 58 | + (DataCube.download, DataCube.create_job), |
| 59 | + (DataCube.download, DataCube.execute_batch), |
| 60 | + (DataCube.create_job, DataCube.execute_batch), |
| 61 | + # DataCube vs BatchJob |
| 62 | + (BatchJob.run_synchronous, DataCube.execute_batch), |
40 | 63 | # DataCube vs VectorCube |
41 | | - (DataCube.download, VectorCube.download, False), |
42 | | - (DataCube.create_job, VectorCube.create_job, False), |
43 | | - (DataCube.execute_batch, VectorCube.execute_batch, False), |
44 | | - (DataCube.save_result, VectorCube.save_result, False), |
| 64 | + (DataCube.download, VectorCube.download), |
| 65 | + (DataCube.create_job, VectorCube.create_job), |
| 66 | + (DataCube.execute_batch, VectorCube.execute_batch), |
| 67 | + (DataCube.save_result, VectorCube.save_result), |
45 | 68 | # DataCube vs MlModel |
46 | | - (DataCube.create_job, MlModel.create_job, True), |
47 | | - (DataCube.execute_batch, MlModel.execute_batch, True), |
| 69 | + (DataCube.create_job, MlModel.create_job), |
| 70 | + (DataCube.execute_batch, MlModel.execute_batch), |
48 | 71 | # DataCube vs StacResource |
49 | | - (DataCube.download, StacResource.download, True), |
50 | | - (DataCube.create_job, StacResource.create_job, True), |
51 | | - (DataCube.execute_batch, StacResource.execute_batch, True), |
| 72 | + (DataCube.download, StacResource.download), |
| 73 | + (DataCube.create_job, StacResource.create_job), |
| 74 | + (DataCube.execute_batch, StacResource.execute_batch), |
52 | 75 | ], |
53 | 76 | ) |
54 | | -def test_compare_download_execute_params(method_a, method_b, only_intersection): |
| 77 | +def test_cube_processing_params_and_return(method_a, method_b): |
| 78 | + """Check params/return of cube download/execute related methods""" |
| 79 | + signature_a = inspect.signature(method_a) |
| 80 | + signature_b = inspect.signature(method_b) |
| 81 | + |
| 82 | + only_intersection = set(signature_a.parameters.keys()) != set(signature_b.parameters.keys()) |
55 | 83 | assert_same_param_docs(method_a, method_b, only_intersection=only_intersection) |
56 | | - # TODO: compare return description |
| 84 | + |
| 85 | + if signature_a.return_annotation == signature_b.return_annotation: |
| 86 | + assert_same_return_docs(method_a, method_b) |
0 commit comments