Skip to content

Commit

Permalink
Merge pull request #35 from RMI-PACTA/logger-updates
Browse files Browse the repository at this point in the history
Logger updates
  • Loading branch information
AlexAxthelm authored Nov 1, 2024
2 parents f39243d + 76c2346 commit 73c648c
Show file tree
Hide file tree
Showing 21 changed files with 14 additions and 288 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/setup.R
Original file line number Diff line number Diff line change
@@ -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()
)
15 changes: 0 additions & 15 deletions tests/testthat/test-check_dir_writable.R
Original file line number Diff line number Diff line change
@@ -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", {
Expand Down
15 changes: 0 additions & 15 deletions tests/testthat/test-check_file.R
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
16 changes: 0 additions & 16 deletions tests/testthat/test-check_io.R
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
15 changes: 0 additions & 15 deletions tests/testthat/test-create_manifest.R
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
15 changes: 0 additions & 15 deletions tests/testthat/test-export_manifest.R
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
15 changes: 0 additions & 15 deletions tests/testthat/test-get_environment.R
Original file line number Diff line number Diff line change
@@ -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(),
Expand Down
15 changes: 0 additions & 15 deletions tests/testthat/test-get_file_metadata.R
Original file line number Diff line number Diff line change
@@ -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")

Expand Down
15 changes: 0 additions & 15 deletions tests/testthat/test-get_git_info.R
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
15 changes: 0 additions & 15 deletions tests/testthat/test-get_individual_package_info.R
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
15 changes: 0 additions & 15 deletions tests/testthat/test-get_package_info.R
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
15 changes: 0 additions & 15 deletions tests/testthat/test-get_single_file_metadata.R
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
15 changes: 0 additions & 15 deletions tests/testthat/test-inherit_config.R
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
15 changes: 0 additions & 15 deletions tests/testthat/test-is_git_path.R
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
15 changes: 0 additions & 15 deletions tests/testthat/test-merge_lists.R
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
15 changes: 0 additions & 15 deletions tests/testthat/test-modify_list_element.R
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
15 changes: 0 additions & 15 deletions tests/testthat/test-modify_single_list_element.R
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
16 changes: 0 additions & 16 deletions tests/testthat/test-parse_params.R
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
15 changes: 0 additions & 15 deletions tests/testthat/test-parse_raw_params.R
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
15 changes: 0 additions & 15 deletions tests/testthat/test-un_asis.R
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit 73c648c

Please sign in to comment.