diff --git a/DESCRIPTION b/DESCRIPTION index 6127d24..f13eb05 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: pacta.workflow.utils Title: Utility functions for PACTA workflows -Version: 0.0.0.9014 +Version: 0.0.0.9015 Authors@R: c(person(given = "Alex", family = "Axthelm", diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R new file mode 100644 index 0000000..00770a9 --- /dev/null +++ b/tests/testthat/setup.R @@ -0,0 +1,13 @@ +## save current settings so that we can reset later + +## Logger Settings +# Set threshold to OFF, and capture previous state +logger_threshold <- logger::log_threshold("OFF") + +## Tear down function +withr::defer( + expr = { + logger::log_threshold(logger_threshold) + }, + envir = teardown_env() +) diff --git a/tests/testthat/test-check_dir_writable.R b/tests/testthat/test-check_dir_writable.R index f5c54a1..29f60ae 100644 --- a/tests/testthat/test-check_dir_writable.R +++ b/tests/testthat/test-check_dir_writable.R @@ -1,18 +1,3 @@ -## save current settings so that we can reset later -threshold <- logger::log_threshold() -appender <- logger::log_appender() -layout <- logger::log_layout() -on.exit({ - ## reset logger settings - logger::log_threshold(threshold) - logger::log_layout(layout) - logger::log_appender(appender) -}) - -logger::log_appender(logger::appender_stdout) -logger::log_threshold(logger::FATAL) -logger::log_layout(logger::layout_simple) - # TESTS BEGIN test_that("check_dir_writable correctly registers writable directory", { diff --git a/tests/testthat/test-check_file.R b/tests/testthat/test-check_file.R index ab00dd2..1deab88 100644 --- a/tests/testthat/test-check_file.R +++ b/tests/testthat/test-check_file.R @@ -1,18 +1,3 @@ -## save current settings so that we can reset later -threshold <- logger::log_threshold() -appender <- logger::log_appender() -layout <- logger::log_layout() -on.exit({ - ## reset logger settings - logger::log_threshold(threshold) - logger::log_layout(layout) - logger::log_appender(appender) -}) - -logger::log_appender(logger::appender_stdout) -logger::log_threshold(logger::FATAL) -logger::log_layout(logger::layout_simple) - test_that("check_dir_writable correctly identifies missing files", { test_file <- withr::local_tempfile() expect_warning( diff --git a/tests/testthat/test-check_io.R b/tests/testthat/test-check_io.R index 7ed7c2e..93fd2a0 100644 --- a/tests/testthat/test-check_io.R +++ b/tests/testthat/test-check_io.R @@ -1,19 +1,3 @@ -## save current settings so that we can reset later -threshold <- logger::log_threshold() -appender <- logger::log_appender() -layout <- logger::log_layout() -on.exit({ - ## reset logger settings - logger::log_threshold(threshold) - logger::log_layout(layout) - logger::log_appender(appender) -}) - -logger::log_appender(logger::appender_stdout) -logger::log_threshold(logger::FATAL) -logger::log_layout(logger::layout_simple) - - missing_file <- withr::local_tempfile() file_is_dir <- withr::local_tempdir() empty_file <- withr::local_tempfile() diff --git a/tests/testthat/test-create_manifest.R b/tests/testthat/test-create_manifest.R index 20e2fb3..e400e80 100644 --- a/tests/testthat/test-create_manifest.R +++ b/tests/testthat/test-create_manifest.R @@ -1,18 +1,3 @@ -## save current settings so that we can reset later -threshold <- logger::log_threshold() -appender <- logger::log_appender() -layout <- logger::log_layout() -on.exit({ - ## reset logger settings - logger::log_threshold(threshold) - logger::log_layout(layout) - logger::log_appender(appender) -}) - -logger::log_appender(logger::appender_stdout) -logger::log_threshold(logger::FATAL) -logger::log_layout(logger::layout_simple) - test_that("create_manifest with minimal arguments", { suppressWarnings({ manifest <- create_manifest( diff --git a/tests/testthat/test-export_manifest.R b/tests/testthat/test-export_manifest.R index 59dcfc4..ff439bb 100644 --- a/tests/testthat/test-export_manifest.R +++ b/tests/testthat/test-export_manifest.R @@ -1,18 +1,3 @@ -## save current settings so that we can reset later -threshold <- logger::log_threshold() -appender <- logger::log_appender() -layout <- logger::log_layout() -on.exit({ - ## reset logger settings - logger::log_threshold(threshold) - logger::log_layout(layout) - logger::log_appender(appender) -}) - -logger::log_appender(logger::appender_stdout) -logger::log_threshold(logger::FATAL) -logger::log_layout(logger::layout_simple) - test_that("export_manifest with minimal arguments", { manifest_file <- withr::local_tempfile(fileext = ".json") suppressWarnings({ diff --git a/tests/testthat/test-get_environment.R b/tests/testthat/test-get_environment.R index 20ea5f4..ac744e7 100644 --- a/tests/testthat/test-get_environment.R +++ b/tests/testthat/test-get_environment.R @@ -1,18 +1,3 @@ -## save current settings so that we can reset later -threshold <- logger::log_threshold() -appender <- logger::log_appender() -layout <- logger::log_layout() -on.exit({ - ## reset logger settings - logger::log_threshold(threshold) - logger::log_layout(layout) - logger::log_appender(appender) -}) - -logger::log_appender(logger::appender_stdout) -logger::log_threshold(logger::FATAL) -logger::log_layout(logger::layout_simple) - test_that("get_r_session_info returns expected values", { expect_identical( get_r_session_info(), diff --git a/tests/testthat/test-get_file_metadata.R b/tests/testthat/test-get_file_metadata.R index 580f751..2863bb3 100644 --- a/tests/testthat/test-get_file_metadata.R +++ b/tests/testthat/test-get_file_metadata.R @@ -1,18 +1,3 @@ -## save current settings so that we can reset later -threshold <- logger::log_threshold() -appender <- logger::log_appender() -layout <- logger::log_layout() -on.exit({ - ## reset logger settings - logger::log_threshold(threshold) - logger::log_layout(layout) - logger::log_appender(appender) -}) - -logger::log_appender(logger::appender_stdout) -logger::log_threshold(logger::FATAL) -logger::log_layout(logger::layout_simple) - # setup test_time <- as.POSIXct("2020-01-01T12:34:56+00:00") diff --git a/tests/testthat/test-get_git_info.R b/tests/testthat/test-get_git_info.R index 639d37e..b845c02 100644 --- a/tests/testthat/test-get_git_info.R +++ b/tests/testthat/test-get_git_info.R @@ -1,18 +1,3 @@ -## save current settings so that we can reset later -threshold <- logger::log_threshold() -appender <- logger::log_appender() -layout <- logger::log_layout() -on.exit({ - ## reset logger settings - logger::log_threshold(threshold) - logger::log_layout(layout) - logger::log_appender(appender) -}) - -logger::log_appender(logger::appender_stdout) -logger::log_threshold(logger::FATAL) -logger::log_layout(logger::layout_simple) - # TESTS BEGIN test_that("get_git_info processes non-git-repo correctly", { test_dir <- withr::local_tempdir() diff --git a/tests/testthat/test-get_individual_package_info.R b/tests/testthat/test-get_individual_package_info.R index 2a46010..3a5f532 100644 --- a/tests/testthat/test-get_individual_package_info.R +++ b/tests/testthat/test-get_individual_package_info.R @@ -1,18 +1,3 @@ -## save current settings so that we can reset later -threshold <- logger::log_threshold() -appender <- logger::log_appender() -layout <- logger::log_layout() -on.exit({ - ## reset logger settings - logger::log_threshold(threshold) - logger::log_layout(layout) - logger::log_appender(appender) -}) - -logger::log_appender(logger::appender_stdout) -logger::log_threshold(logger::FATAL) -logger::log_layout(logger::layout_simple) - expect_package_info <- function( package_info, package_identical, diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index 26c9cfe..0eae943 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -1,18 +1,3 @@ -## save current settings so that we can reset later -threshold <- logger::log_threshold() -appender <- logger::log_appender() -layout <- logger::log_layout() -on.exit({ - ## reset logger settings - logger::log_threshold(threshold) - logger::log_layout(layout) - logger::log_appender(appender) -}) - -logger::log_appender(logger::appender_stdout) -logger::log_threshold(logger::FATAL) -logger::log_layout(logger::layout_simple) - expect_warning_if_any_pkgload <- function(object, regexp) { attached_pkgs <- names(utils::sessionInfo()[["otherPkgs"]]) has_pkgload <- any( diff --git a/tests/testthat/test-get_single_file_metadata.R b/tests/testthat/test-get_single_file_metadata.R index af1f62d..8a11ba8 100644 --- a/tests/testthat/test-get_single_file_metadata.R +++ b/tests/testthat/test-get_single_file_metadata.R @@ -1,18 +1,3 @@ -## save current settings so that we can reset later -threshold <- logger::log_threshold() -appender <- logger::log_appender() -layout <- logger::log_layout() -on.exit({ - ## reset logger settings - logger::log_threshold(threshold) - logger::log_layout(layout) - logger::log_appender(appender) -}) - -logger::log_appender(logger::appender_stdout) -logger::log_threshold(logger::FATAL) -logger::log_layout(logger::layout_simple) - test_that("get_single_file_metadata processes CSV tables correctly", { testfile <- withr::local_tempfile(fileext = ".csv") write.csv(mtcars, testfile, row.names = FALSE) diff --git a/tests/testthat/test-inherit_config.R b/tests/testthat/test-inherit_config.R index ffa59fb..2e26661 100644 --- a/tests/testthat/test-inherit_config.R +++ b/tests/testthat/test-inherit_config.R @@ -1,18 +1,3 @@ -## save current settings so that we can reset later -threshold <- logger::log_threshold() -appender <- logger::log_appender() -layout <- logger::log_layout() -on.exit({ - ## reset logger settings - logger::log_threshold(threshold) - logger::log_layout(layout) - logger::log_appender(appender) -}) - -logger::log_appender(logger::appender_stdout) -logger::log_threshold(logger::FATAL) -logger::log_layout(logger::layout_simple) - test_that("No inheritence", { params <- list( foo = 1L, diff --git a/tests/testthat/test-is_git_path.R b/tests/testthat/test-is_git_path.R index eabff57..b7e3d41 100644 --- a/tests/testthat/test-is_git_path.R +++ b/tests/testthat/test-is_git_path.R @@ -1,18 +1,3 @@ -## save current settings so that we can reset later -threshold <- logger::log_threshold() -appender <- logger::log_appender() -layout <- logger::log_layout() -on.exit({ - ## reset logger settings - logger::log_threshold(threshold) - logger::log_layout(layout) - logger::log_appender(appender) -}) - -logger::log_appender(logger::appender_stdout) -logger::log_threshold(logger::FATAL) -logger::log_layout(logger::layout_simple) - # # TESTS BEGIN test_that("is_git_path processes non-existing directory correctly", { test_dir <- withr::local_tempdir() diff --git a/tests/testthat/test-merge_lists.R b/tests/testthat/test-merge_lists.R index e9521eb..dcb8b75 100644 --- a/tests/testthat/test-merge_lists.R +++ b/tests/testthat/test-merge_lists.R @@ -1,18 +1,3 @@ -## save current settings so that we can reset later -threshold <- logger::log_threshold() -appender <- logger::log_appender() -layout <- logger::log_layout() -on.exit({ - ## reset logger settings - logger::log_threshold(threshold) - logger::log_layout(layout) - logger::log_appender(appender) -}) - -logger::log_appender(logger::appender_stdout) -logger::log_threshold(logger::FATAL) -logger::log_layout(logger::layout_simple) - simple_list <- list( a = 1L, b = "base string", diff --git a/tests/testthat/test-modify_list_element.R b/tests/testthat/test-modify_list_element.R index 16bb014..91de225 100644 --- a/tests/testthat/test-modify_list_element.R +++ b/tests/testthat/test-modify_list_element.R @@ -1,18 +1,3 @@ -## save current settings so that we can reset later -threshold <- logger::log_threshold() -appender <- logger::log_appender() -layout <- logger::log_layout() -on.exit({ - ## reset logger settings - logger::log_threshold(threshold) - logger::log_layout(layout) - logger::log_appender(appender) -}) - -logger::log_appender(logger::appender_stdout) -logger::log_threshold(logger::FATAL) -logger::log_layout(logger::layout_simple) - test_that("modify_list_element correctly modifies a flat list", { test_list <- list(a = 1L, b = 2.2, c = "a") results <- modify_list_element( diff --git a/tests/testthat/test-modify_single_list_element.R b/tests/testthat/test-modify_single_list_element.R index 04f903f..7e64548 100644 --- a/tests/testthat/test-modify_single_list_element.R +++ b/tests/testthat/test-modify_single_list_element.R @@ -1,18 +1,3 @@ -## save current settings so that we can reset later -threshold <- logger::log_threshold() -appender <- logger::log_appender() -layout <- logger::log_layout() -on.exit({ - ## reset logger settings - logger::log_threshold(threshold) - logger::log_layout(layout) - logger::log_appender(appender) -}) - -logger::log_appender(logger::appender_stdout) -logger::log_threshold(logger::FATAL) -logger::log_layout(logger::layout_simple) - test_that("modify_single_list_element correctly modifies a flat list", { test_list <- list(a = 1L, b = 2.2, c = "a") results <- modify_single_list_element( diff --git a/tests/testthat/test-parse_params.R b/tests/testthat/test-parse_params.R index 64a806f..df49b09 100644 --- a/tests/testthat/test-parse_params.R +++ b/tests/testthat/test-parse_params.R @@ -1,19 +1,3 @@ -## save current settings so that we can reset later -threshold <- logger::log_threshold() -appender <- logger::log_appender() -layout <- logger::log_layout() -on.exit({ - ## reset logger settings - logger::log_threshold(threshold) - logger::log_layout(layout) - logger::log_appender(appender) -}) - -logger::log_appender(logger::appender_stdout) -logger::log_threshold(logger::FATAL) -logger::log_layout(logger::layout_simple) - - test_that("No inheritence, pass as string", { json_string <- '{ "id": 1, diff --git a/tests/testthat/test-parse_raw_params.R b/tests/testthat/test-parse_raw_params.R index 3d78b0e..1d0433f 100644 --- a/tests/testthat/test-parse_raw_params.R +++ b/tests/testthat/test-parse_raw_params.R @@ -1,18 +1,3 @@ -## save current settings so that we can reset later -threshold <- logger::log_threshold() -appender <- logger::log_appender() -layout <- logger::log_layout() -on.exit({ - ## reset logger settings - logger::log_threshold(threshold) - logger::log_layout(layout) - logger::log_appender(appender) -}) - -logger::log_appender(logger::appender_stdout) -logger::log_threshold(logger::FATAL) -logger::log_layout(logger::layout_simple) - test_that("No inheritence, no raw param validation, pass as string", { json_string <- '{ "id": 1, diff --git a/tests/testthat/test-un_asis.R b/tests/testthat/test-un_asis.R index aa6ec56..5f22f0e 100644 --- a/tests/testthat/test-un_asis.R +++ b/tests/testthat/test-un_asis.R @@ -1,18 +1,3 @@ -## save current settings so that we can reset later -threshold <- logger::log_threshold() -appender <- logger::log_appender() -layout <- logger::log_layout() -on.exit({ - ## reset logger settings - logger::log_threshold(threshold) - logger::log_layout(layout) - logger::log_appender(appender) -}) - -logger::log_appender(logger::appender_stdout) -logger::log_threshold(logger::FATAL) -logger::log_layout(logger::layout_simple) - test_that("un_asis does not alter objects without AsIs class", { x <- rnorm(10L) results <- un_asis(x)