Commit 03737d70 authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Added test on pipeline name

parent 343ac6e1
......@@ -31,9 +31,11 @@ trait PipelineCommand extends MainCommand with GatkLogging with ImplicitConversi
* Gets location of compiled class of pipeline
* @return path from classPath to class file
*/
def pipeline = "/" + getClass.getName.stripSuffix("$").replaceAll("\\.", "/") + ".class"
def pipeline = "/" + getClass.getName.takeWhile(_ != '$').replaceAll("\\.", "/") + ".class"
def pipelineName = getClass.getSimpleName.takeWhile(_ != '$').toLowerCase
def pipelineName = getClass.getName.takeWhile(_ != '$').split("\\.").last.toLowerCase
protected val globalConfig = Config.global
/** Class can be used directly from java with -cp option */
def main(args: Array[String]): Unit = {
......@@ -41,7 +43,7 @@ trait PipelineCommand extends MainCommand with GatkLogging with ImplicitConversi
for (t <- 0 until argsSize) {
if (args(t) == "-config" || args(t) == "--config_file") {
if (args.length <= (t + 1)) throw new IllegalStateException("-config needs a value: <file>")
Config.global.loadConfigFile(new File(args(t + 1)))
globalConfig.loadConfigFile(new File(args(t + 1)))
}
if (args(t) == "-cv" || args(t) == "--config_value") {
......@@ -52,7 +54,7 @@ trait PipelineCommand extends MainCommand with GatkLogging with ImplicitConversi
val p = v(0).split(":")
val key = p.last
val path = p.dropRight(1).toList
Config.global.addValue(key, value, path)
globalConfig.addValue(key, value, path)
}
if (args(t) == "--logging_level" || args(t) == "-l") {
......@@ -74,8 +76,8 @@ trait PipelineCommand extends MainCommand with GatkLogging with ImplicitConversi
val logFile = {
val pipelineName = this.getClass.getSimpleName.toLowerCase.split("""\$""").head
val pipelineConfig = Config.global.map.getOrElse(pipelineName, Map()).asInstanceOf[Map[String, Any]]
val pipelineOutputDir = new File(Config.global.map.getOrElse("output_dir", pipelineConfig.getOrElse("output_dir", "./")).toString)
val pipelineConfig = globalConfig.map.getOrElse(pipelineName, Map()).asInstanceOf[Map[String, Any]]
val pipelineOutputDir = new File(globalConfig.map.getOrElse("output_dir", pipelineConfig.getOrElse("output_dir", "./")).toString)
val logDir: File = new File(pipelineOutputDir, ".log")
logDir.mkdirs()
new File(logDir, "biopet." + BiopetQCommandLine.timestamp + ".log")
......@@ -91,7 +93,7 @@ trait PipelineCommand extends MainCommand with GatkLogging with ImplicitConversi
argv ++= List("--log_to_file", new File(logFile.getParentFile, "queue." + BiopetQCommandLine.timestamp + ".log").getAbsolutePath)
}
if (!args.contains("-retry") && !args.contains("--retry_failed")) {
val retry: Int = Config.global(pipelineName, Nil, "retry", default = 5)
val retry: Int = globalConfig(pipelineName, Nil, "retry", default = 5)
logger.info("No retry flag found, ")
argv ++= List("-retry", retry.toString)
}
......
package nl.lumc.sasc.biopet.core
import nl.lumc.sasc.biopet.utils.config.Config
import org.scalatest.Matchers
import org.scalatest.testng.TestNGSuite
import org.testng.annotations.Test
/**
* Created by pjvanthof on 17/11/15.
*/
class PipelineCommandTest extends TestNGSuite with Matchers {
@Test
def testPipelineCommand: Unit = {
val pipeline = new PipelineCommand {
override val globalConfig = new Config(Map())
def getConfig = globalConfig
}
pipeline.pipelineName shouldBe this.getClass.getSimpleName.toLowerCase
pipeline.pipeline shouldBe s"/${this.getClass.getName.stripSuffix("$").replaceAll("\\.", "/")}.class"
// Config should be emty if the main method is not yet touched
pipeline.getConfig.map shouldBe empty
//TODO: Main method testing
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment