tests/testthat/test_001_processor_incubatortemp.R

# Setup -------------------------------------------------------------------

hash <- function(dir) {
  new_files <- list.files(dir, full.names = FALSE, recursive = TRUE)
  x <- lapply(
    new_files,
    function(fn) {
      fnc <- file.path( dir, fn )
      f <- file( fnc, open = "rb" )
      hash <- as.character( openssl::sha256( f ) )
      close(f)
      rm(f)
      hash <- paste(hash, fn, sep = "  ")
    }
  )
  unlist(x)
}

raw <- system.file( "0.raw.data", package = "LEEF.measurement.incubatortemp")
pre_processed <- tempfile(pattern = "test_processed_")
extracted <- tempfile(pattern = "test_extracted_")

# Skip if data not there --------------------------------------------------

if (!file.exists(raw)) skip("Test data not available!")

# Test pre_processor ------------------------------------------------------

context("Test pre_processor_incubatortemp()")

test_that(
  "pre_processor_incubatortemp() runs without error",
  expect_error(
    object = suppressMessages( pre_processor_incubatortemp( input = raw, output = pre_processed ) ),
    regexp = NA
  )
)

test_that(
  "pre_processor_incubatortemp() returns correct result",
  expect_known_hash(
    hash( file.path(pre_processed, "incubatortemp") ),
    hash = "9842f0d8e8"
  )
)


# Test extractor ----------------------------------------------------------


context("Test extractor_incubatortemp()")

test_that(
  "extractor_incubatortemp() runs without error",
  expect_error(
    object = suppressMessages( extractor_incubatortemp( input = pre_processed, output = extracted) ),
    regexp = NA
  )
)

test_that(
  "extractor_incubatortemp() returns correct result",
  expect_known_hash(
    hash( file.path(extracted, "incubatortemp") ),
    hash = "05a445b058"
  )
)


# Teardown ----------------------------------------------------------------

unlink(pre_processed, recursive = TRUE, force = TRUE)
unlink(extracted, recursive = TRUE, force = TRUE)
LEEF-UZH/LEEF.measurement.incubatortemp documentation built on Sept. 27, 2020, 6:40 p.m.