Skip to content

Commit 79bd568

Browse files
author
Alan Christie
committed
2 parents 8033810 + d9105c2 commit 79bd568

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed

decoder/decoder.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,16 @@ 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+
return job_definition.get("variables", {}).get("outputs", {}).get("properties", {})
334+
335+
336+
def get_inputs(job_definition: Dict[str, Any]) -> Optional[Dict[str, Any]]:
337+
"""Given a Job Definition this function returns the inputs declared."""
338+
return job_definition.get("variables", {}).get("inputs", {}).get("properties", {})
339+
340+
331341
def decode(
332342
template_text: str,
333343
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 == {}
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 == {}
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)