Skip to content

Commit

Permalink
Merge pull request #10 from PMCC-BioinformaticsCore/release-v0.3.1
Browse files Browse the repository at this point in the history
Release v0.3.1
  • Loading branch information
rlupat authored Jul 12, 2023
2 parents a9cc0da + f74f697 commit d42ed24
Show file tree
Hide file tree
Showing 9 changed files with 260 additions and 115 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ __pycache__/
**/**/DS_Store
build/
dist/
illusional.wdlgen.egg-info
venv/
illusional.wdlgen.egg-info
*.egg-info
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"python.testing.unittestArgs": [
"-v",
"-s",
"./tests",
"-p",
"test_*.py"
],
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true
}
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup

__version__ = "v0.3.0"
__version__ = "v0.3.1.2"

DESCRIPTION = (
"Contains classes and helpers to generate WDL without worrying about the syntax. "
Expand Down
13 changes: 13 additions & 0 deletions tests/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@



def non_blank_lines_list(text: str) -> list[str]:
lines = text.splitlines()
lines = [ln for ln in lines if not ln == '']
return lines

def non_blank_lines_str(text: str) -> str:
lines = text.splitlines()
lines = [ln for ln in lines if not ln == '']
outstr = '\n'.join(lines)
return outstr
89 changes: 53 additions & 36 deletions tests/test_task_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
ParameterMeta,
)

from tests.helpers import non_blank_lines_list


class TestTaskGeneration(unittest.TestCase):
def test_simple_task(self):
Expand Down Expand Up @@ -44,7 +46,7 @@ def test_readme(self):
w.imports.append(Workflow.WorkflowImport("tool_file", ""))
w.inputs.append(Input(WdlType.parse_type("String"), "inputGreeting"))

inputs_map = {"taskGreeting": "inputGreeting"}
inputs_map = {'taskGreeting': {'value': 'inputGreeting'}}
w.calls.append(
WorkflowCall("Q.namspaced_task_identifier", "task_alias", inputs_map)
)
Expand Down Expand Up @@ -234,15 +236,18 @@ def test_commandinp_array_inp(self):
class TestWorkflowGeneration(unittest.TestCase):
def test_hello_workflow(self):
# https://github.com/openwdl/wdl/#specifying-inputs-and-using-declarations
w = Workflow("test")
w = Workflow('test')

w.calls.append(WorkflowCall(TestTaskGeneration.test_hello_tasks().name))

inputs_details={
'salutation': {'value': 'Greetings'},
'name': {'value': 'Michael'}
}
w.calls.append(
WorkflowCall(
TestTaskGeneration.test_hello_tasks().name,
alias="hello2",
inputs_map={"salutation": '"Greetings"', "name": '"Michael"'},
alias='hello2',
inputs_details=inputs_details,
)
)

Expand All @@ -255,8 +260,8 @@ def test_call_scatter(self):
"i",
"integers",
[
WorkflowCall(Task("task1").name, inputs_map={"num": "i"}),
WorkflowCall(Task("task2").name, inputs_map={"num": "task1.output"}),
WorkflowCall(Task('task1').name, inputs_details={'num': {'value': 'i'}}),
WorkflowCall(Task('task2').name, inputs_details={'num': {'value': 'task1.output'}}),
],
)

Expand All @@ -267,19 +272,23 @@ def test_call_scatter(self):

class TestWorkflowParameterMetaGeneration(unittest.TestCase):
def test_parameter_meta_scalar(self):
w = Task("param_meta_scalar", parameter_meta=ParameterMeta(test=42))
task = Task("param_meta_scalar", parameter_meta=ParameterMeta(test=42))
task_str = task.get_string()
task_lines = non_blank_lines_list(task_str)

expected = """\
task param_meta_scalar {
parameter_meta {
test: 42
}
}"""
derived_workflow_only = "".join(w.get_string().splitlines(keepends=True)[2:])
self.assertEqual(expected, derived_workflow_only)
task_str = '\n'.join(task_lines[1:])
self.assertEqual(expected, task_str)

def test_parameter_meta_bool(self):
w = Task("param_meta_scalar", parameter_meta=ParameterMeta(pos=True, neg=False))
task = Task("param_meta_scalar", parameter_meta=ParameterMeta(pos=True, neg=False))
task_str = task.get_string()
task_lines = non_blank_lines_list(task_str)

expected = """\
task param_meta_scalar {
Expand All @@ -288,96 +297,104 @@ def test_parameter_meta_bool(self):
neg: false
}
}"""
derived_workflow_only = "".join(w.get_string().splitlines(keepends=True)[2:])
self.assertEqual(expected, derived_workflow_only)
task_str = '\n'.join(task_lines[1:])
self.assertEqual(expected, task_str)

def test_parameter_meta_string(self):
w = Task(
"param_meta_string", parameter_meta=ParameterMeta(other="string value")
)
task = Task("param_meta_string", parameter_meta=ParameterMeta(other="string value"))
task_str = task.get_string()
task_lines = non_blank_lines_list(task_str)


expected = """\
task param_meta_string {
parameter_meta {
other: "string value"
}
}"""
derived_workflow_only = "".join(w.get_string().splitlines(keepends=True)[2:])
self.assertEqual(expected, derived_workflow_only)
task_str = '\n'.join(task_lines[1:])
self.assertEqual(expected, task_str)

def test_parameter_meta_obj(self):
w = Task(
task = Task(
"param_meta_obj",
parameter_meta=ParameterMeta(
obj_value=ParameterMeta.ParamMetaAttribute(
help="This is help text", scalar=96
)
),
)
task_str = task.get_string()
task_lines = non_blank_lines_list(task_str)

expected = """\
task param_meta_obj {
parameter_meta {
obj_value: {help: "This is help text", scalar: 96}
}
}"""
derived_workflow_only = "".join(w.get_string().splitlines(keepends=True)[2:])
self.assertEqual(expected, derived_workflow_only)
task_str = '\n'.join(task_lines[1:])
self.assertEqual(expected, task_str)

def test_parameter_meta_dict(self):
w = Task(
task = Task(
"param_meta_obj",
parameter_meta=ParameterMeta(
obj_value={
"help": "This is help text", "scalar": 96
}
),
)
task_str = task.get_string()
task_lines = non_blank_lines_list(task_str)

expected = """\
task param_meta_obj {
parameter_meta {
obj_value: {help: "This is help text", scalar: 96}
}
}"""
derived_workflow_only = "".join(w.get_string().splitlines(keepends=True)[2:])
self.assertEqual(expected, derived_workflow_only)
task_str = '\n'.join(task_lines[1:])
self.assertEqual(expected, task_str)


class TestWorkflowMetaGeneration(unittest.TestCase):
def test_meta_scalar(self):
w = Task("meta_scalar", meta=Meta(arbitrary_scalar=42))

task = Task("meta_scalar", meta=Meta(arbitrary_scalar=42))
task_str = task.get_string()
task_lines = non_blank_lines_list(task_str)
expected = """\
task meta_scalar {
meta {
arbitrary_scalar: 42
}
}"""
derived_workflow_only = "".join(w.get_string().splitlines(keepends=True)[2:])
self.assertEqual(expected, derived_workflow_only)
task_str = '\n'.join(task_lines[1:])
self.assertEqual(expected, task_str)

def test_meta_bool(self):
w = Task("meta_scalar", meta=Meta(pos=True, neg=False))

task = Task("meta_scalar", meta=Meta(pos=True, neg=False))
task_str = task.get_string()
task_lines = non_blank_lines_list(task_str)
expected = """\
task meta_scalar {
meta {
pos: true
neg: false
}
}"""
derived_workflow_only = "".join(w.get_string().splitlines(keepends=True)[2:])
self.assertEqual(expected, derived_workflow_only)
task_str = '\n'.join(task_lines[1:])
self.assertEqual(expected, task_str)

def test_meta_string(self):
w = Task("meta_string", meta=Meta(author="illusional"))

task = Task("meta_string", meta=Meta(author="illusional"))
task_str = task.get_string()
task_lines = non_blank_lines_list(task_str)
expected = """\
task meta_string {
meta {
author: "illusional"
}
}"""
derived_workflow_only = "".join(w.get_string().splitlines(keepends=True)[2:])
self.assertEqual(expected, derived_workflow_only)
task_str = '\n'.join(task_lines[1:])
self.assertEqual(expected, task_str)
Loading

0 comments on commit d42ed24

Please sign in to comment.