Commit 313b0c04 authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Make a val for globalConfig, test should now be able to override it so unit...

Make a val for globalConfig, test should now be able to override it so unit test are not depending on a global var
parent be1acd39
......@@ -32,7 +32,7 @@ trait BiopetQScript extends Configurable with GatkLogging {
val configfiles: List[File] = Nil
var outputDir: String = {
val temp = Config.getValueFromMap(Config.global.map, ConfigValueIndex(this.configName, configPath, "output_dir"))
val temp = Config.getValueFromMap(globalConfig.map, ConfigValueIndex(this.configName, configPath, "output_dir"))
if (temp.isEmpty) ""
else {
val t = temp.get.value.toString
......@@ -71,7 +71,7 @@ trait BiopetQScript extends Configurable with GatkLogging {
case _ =>
}
if (new File(outputDir).canWrite) Config.global.writeReport(qSettings.runName, outputDir + ".log/" + qSettings.runName)
if (new File(outputDir).canWrite) globalConfig.writeReport(qSettings.runName, outputDir + ".log/" + qSettings.runName)
else BiopetQScript.addError("Output dir: '" + outputDir + "' is not writeable")
BiopetQScript.checkErrors
......
......@@ -28,7 +28,7 @@ trait MultiSampleQScript extends BiopetQScript {
@Argument(doc = "Only Sample", shortName = "sample", required = false)
private val onlySamples: List[String] = Nil
require(Config.global.map.contains("samples"), "No Samples found in config")
require(globalConfig.map.contains("samples"), "No Samples found in config")
/**
* Sample class with basic functions build in
......@@ -80,7 +80,7 @@ trait MultiSampleQScript extends BiopetQScript {
/** returns a set with library names */
protected def libIds: Set[String] = {
ConfigUtils.getMapFromPath(Config.global.map, List("samples", sampleId, "libraries")).getOrElse(Map()).keySet
ConfigUtils.getMapFromPath(globalConfig.map, List("samples", sampleId, "libraries")).getOrElse(Map()).keySet
}
/** Adds sample jobs */
......@@ -125,7 +125,7 @@ trait MultiSampleQScript extends BiopetQScript {
val samples: Map[String, Sample] = sampleIds.map(id => id -> makeSample(id)).toMap
/** Returns a list of all sampleIDs */
protected def sampleIds: Set[String] = ConfigUtils.any2map(Config.global.map("samples")).keySet
protected def sampleIds: Set[String] = ConfigUtils.any2map(globalConfig.map("samples")).keySet
/** Runs addAndTrackJobs method for each sample */
final def addSamplesJobs() {
......
......@@ -138,7 +138,6 @@ class Config(var map: Map[String, Any]) extends Logging {
defaultCache += (requestedIndex -> ConfigValue(requestedIndex, null, default, freeVar))
defaultCache(requestedIndex)
} else ConfigValue(requestedIndex, null, null, freeVar)
//else throw new IllegalStateException("Value in config could not be found but it seems required, index: " + requestedIndex)
}
def writeReport(id: String, directory: String): Unit = {
......@@ -175,7 +174,7 @@ class Config(var map: Map[String, Any]) extends Logging {
val fullEffective = ConfigUtils.mergeMaps(effectiveFound, effectiveDefaultFound)
val fullEffectiveWithNotFound = ConfigUtils.mergeMaps(fullEffective, notFound)
writeMapToJsonFile(Config.global.map, "input")
writeMapToJsonFile(this.map, "input")
writeMapToJsonFile(found, "found")
writeMapToJsonFile(effectiveFound, "effective.found")
writeMapToJsonFile(effectiveDefaultFound, "effective.defaults")
......
......@@ -21,6 +21,7 @@ import nl.lumc.sasc.biopet.utils.ConfigUtils.ImplicitConversions
trait Configurable extends ImplicitConversions {
/** Should be object of parant object */
val root: Configurable
val globalConfig: Config = if (root != null) root.globalConfig else Config.global
/** subfix to the path */
def subPath: List[String] = Nil
......@@ -98,8 +99,8 @@ trait Configurable extends ImplicitConversions {
val value = Config.getValueFromMap(defaults.toMap, ConfigValueIndex(m, p, key, freeVar))
if (value.isDefined) value.get.value else default
}
if (d == null) Config.global(m, p, key, freeVar = freeVar)
else Config.global(m, p, key, d, freeVar)
if (d == null) globalConfig(m, p, key, freeVar = freeVar)
else globalConfig(m, p, key, d, freeVar)
}
/**
......@@ -121,7 +122,7 @@ trait Configurable extends ImplicitConversions {
val m = if (submodule != null) submodule else configName
val p = path(s, l, submodule)
Config.global.contains(m, p, key, freeVar) || !(Config.getValueFromMap(defaults.toMap, ConfigValueIndex(m, p, key, freeVar)) == None)
globalConfig.contains(m, p, key, freeVar) || !(Config.getValueFromMap(defaults.toMap, ConfigValueIndex(m, p, key, freeVar)) == None)
}
}
}
......@@ -11,10 +11,10 @@ import org.testng.annotations.Test
*/
class ConfigurableTest extends TestNGSuite with Matchers {
@Test def testConfigurable: Unit = {
Config.global.map = Map()
Config.global.loadConfigFile(ConfigurableTest.file)
val classC = new ClassC
val classC = new ClassC {
override def configName = "classc"
override val globalConfig = new Config(ConfigurableTest.map)
}
classC.configPath shouldBe Nil
classC.configFullPath shouldBe List("classc")
......@@ -53,12 +53,12 @@ abstract class Cfg extends Configurable {
class ClassA(val root: Configurable) extends Cfg
class ClassB(val root: Configurable) extends Cfg {
val classA = new ClassA(this)
lazy val classA = new ClassA(this)
}
class ClassC(val root: Configurable) extends Cfg {
def this() = this(null)
val classB = new ClassB(this)
lazy val classB = new ClassB(this)
}
object ConfigurableTest {
......@@ -80,6 +80,4 @@ object ConfigurableTest {
)
)
)
val file = ConfigUtilsTest.writeTemp(ConfigUtils.mapToJson(map).spaces2)
}
Supports Markdown
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