Commit e5a21c98 authored by Ihrig, Arvid Conrad (ari)'s avatar Ihrig, Arvid Conrad (ari)
Browse files

Integrated Pipeline: code cleanup, removed no longer used case class, more matchers

parent 49164a53
package eu.nomad_lab.integrated_pipeline.messages
/**
* Summary of the file tree scanning (i.e. identification of potential calculations, not the
* actual parsing of these files)
*
* @param request the original scan request
* @param numCandidates number of identified candidate calculations in the file tree
*/
case class FileTreeScanResult(
request: FileTreeScanTask,
numCandidates: Long
)
......@@ -5,17 +5,17 @@ import eu.nomad_lab.TreeType.TreeType
import eu.nomad_lab.h5.CalculationH5
import eu.nomad_lab.integrated_pipeline.OutputType
import eu.nomad_lab.integrated_pipeline.OutputType.OutputType
import eu.nomad_lab.integrated_pipeline.messages.{ FileParsingTask, FileTreeScanTask }
import eu.nomad_lab.integrated_pipeline.messages.FileTreeScanTask
import eu.nomad_lab.meta.KnownMetaInfoEnvs
import eu.nomad_lab.{ H5Lib, JsonUtils, TreeType }
import integrated_pipeline_tests._
import org.scalatest.{ Assertion, Informer }
import org.scalatest.Assertions.succeed
import org.scalatest.{ Assertion, Informer }
import scala.collection.mutable
import scala.io.Source
package object integrated_pipeline_end_to_end_tests {
package object integrated_pipeline_end_to_end_tests extends TestDataBuilders {
implicit val metaInfo = KnownMetaInfoEnvs.all
......@@ -72,8 +72,8 @@ package object integrated_pipeline_end_to_end_tests {
def assertValidityOfGeneratedJsonFiles(sample: TestTreeData, treeTask: FileTreeScanTask,
tmpResultsFolder: Path): Assertion = {
sample.candidateCalculationsWithParsers.foreach { entry =>
val id = FileParsingTask(treeTask, Paths.get(entry._1), "").calculationGid
val fileName = s"$id.json"
val task = aFileParsingTask().withTreeTask(treeTask).withRelativePath(entry._1).build()
val fileName = s"${task.calculationGid}.json"
val location = tmpResultsFolder.resolve(fileName)
assert(
location.toFile.exists(),
......@@ -92,7 +92,8 @@ package object integrated_pipeline_end_to_end_tests {
def assertValidityOfGeneratedHDF5Files(sample: TestTreeData, treeTask: FileTreeScanTask,
tmpResultsFolder: Path): Assertion = {
sample.candidateCalculationsWithParsers.foreach { entry =>
val id = FileParsingTask(treeTask, Paths.get(entry._1), "").calculationGid
val task = aFileParsingTask().withTreeTask(treeTask).withRelativePath(entry._1).build()
val id = task.calculationGid
val fileName = s"$id.h5"
val location = tmpResultsFolder.resolve(fileName)
assert(
......
......@@ -4,7 +4,9 @@ import java.nio.file.{ Path, Paths }
import eu.nomad_lab.TreeType
import eu.nomad_lab.TreeType.TreeType
import eu.nomad_lab.integrated_pipeline.messages.{ FileParsingTask, FileParsingTaskEndTree, FileParsingTaskStartTree, FileTreeScanTask }
import eu.nomad_lab.integrated_pipeline.messages._
import eu.nomad_lab.parsers.ParseResult.ParseResult
import eu.nomad_lab.parsers._
import integrated_pipeline_tests.Builders._
trait TestDataBuilders {
......@@ -14,15 +16,16 @@ trait TestDataBuilders {
def aFileParsingTask() = BuilderFileParsingTask()
def aFileParsingTaskStartTree() = BuilderFileParsingTaskStartTree()
def aFileParsingTaskEndTree() = BuilderFileParsingTaskEndTree()
def anInMemoryResult() = BuilderInMemoryResult()
}
object Builders {
private def dummyFileTreeScanTask = FileTreeScanTask(Paths.get(""), TreeType.Directory)
private val unusedPath = Paths.get("")
case class BuilderFileTreeScanTask(
treeBasePath: Path = Paths.get(""),
treeType: TreeType = TreeType.Zip
treeBasePath: Path = unusedPath,
treeType: TreeType = TreeType.Directory
) {
def withBasePath(path: Path) = copy(treeBasePath = path)
......@@ -36,8 +39,8 @@ object Builders {
}
case class BuilderFileParsingTask(
private val treeTask: FileTreeScanTask = dummyFileTreeScanTask,
private val relativePath: Path = Paths.get(""),
private val treeTask: FileTreeScanTask = BuilderFileTreeScanTask().build(),
private val relativePath: Path = unusedPath,
private val parserName: String = "noParser"
) {
......@@ -54,7 +57,7 @@ object Builders {
}
case class BuilderFileParsingTaskStartTree(
private val treeTask: FileTreeScanTask = dummyFileTreeScanTask
private val treeTask: FileTreeScanTask = BuilderFileTreeScanTask().build()
) {
def withTreeTask(task: FileTreeScanTask) = copy(treeTask = task)
......@@ -63,7 +66,7 @@ object Builders {
}
case class BuilderFileParsingTaskEndTree(
private val treeTask: FileTreeScanTask = dummyFileTreeScanTask
private val treeTask: FileTreeScanTask = BuilderFileTreeScanTask().build()
) {
def withTreeTask(task: FileTreeScanTask) = copy(treeTask = task)
......@@ -71,4 +74,27 @@ object Builders {
def build() = FileParsingTaskEndTree(treeTask = treeTask)
}
case class BuilderInMemoryResult(
private val task: FileParsingTask = BuilderFileParsingTask().build(),
private val result: ParseResult = ParseResult.ParseSkipped,
private val start: Option[StartedParsingSession] = None,
private val events: Seq[ParseEvent] = Seq(),
private val end: Option[FinishedParsingSession] = None
) {
def withTask(newTask: FileParsingTask) = copy(task = newTask)
def withParseResult(newResult: ParseResult) = copy(result = newResult)
def withStartEvent(event: Option[StartedParsingSession]) = copy(start = event)
def withEvents(newEvents: Seq[ParseEvent]) = copy(events = newEvents)
def withFinishEvent(event: Option[FinishedParsingSession]) = copy(end = event)
def build() = InMemoryResult(
task = task,
result = result,
start = start,
events = events,
end = end
)
}
}
......@@ -2,10 +2,13 @@ package integrated_pipeline_tests
import java.nio.file.{ Path, Paths }
import eu.nomad_lab.integrated_pipeline.messages.{ FileParsingTask, FileParsingTaskSignal, FileTreeScanTask }
import eu.nomad_lab.integrated_pipeline.messages._
import eu.nomad_lab.parsers.ParseResult.ParseResult
import org.scalatest.matchers.{ HavePropertyMatchResult, HavePropertyMatcher }
trait MessageMatchers extends FileTreeTaskMatchers with FileParsingTaskMatchers
trait MessageMatchers
extends FileTreeTaskMatchers
with FileParsingTaskMatchers
object MessageMatchers extends MessageMatchers
......@@ -55,4 +58,50 @@ trait FileParsingTaskMatchers {
test.relativePath
)
}
}
trait FileParsingResultMatchers {
def treeTask(expectedValue: FileTreeScanTask) =
new HavePropertyMatcher[FileParsingResultSignal, FileTreeScanTask] {
def apply(test: FileParsingResultSignal) =
HavePropertyMatchResult(
test.treeTask == expectedValue,
"parent tree task",
expectedValue,
test.treeTask
)
}
def status(expectedValue: ParseResult) =
new HavePropertyMatcher[FileParsingResult, ParseResult] {
def apply(test: FileParsingResult) =
HavePropertyMatchResult(
test.result == expectedValue,
"parsing result status",
expectedValue,
test.result
)
}
def relativePath(expectedValue: Path) =
new HavePropertyMatcher[FileParsingResult, Path] {
def apply(test: FileParsingResult) =
HavePropertyMatchResult(
test.task.relativePath == expectedValue,
"relative file path",
expectedValue,
test.task.relativePath
)
}
def relativePath(expectedValue: String) =
new HavePropertyMatcher[FileParsingResult, Path] {
def apply(test: FileParsingResult) =
HavePropertyMatchResult(
test.task.relativePath == Paths.get(expectedValue),
"relative file path",
Paths.get(expectedValue),
test.task.relativePath
)
}
}
\ No newline at end of file
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