Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Christie committed Jul 20, 2023
2 parents 8033810 + d9105c2 commit 79bd568
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
10 changes: 10 additions & 0 deletions decoder/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,16 @@ def get_jobs_replaced(job_definition: Dict[str, Any]) -> Optional[List[str]]:
return list(replaced)


def get_outputs(job_definition: Dict[str, Any]) -> Optional[Dict[str, Any]]:
"""Given a Job Definition this function returns the outputs declared."""
return job_definition.get("variables", {}).get("outputs", {}).get("properties", {})


def get_inputs(job_definition: Dict[str, Any]) -> Optional[Dict[str, Any]]:
"""Given a Job Definition this function returns the inputs declared."""
return job_definition.get("variables", {}).get("inputs", {}).get("properties", {})


def decode(
template_text: str,
variable_map: Optional[Dict[str, str]],
Expand Down
46 changes: 46 additions & 0 deletions tests/test_get_inputs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Tests for the decoder's get_inputs() function.
from typing import Dict

import pytest

pytestmark = pytest.mark.unit

from decoder import decoder


def test_get_inputs_when_none():
# Arrange
job_definition: Dict = {}

# Act
inputs = decoder.get_inputs(job_definition)

# Assert
assert inputs == {}


def test_get_inputs():
# Arrange
job_definition: Dict = {
"variables": {
"inputs": {
"properties": {
"inputFile": {
"title": "PDB File",
"mime-types": ["chemical/x-pdb"],
"type": "file",
}
}
}
}
}

# Act
inputs = decoder.get_inputs(job_definition)

# Assert
assert inputs
assert "inputFile" in inputs
assert inputs["inputFile"]["title"] == "PDB File"
assert inputs["inputFile"]["mime-types"] == ["chemical/x-pdb"]
assert inputs["inputFile"]["type"] == "file"
46 changes: 46 additions & 0 deletions tests/test_get_outputs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Tests for the decoder's get_outputs() function.
from typing import Dict

import pytest

pytestmark = pytest.mark.unit

from decoder import decoder


def test_get_outputs_when_none():
# Arrange
job_definition: Dict = {}

# Act
outputs = decoder.get_outputs(job_definition)

# Assert
assert outputs == {}


def test_get_outputs():
# Arrange
job_definition: Dict = {
"variables": {
"outputs": {
"properties": {
"pdbFile": {
"title": "PDB File",
"mime-types": ["chemical/x-pdb"],
"type": "file",
}
}
}
}
}

# Act
outputs = decoder.get_outputs(job_definition)

# Assert
assert outputs
assert "pdbFile" in outputs
assert outputs["pdbFile"]["title"] == "PDB File"
assert outputs["pdbFile"]["mime-types"] == ["chemical/x-pdb"]
assert outputs["pdbFile"]["type"] == "file"

0 comments on commit 79bd568

Please sign in to comment.