Skip to content

Commit

Permalink
de-CTKS map tests (broadinstitute#4530)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcovarr authored Jan 10, 2019
1 parent 0c5d20c commit e4b4dbc
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 141 deletions.
12 changes: 12 additions & 0 deletions centaur/src/main/resources/standardTestCases/map_workflow.test
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
}
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
}
71 changes: 0 additions & 71 deletions core/src/test/scala/cromwell/util/SampleWdl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -130,26 +130,6 @@ object SampleWdl {
val OutputValue = "Hello world!"
}

object HelloWorldWithoutWorkflow extends SampleWdl {
override def workflowSource(runtime: String = "") =
s"""
|task hello {
| String addressee
| command {
| echo "Hello $${addressee}!"
| }
| output {
| String salutation = read_string(stdout())
| }
|}
""".stripMargin

val Addressee = "hello.hello.addressee"
val rawInputs = Map(Addressee -> "world")
val OutputKey = "hello.hello.salutation"
val OutputValue = "Hello world!\n"
}

object GoodbyeWorld extends SampleWdl {
override def workflowSource(runtime: String = "") =
"""
Expand Down Expand Up @@ -314,19 +294,6 @@ object SampleWdl {
""".stripMargin).replaceAll("RUNTIME", runtime)
}

object ThreeStepWithInputsInTheOutputsSection extends ThreeStepTemplate {
override def workflowSource(runtime: String = "") = sourceString(outputsSection =
"""
|output {
| cgrep.pattern
|}
""".stripMargin).replaceAll("RUNTIME", runtime)
}

object ThreeStepLargeJson extends ThreeStepTemplate {
override lazy val rawInputs = Map(ThreeStep.PatternKey -> "." * 10000)
}

object WorkflowOutputsWithFiles extends SampleWdl {
// ASCII art from http://www.chris.com/ascii/joan/www.geocities.com/SoHo/7373/flag.html with pipes
// replaced by exclamation points to keep stripMargin from removing the flagpole.
Expand Down Expand Up @@ -523,44 +490,6 @@ object SampleWdl {
override val rawInputs: Map[String, Any] = Map.empty
}

case class MapLiteral(catRootDir: Path) extends SampleWdl {
createFileArray(catRootDir)
def cleanup() = cleanupFileArray(catRootDir)

override def workflowSource(runtime: String = "") =
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

override val rawInputs = Map.empty[String, String]
}

class ScatterWdl extends SampleWdl {
val tasks = s"""task A {
| command {
Expand Down
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
}
70 changes: 0 additions & 70 deletions server/src/test/scala/cromwell/MapWorkflowSpec.scala

This file was deleted.

0 comments on commit e4b4dbc

Please sign in to comment.