Skip to content

Commit

Permalink
Merge pull request #105 from pyiron/reduce_dependence_on_pyiron_workflow
Browse files Browse the repository at this point in the history
[patch] Reduce dependence on pyiron workflow
  • Loading branch information
samwaseda authored Jan 27, 2025
2 parents e29040e + 24554dd commit 287a0e5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pyiron_ontology/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ def get_inputs_and_outputs(node: Node) -> dict:
for key, value in node.inputs.items():
if inputs[key] is None:
inputs[key] = {}
inputs[key]["value"] = value.value
if value.value is not NOT_DATA:
inputs[key]["value"] = value.value
inputs[key]["connection"] = get_source_output(value)
for key, value in node.outputs.to_value_dict().items():
outputs[key]["value"] = value
if value is not NOT_DATA:
outputs[key]["value"] = value
return {
"inputs": inputs,
"outputs": outputs,
Expand Down Expand Up @@ -129,7 +131,7 @@ def get_triples(
graph.add((label, RDF.type, PROV.Entity))
if d.get("uri", None) is not None:
graph.add((label, RDF.type, URIRef(d["uri"])))
if d.get("value", NOT_DATA) is not NOT_DATA:
if "value" in d:
graph.add((label, RDF.value, Literal(d["value"])))
if io_ == "inputs":
graph.add((label, PNS.inputOf, URIRef(full_label)))
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,26 @@ def test_namespace(self):
with self.assertRaises(AttributeError):
_ = PNS.ahoy

def test_parsing_without_running(self):
wf = Workflow("correct_analysis")
wf.addition = add(a=1.0, b=2.0)
data = get_inputs_and_outputs(wf.addition)
self.assertFalse("value" in data["outputs"])
graph = get_triples(data)
self.assertEqual(
len(list(graph.triples((None, RDF.value, None)))),
2,
msg="There should be only values for a and b, but not for the output",
)
wf.run()
data = get_inputs_and_outputs(wf.addition)
graph = get_triples(data)
self.assertEqual(
len(list(graph.triples((None, RDF.value, None)))),
3,
msg="There should be values for a, b and the output",
)


if __name__ == "__main__":
unittest.main()

0 comments on commit 287a0e5

Please sign in to comment.