Skip to content

Commit 1fa2c98

Browse files
committed
fix test supporting collection input (fixes #682) - cwltool patch loadContents (relates to common-workflow-language/cwltool#2036)
1 parent 4b30de5 commit 1fa2c98

File tree

4 files changed

+30
-18
lines changed

4 files changed

+30
-18
lines changed

CHANGES.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ Changes
1212

1313
Changes:
1414
--------
15-
- No change.
15+
- Add support of *OGC API - Processes: Part 3* ``collection`` as input to a `Process`
16+
(fixes `#682 <https://github.com/crim-ca/weaver/issues/682>`_).
17+
- Update ``cwltool`` with fork
18+
`fmigneault/cwltool @ fix-load-contents-array <https://github.com/fmigneault/cwltool/tree/fix-load-contents-array>`_
19+
until ``loadContents`` behavior is resolved for ``type: File[]``
20+
(relates to `common-workflow-language/cwltool#2036 <https://github.com/common-workflow-language/cwltool/pull/2036>`_).
1621

1722
Fixes:
1823
------

requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ cryptography
3535
# use cwltool gpu-enabled support until integrated within the original tool
3636
# (https://github.com/common-workflow-language/common-workflow-language/issues/587)
3737
### git+https://github.com/crim-ca/cwltool@docker-gpu#egg=cwltool
38-
cwltool==3.1.20230906142556
38+
##cwltool==3.1.20230906142556
39+
cwltool @ git+https://github.com/fmigneault/cwltool.git@fix-load-contents-array
3940
docker>=7.1
4041
duration
4142
esgf-compute-api @ git+https://github.com/ESGF/[email protected]
@@ -58,7 +59,7 @@ lxml
5859
mako
5960
# force use of later mistune (https://github.com/common-workflow-language/schema_salad/pull/619#issuecomment-1346025607)
6061
# employed by cwltool -> schema-salad -> mistune
61-
mistune>=2.0.3,<2.1
62+
#mistune>=2.0.3,<2.1
6263
mypy_boto3_s3
6364
numpy>=1.22.2,<2; python_version < "3.10"
6465
numpy>=1.22.2; python_version >= "3.10"

tests/functional/application-packages/EchoFeatures/echo_features.cwl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ inputs:
2222
}
2323
return "http://www.opengis.net/def/glossary/term/FeatureCollection";
2424
}
25+
loadContents: true
2526
inputBinding:
2627
valueFrom: |
2728
${
2829
if (Array.isArray(inputs.features)) {
29-
return {
30+
return JSON.stringify({
3031
"type": "FeatureCollection",
31-
"features": inputs.features.every(item => item.contents)
32-
};
32+
"features": inputs.features.map(item => JSON.parse(item.contents))
33+
});
3334
}
3435
return inputs.features.contents;
3536
}
@@ -38,8 +39,8 @@ outputs:
3839
type: File
3940
format: "ogc-term:FeatureCollection"
4041
outputBinding:
41-
glob: "features.json"
42-
stdout: "features.json"
42+
glob: "features.geojson"
43+
stdout: "features.geojson"
4344
$namespaces:
4445
iana: "https://www.iana.org/assignments/media-types/"
4546
ogc-term: "http://www.opengis.net/def/glossary/term/"

tests/functional/test_wps_package.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2277,23 +2277,21 @@ def test_execute_job_with_collection_input_geojson_feature_collection(self):
22772277
tmp_dir = stack.enter_context(tempfile.TemporaryDirectory()) # pylint: disable=R1732
22782278
stack.enter_context(mocked_file_server(tmp_dir, tmp_host, settings=self.settings, mock_browse_index=True))
22792279

2280-
col_file = os.path.join(tmp_dir, "test.geojson")
22812280
exec_body_val = self.retrieve_payload(name, "execute", local=True)
2281+
col_file = os.path.join(tmp_dir, "test.json")
2282+
col_feats = exec_body_val["inputs"]["features"]["value"] # type: JSON
22822283
with open(col_file, mode="w", encoding="utf-8") as tmp_feature_collection_geojson:
2283-
json.dump(
2284-
exec_body_val["inputs"]["features"]["value"],
2285-
tmp_feature_collection_geojson,
2286-
)
2284+
json.dump(col_feats, tmp_feature_collection_geojson)
22872285

22882286
col_exec_body = {
22892287
"mode": ExecuteMode.ASYNC,
22902288
"response": ExecuteResponse.DOCUMENT,
22912289
"inputs": {
22922290
"features": {
22932291
# accessed directly as a static GeoJSON FeatureCollection
2294-
"collection": "https://mocked-file-server.com/test.geojson",
2292+
"collection": "https://mocked-file-server.com/test.json",
22952293
"format": ExecuteCollectionFormat.GEOJSON,
2296-
"type": ContentType.APP_GEOJSON,
2294+
"schema": "http://www.opengis.net/def/glossary/term/FeatureCollection",
22972295
},
22982296
}
22992297
}
@@ -2307,9 +2305,16 @@ def test_execute_job_with_collection_input_geojson_feature_collection(self):
23072305

23082306
status_url = resp.json["location"]
23092307
results = self.monitor_job(status_url)
2310-
assert "outputs" in results
2311-
2312-
raise NotImplementedError # FIXME: implement! (see above bbox case for inspiration)
2308+
assert "features" in results
2309+
2310+
job_id = status_url.rsplit("/", 1)[-1]
2311+
wps_dir = get_wps_output_dir(self.settings)
2312+
job_dir = os.path.join(wps_dir, job_id)
2313+
job_out = os.path.join(job_dir, "features", "features.geojson")
2314+
assert os.path.isfile(job_out), f"Invalid output file not found: [{job_out}]"
2315+
with open(job_out, mode="r", encoding="utf-8") as out_fd:
2316+
out_data = json.load(out_fd)
2317+
assert out_data["features"] == col_feats["features"]
23132318

23142319
def test_execute_job_with_collection_input_ogc_features(self):
23152320
name = "EchoFeatures"

0 commit comments

Comments
 (0)