forked from broadinstitute/cromwell
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
de-CTKS map tests (broadinstitute#4530)
- Loading branch information
Showing
5 changed files
with
145 additions
and
141 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
centaur/src/main/resources/standardTestCases/map_workflow.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: map_workflow | ||
testFormat: workflowsuccess | ||
|
||
files { | ||
workflow: map_workflow/map_workflow.wdl | ||
} | ||
|
||
metadata { | ||
"outputs.wf.read_map.out_map.x": 500 | ||
"outputs.wf.read_map.out_map.y": 600 | ||
"outputs.wf.read_map.out_map.z": 700 | ||
} |
48 changes: 48 additions & 0 deletions
48
centaur/src/main/resources/standardTestCases/map_workflow/map_workflow.wdl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
version 1.0 | ||
|
||
task make_files { | ||
command { | ||
for f in f1 f2 f3; do touch $f; done | ||
} | ||
output { | ||
Array[File] files = ["f1", "f2", "f3"] | ||
} | ||
runtime { | ||
docker: "python:2.7" | ||
} | ||
} | ||
|
||
task write_map { | ||
input { | ||
Map[File, String] file_to_name | ||
} | ||
command { | ||
cat ${write_map(file_to_name)} | ||
} | ||
output { | ||
String contents = read_string(stdout()) | ||
} | ||
runtime { | ||
docker: "python:2.7" | ||
} | ||
} | ||
task read_map { | ||
command <<< | ||
python <<CODE | ||
map = {'x': 500, 'y': 600, 'z': 700} | ||
print("\\n".join(["{}\\t{}".format(k,v) for k,v in map.items()])) | ||
CODE | ||
>>> | ||
output { | ||
Map[String, Int] out_map = read_map(stdout()) | ||
} | ||
runtime { | ||
docker: "python:2.7" | ||
} | ||
} | ||
workflow wf { | ||
call make_files | ||
Map[File, String] map = {make_files.files[0]: "alice", make_files.files[1]: "bob", make_files.files[2]: "chuck"} | ||
call write_map {input: file_to_name = map} | ||
call read_map | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
languageFactories/wdl-draft2/src/test/scala/languages.wdl.draft2/MapWorkflowSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package languages.wdl.draft2 | ||
|
||
import languages.wdl.draft2.MapWorkflowSpec._ | ||
import org.scalatest.{FlatSpec, Matchers} | ||
import wdl.draft2.model.expression.{NoFunctions, WdlFunctions} | ||
import wdl.draft2.model.{Draft2ImportResolver, WdlNamespaceWithWorkflow} | ||
import wom.types.{WomMapType, WomSingleFileType, WomStringType} | ||
import wom.values.{WomMap, WomSingleFile, WomString, WomValue} | ||
|
||
import scala.util.{Success, Try} | ||
|
||
class MapWorkflowSpec extends FlatSpec with Matchers { | ||
val namespace = WdlNamespaceWithWorkflow.load(WorkflowSource, Seq.empty[Draft2ImportResolver]).get | ||
val expectedMap = WomMap(WomMapType(WomSingleFileType, WomStringType), Map( | ||
WomSingleFile("f1") -> WomString("alice"), | ||
WomSingleFile("f2") -> WomString("bob"), | ||
WomSingleFile("f3") -> WomString("chuck") | ||
)) | ||
|
||
"A static Map[File, String] declaration" should "be a valid declaration" in { | ||
val declaration = namespace.workflow.declarations.find { | ||
_.unqualifiedName == "map" | ||
}.getOrElse { | ||
fail("Expected declaration 'map' to be found") | ||
} | ||
val expression = declaration.expression.getOrElse { | ||
fail("Expected an expression for declaration 'map'") | ||
} | ||
val value = expression.evaluate((_: String) => fail("No lookups"), NoFunctions).getOrElse { | ||
fail("Expected expression for 'map' to evaluate") | ||
} | ||
expectedMap.womType.coerceRawValue(value).get shouldEqual expectedMap | ||
} | ||
|
||
it should "be usable as an input" in { | ||
val writeMapTask = namespace.findTask("write_map").getOrElse { | ||
fail("Expected to find task 'write_map'") | ||
} | ||
class CannedFunctions extends WdlFunctions[WomValue] { | ||
def write_map(params: Seq[Try[WomValue]]): Try[WomSingleFile] = Success(WomSingleFile("/test/map/path")) | ||
|
||
override def getFunction(name: String): WdlFunction = name match { | ||
case "write_map" => write_map | ||
case _ => throw new UnsupportedOperationException("Only write_map should be called") | ||
} | ||
} | ||
val command = writeMapTask.instantiateCommand(writeMapTask.inputsFromMap(Map("file_to_name" -> expectedMap)), new CannedFunctions).getOrElse { | ||
fail("Expected instantiation to work") | ||
} | ||
command.head.commandString shouldEqual "cat /test/map/path" | ||
} | ||
} | ||
|
||
object MapWorkflowSpec { | ||
val WorkflowSource = | ||
s""" | ||
|task write_map { | ||
| Map[File, String] file_to_name | ||
| command { | ||
| cat $${write_map(file_to_name)} | ||
| } | ||
| output { | ||
| String contents = read_string(stdout()) | ||
| } | ||
|} | ||
| | ||
|task read_map { | ||
| command <<< | ||
| python <<CODE | ||
| map = {'x': 500, 'y': 600, 'z': 700} | ||
| print("\\n".join(["{}\\t{}".format(k,v) for k,v in map.items()])) | ||
| CODE | ||
| >>> | ||
| output { | ||
| Map[String, Int] out_map = read_map(stdout()) | ||
| } | ||
|} | ||
| | ||
|workflow wf { | ||
| Map[File, String] map = {"f1": "alice", "f2": "bob", "f3": "chuck"} | ||
| call write_map {input: file_to_name = map} | ||
| call read_map | ||
|} | ||
""".stripMargin | ||
} |
This file was deleted.
Oops, something went wrong.