WriteDependenciesTest.scala 2.16 KB
Newer Older
1
2
3
4
5
package nl.lumc.sasc.biopet.core

import java.io.File
import java.nio.file.Files

Peter van 't Hof's avatar
Peter van 't Hof committed
6
import nl.lumc.sasc.biopet.utils.ConfigUtils
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import org.broadinstitute.gatk.queue.function.QFunction
import org.scalatest.Matchers
import org.scalatest.testng.TestNGSuite
import org.testng.annotations.Test

import scala.io.Source

/**
  * Created by pjvanthof on 09/05/16.
  */
class WriteDependenciesTest extends TestNGSuite with Matchers {

  import WriteDependenciesTest._

  case class Qfunc(in: Seq[File], out: Seq[File]) extends QFunction {
    override def inputs = in
    override def outputs = out
    override def doneOutputs = out.map(x => new File(x.getParentFile, s".${x.getName}.done"))
    override def failOutputs = out.map(x => new File(x.getParentFile, s".${x.getName}.fail"))
    jobOutputFile = new File(out.head + ".out")
  }

  @Test
Peter van 't Hof's avatar
Peter van 't Hof committed
30
  def testDeps: Unit = {
31
32
    val outputFile = File.createTempFile("deps.", ".json")
    outputFile.deleteOnExit()
Peter van 't Hof's avatar
Peter van 't Hof committed
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
    val func1 = Qfunc(file1 :: Nil, file2 :: Nil)
    val func2 = Qfunc(file2 :: Nil, file3 :: Nil)
    WriteDependencies.writeDependencies(func1 :: func2 :: Nil, outputFile)
    val deps = ConfigUtils.fileToConfigMap(outputFile)
    deps("jobs") shouldBe a[Map[_, _]]
    val jobs = deps("jobs").asInstanceOf[Map[String, Map[String, Any]]]
    jobs.count(_._1.contains("Qfunc")) shouldBe 2

    deps("files") shouldBe a[List[_]]
    val files = deps("files").asInstanceOf[List[Map[String, Any]]]
    val paths = files.map(x => x.get("path")).flatten
    assert(paths.contains(file1.toString))
    assert(paths.contains(file2.toString))
    assert(paths.contains(file3.toString))

    files.find(_.get("path") == Some(file1.toString)).flatMap(_.get("pipeline_input")) shouldBe Some(true)
    files.find(_.get("path") == Some(file2.toString)).flatMap(_.get("pipeline_input")) shouldBe Some(false)
    files.find(_.get("path") == Some(file3.toString)).flatMap(_.get("pipeline_input")) shouldBe Some(false)
51
52
53
54
55
56
57
58
59
60
  }
}

object WriteDependenciesTest {
  val tempDir = Files.createTempDirectory("test").toFile
  tempDir.deleteOnExit()
  val file1 = new File(tempDir, "file1.txt")
  val file2 = new File(tempDir, "file2.txt")
  val file3 = new File(tempDir, "file3.txt")
}