Skip to content

Commit fa3c25e

Browse files
author
Alan Christie
committed
feat: Experiment with get_inputs and get_outputs
1 parent 1addfa3 commit fa3c25e

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed

decoder/decoder.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,18 @@ def get_jobs_replaced(job_definition: Dict[str, Any]) -> Optional[List[str]]:
328328
return list(replaced)
329329

330330

331+
def get_outputs(job_definition: Dict[str, Any]) -> Optional[Dict[str, Any]]:
332+
"""Given a Job Definition this function returns the outputs declared.
333+
"""
334+
return job_definition.get('variables', {}).get('outputs', {}).get('properties', {})
335+
336+
337+
def get_inputs(job_definition: Dict[str, Any]) -> Optional[Dict[str, Any]]:
338+
"""Given a Job Definition this function returns the inputs declared.
339+
"""
340+
return job_definition.get('variables', {}).get('inputs', {}).get('properties', {})
341+
342+
331343
def decode(
332344
template_text: str,
333345
variable_map: Optional[Dict[str, str]],

tests/test_get_inputs.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Tests for the decoder's get_inputs() function.
2+
from typing import Dict
3+
4+
import pytest
5+
6+
pytestmark = pytest.mark.unit
7+
8+
from decoder import decoder
9+
10+
11+
def test_get_inputs_when_none():
12+
# Arrange
13+
job_definition: Dict = {}
14+
15+
# Act
16+
inputs = decoder.get_inputs(job_definition)
17+
18+
# Assert
19+
assert inputs is None
20+
21+
22+
def test_get_inputs():
23+
# Arrange
24+
job_definition: Dict = {
25+
"variables": {
26+
"inputs": {
27+
"properties": {
28+
"inputFile": {
29+
"title": "PDB File",
30+
"mime-types": ["chemical/x-pdb"],
31+
"type": "file",
32+
}
33+
}
34+
}
35+
}
36+
}
37+
38+
# Act
39+
inputs = decoder.get_inputs(job_definition)
40+
41+
# Assert
42+
assert inputs
43+
assert "inputFile" in inputs
44+
assert inputs["inputFile"]["title"] == "PDB File"
45+
assert inputs["inputFile"]["mime-types"] == ["chemical/x-pdb"]
46+
assert inputs["inputFile"]["type"] == "file"

tests/test_get_outputs.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Tests for the decoder's get_outputs() function.
2+
from typing import Dict
3+
4+
import pytest
5+
6+
pytestmark = pytest.mark.unit
7+
8+
from decoder import decoder
9+
10+
11+
def test_get_outputs_when_none():
12+
# Arrange
13+
job_definition: Dict = {}
14+
15+
# Act
16+
outputs = decoder.get_outputs(job_definition)
17+
18+
# Assert
19+
assert outputs is None
20+
21+
22+
def test_get_outputs():
23+
# Arrange
24+
job_definition: Dict = {
25+
"variables": {
26+
"outputs": {
27+
"properties": {
28+
"pdbFile": {
29+
"title": "PDB File",
30+
"mime-types": ["chemical/x-pdb"],
31+
"type": "file",
32+
}
33+
}
34+
}
35+
}
36+
}
37+
38+
# Act
39+
outputs = decoder.get_outputs(job_definition)
40+
41+
# Assert
42+
assert outputs
43+
assert "pdbFile" in outputs
44+
assert outputs["pdbFile"]["title"] == "PDB File"
45+
assert outputs["pdbFile"]["mime-types"] == ["chemical/x-pdb"]
46+
assert outputs["pdbFile"]["type"] == "file"

0 commit comments

Comments
 (0)