Skip to content

Commit

Permalink
basic test & fix typing
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-c committed Dec 15, 2022
1 parent 6909002 commit e2009ac
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
10 changes: 5 additions & 5 deletions cwltool/provenance_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def record_process_end(
self.document.wasEndedBy(process_run_id, None, self.workflow_run_uri, when)

def _add_nested_annotations(
self, annotation_key, annotation_value, e: ProvEntity
self, annotation_key: str, annotation_value: Any, e: ProvEntity
) -> ProvEntity:
"""Propagate input data annotations to provenance."""
# Change https:// into http:// first
Expand Down Expand Up @@ -398,13 +398,13 @@ def declare_file(self, value: CWLObjectType) -> Tuple[ProvEntity, ProvEntity, st

# Identify all schema annotations
schema_annotations = dict(
[(v, value[v]) for v in value.keys() if "schema.org" in v]
[(v, value[v]) for v in value.keys() if v.startswith("https://schema.org")]
)

# Transfer SCHEMA annotations to provenance
for s in schema_annotations:
if "additionalType" in s:
additional_type = schema_annotations[s].split(sep="/")[
additional_type = cast(str, schema_annotations[s]).split(sep="/")[
-1
] # find better method?
file_entity.add_attributes({PROV_TYPE: SCHEMA[additional_type]})
Expand Down Expand Up @@ -527,13 +527,13 @@ def declare_directory(self, value: CWLObjectType) -> ProvEntity:

# Identify all schema annotations
schema_annotations = dict(
[(v, value[v]) for v in value.keys() if "schema.org" in v]
[(v, value[v]) for v in value.keys() if v.startswith("https://schema.org")]
)

# Transfer SCHEMA annotations to provenance
for s in schema_annotations:
if "additionalType" in s:
additional_type = schema_annotations[s].split(sep="/")[
additional_type = cast(str, schema_annotations[s]).split(sep="/")[
-1
] # find better method?
coll.add_attributes({PROV_TYPE: SCHEMA[additional_type]})
Expand Down
22 changes: 22 additions & 0 deletions tests/test_provenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,28 @@ def test_revsort_workflow(tmp_path: Path) -> None:
check_provenance(folder)


@needs_docker
def test_revsort_label_annotations(tmp_path: Path) -> None:
"""Affirm that EDAM file formats in the input object make it into CWLProv."""
base_path = cwltool(
tmp_path,
get_data("tests/wf/revsort.cwl"),
get_data("tests/wf/revsort-job.json"),
)
prov_file = base_path / "metadata" / "provenance" / "primary.cwlprov.nt"
arcp_root = find_arcp(base_path)
g = Graph()
with open(prov_file, "rb") as f:
g.parse(file=f, format="nt", publicID=arcp_root)
mime_having_objects = list(g.subjects(SCHEMA.encodingFormat))
assert len(mime_having_objects) == 2
for obj in mime_having_objects:
assert (
cast(Literal, list(g.objects(obj, SCHEMA.encodingFormat))[0]).value
== "https://www.iana.org/assignments/media-types/text/plain"
)


@needs_docker
def test_nested_workflow(tmp_path: Path) -> None:
check_provenance(cwltool(tmp_path, get_data("tests/wf/nested.cwl")), nested=True)
Expand Down

0 comments on commit e2009ac

Please sign in to comment.