Skip to content

Commit

Permalink
fix test supporting collection input (fixes #682) - cwltool patch loa…
Browse files Browse the repository at this point in the history
…dContents (relates to common-workflow-language/cwltool#2036)
  • Loading branch information
fmigneault committed Aug 26, 2024
1 parent 4b30de5 commit 1fa2c98
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
7 changes: 6 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ Changes

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

Fixes:
------
Expand Down
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ cryptography
# use cwltool gpu-enabled support until integrated within the original tool
# (https://github.com/common-workflow-language/common-workflow-language/issues/587)
### git+https://github.com/crim-ca/cwltool@docker-gpu#egg=cwltool
cwltool==3.1.20230906142556
##cwltool==3.1.20230906142556
cwltool @ git+https://github.com/fmigneault/cwltool.git@fix-load-contents-array
docker>=7.1
duration
esgf-compute-api @ git+https://github.com/ESGF/[email protected]
Expand All @@ -58,7 +59,7 @@ lxml
mako
# force use of later mistune (https://github.com/common-workflow-language/schema_salad/pull/619#issuecomment-1346025607)
# employed by cwltool -> schema-salad -> mistune
mistune>=2.0.3,<2.1
#mistune>=2.0.3,<2.1
mypy_boto3_s3
numpy>=1.22.2,<2; python_version < "3.10"
numpy>=1.22.2; python_version >= "3.10"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ inputs:
}
return "http://www.opengis.net/def/glossary/term/FeatureCollection";
}
loadContents: true
inputBinding:
valueFrom: |
${
if (Array.isArray(inputs.features)) {
return {
return JSON.stringify({
"type": "FeatureCollection",
"features": inputs.features.every(item => item.contents)
};
"features": inputs.features.map(item => JSON.parse(item.contents))
});
}
return inputs.features.contents;
}
Expand All @@ -38,8 +39,8 @@ outputs:
type: File
format: "ogc-term:FeatureCollection"
outputBinding:
glob: "features.json"
stdout: "features.json"
glob: "features.geojson"
stdout: "features.geojson"
$namespaces:
iana: "https://www.iana.org/assignments/media-types/"
ogc-term: "http://www.opengis.net/def/glossary/term/"
25 changes: 15 additions & 10 deletions tests/functional/test_wps_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -2277,23 +2277,21 @@ def test_execute_job_with_collection_input_geojson_feature_collection(self):
tmp_dir = stack.enter_context(tempfile.TemporaryDirectory()) # pylint: disable=R1732
stack.enter_context(mocked_file_server(tmp_dir, tmp_host, settings=self.settings, mock_browse_index=True))

col_file = os.path.join(tmp_dir, "test.geojson")
exec_body_val = self.retrieve_payload(name, "execute", local=True)
col_file = os.path.join(tmp_dir, "test.json")
col_feats = exec_body_val["inputs"]["features"]["value"] # type: JSON
with open(col_file, mode="w", encoding="utf-8") as tmp_feature_collection_geojson:
json.dump(
exec_body_val["inputs"]["features"]["value"],
tmp_feature_collection_geojson,
)
json.dump(col_feats, tmp_feature_collection_geojson)

col_exec_body = {
"mode": ExecuteMode.ASYNC,
"response": ExecuteResponse.DOCUMENT,
"inputs": {
"features": {
# accessed directly as a static GeoJSON FeatureCollection
"collection": "https://mocked-file-server.com/test.geojson",
"collection": "https://mocked-file-server.com/test.json",
"format": ExecuteCollectionFormat.GEOJSON,
"type": ContentType.APP_GEOJSON,
"schema": "http://www.opengis.net/def/glossary/term/FeatureCollection",
},
}
}
Expand All @@ -2307,9 +2305,16 @@ def test_execute_job_with_collection_input_geojson_feature_collection(self):

status_url = resp.json["location"]
results = self.monitor_job(status_url)
assert "outputs" in results

raise NotImplementedError # FIXME: implement! (see above bbox case for inspiration)
assert "features" in results

job_id = status_url.rsplit("/", 1)[-1]
wps_dir = get_wps_output_dir(self.settings)
job_dir = os.path.join(wps_dir, job_id)
job_out = os.path.join(job_dir, "features", "features.geojson")
assert os.path.isfile(job_out), f"Invalid output file not found: [{job_out}]"
with open(job_out, mode="r", encoding="utf-8") as out_fd:
out_data = json.load(out_fd)
assert out_data["features"] == col_feats["features"]

def test_execute_job_with_collection_input_ogc_features(self):
name = "EchoFeatures"
Expand Down

0 comments on commit 1fa2c98

Please sign in to comment.