From 24a1f2b8a348390a54f4d770443c3eea82057a4b Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar (UMass)" Date: Tue, 29 Oct 2024 13:41:20 -0700 Subject: [PATCH 01/12] add tests for running custom checks outside of hub root --- tests/testthat/helper-custom-fns.R | 28 +++++++++++++++++++++ tests/testthat/test-execute_custom_checks.R | 11 ++++++++ 2 files changed, 39 insertions(+) diff --git a/tests/testthat/helper-custom-fns.R b/tests/testthat/helper-custom-fns.R index 0f26133b..06a38755 100644 --- a/tests/testthat/helper-custom-fns.R +++ b/tests/testthat/helper-custom-fns.R @@ -11,3 +11,31 @@ test_custom_checks_caller <- function( # nolint end execute_custom_checks(validations_cfg_path = validations_cfg_path) } + +stand_up_custom_check_hub <- function( + # nolint start + hub_path = system.file("testhubs/flusight", package = "hubValidations"), + new_path = NULL, + check_path = testthat::test_path("testdata/src/R/src_check_works.R")) { + if (is.null(new_path)) { + return() + } + fs::dir_copy(hub_path, new_path) + new_path <- fs::path(new_path, fs::path_file(hub_path)) + withr::with_dir(new_path, create_custom_check("test-check")) + fs::file_copy(check_path, + fs::path(new_path, "src/validations/R/test-check.R"), + overwrite = TRUE + ) + x <- c( + 'default:', + ' test_custom_checks_caller:', + ' src_check_works:', + ' fn: "src_check_works"', + ' source: src/validations/R/test-check.R', + ' args:', + ' extra_msg: "Extra arguments passed"' + ) + writeLines(x, fs::path(new_path, "hub-config", "validations.yml")) + return(new_path) +} diff --git a/tests/testthat/test-execute_custom_checks.R b/tests/testthat/test-execute_custom_checks.R index d59dd446..17e80708 100644 --- a/tests/testthat/test-execute_custom_checks.R +++ b/tests/testthat/test-execute_custom_checks.R @@ -24,6 +24,17 @@ test_that("execute_custom_checks works", { ) }) +test_that("execute_custom_checks works from a separate directory", { + tmp <- withr::local_tempdir() + hub <- stand_up_custom_check_hub(new_path = tmp) + + expect_no_error({ + withr::with_tempdir({ + test_custom_checks_caller(hub_path = hub) + }) + }) +}) + test_that("execute_custom_checks sourcing functions from scripts works", { expect_snapshot( From 9cc2cceb594721b8d2cc6ea2d5954ffedd7aba19 Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar (UMass)" Date: Tue, 29 Oct 2024 13:41:43 -0700 Subject: [PATCH 02/12] add proposed fix for running checks outside of hub root --- R/exec_cfg_check.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/exec_cfg_check.R b/R/exec_cfg_check.R index 059646fd..42dce380 100644 --- a/R/exec_cfg_check.R +++ b/R/exec_cfg_check.R @@ -6,7 +6,9 @@ exec_cfg_check <- function(check_name, validations_cfg, caller_env, caller_call) ) } else if (!is.null(fn_cfg[["source"]])) { # TODO Validate source script. - source(fn_cfg[["source"]], local = TRUE) + hub_path <- rlang::env_get(env = caller_env, nm = "hub_path") + src <- fs::path(hub_path, fn_cfg[["source"]]) + source(src, local = TRUE) fn <- get(fn_cfg[["fn"]]) } From c44eab92b28d90d3973ca4004939d71499df8abc Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar (UMass)" Date: Tue, 29 Oct 2024 14:56:50 -0700 Subject: [PATCH 03/12] rewrite helper to allow for multiple checks --- tests/testthat/helper-custom-fns.R | 36 +++++++++++++++++------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/tests/testthat/helper-custom-fns.R b/tests/testthat/helper-custom-fns.R index 06a38755..4bf9604e 100644 --- a/tests/testthat/helper-custom-fns.R +++ b/tests/testthat/helper-custom-fns.R @@ -16,26 +16,32 @@ stand_up_custom_check_hub <- function( # nolint start hub_path = system.file("testhubs/flusight", package = "hubValidations"), new_path = NULL, - check_path = testthat::test_path("testdata/src/R/src_check_works.R")) { + check_path = testthat::test_path("testdata/src/R/src_check_works.R"), + args = list("src_check_works" = list(extra_msg = 'Extra arguments passed')) + ) { if (is.null(new_path)) { return() } fs::dir_copy(hub_path, new_path) new_path <- fs::path(new_path, fs::path_file(hub_path)) - withr::with_dir(new_path, create_custom_check("test-check")) - fs::file_copy(check_path, - fs::path(new_path, "src/validations/R/test-check.R"), - overwrite = TRUE + script_path <- fs::path(new_path, "src/validations/R/test-check.R") + fs::dir_create(fs::path_dir(script_path)) + fs::file_copy(check_path, script_path, overwrite = TRUE) + n <- seq_along(args) + fun <- lapply(n, function(fn) { + list( + fn = names(args)[[fn]], + source = fs::path_rel(script_path, start = new_path), + args = args[[fn]] + ) + }) + names(fun) <- paste0("check_", n) + yml <- list( + "default" = list( + "test_custom_checks_caller" = fun + ) ) - x <- c( - 'default:', - ' test_custom_checks_caller:', - ' src_check_works:', - ' fn: "src_check_works"', - ' source: src/validations/R/test-check.R', - ' args:', - ' extra_msg: "Extra arguments passed"' - ) - writeLines(x, fs::path(new_path, "hub-config", "validations.yml")) + # nolint end + writeLines(yaml::as.yaml(yml), fs::path(new_path, "hub-config", "validations.yml")) return(new_path) } From cdadb90f74501eb53576ab4b754cd3c0e49325f8 Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar (UMass)" Date: Tue, 29 Oct 2024 14:57:24 -0700 Subject: [PATCH 04/12] refactor custom check tests --- .../testthat/_snaps/execute_custom_checks.md | 5 +- tests/testthat/test-execute_custom_checks.R | 57 +++++++++---------- 2 files changed, 29 insertions(+), 33 deletions(-) diff --git a/tests/testthat/_snaps/execute_custom_checks.md b/tests/testthat/_snaps/execute_custom_checks.md index 6efbfd00..4d162ebb 100644 --- a/tests/testthat/_snaps/execute_custom_checks.md +++ b/tests/testthat/_snaps/execute_custom_checks.md @@ -32,13 +32,12 @@ # execute_custom_checks sourcing functions from scripts works Code - test_custom_checks_caller(validations_cfg_path = testthat::test_path("testdata", - "config", "validations-src.yml")) + print(res) Message -- 2023-05-08-hub-ensemble.parquet ---- - i [src_check_works]: Sourcing custom functions WORKS! Also "Extra arguments passed"!! + i [check_1]: Sourcing custom functions WORKS! Also "Extra arguments passed"!! # execute_custom_checks return early when appropriate diff --git a/tests/testthat/test-execute_custom_checks.R b/tests/testthat/test-execute_custom_checks.R index 17e80708..b93b6c95 100644 --- a/tests/testthat/test-execute_custom_checks.R +++ b/tests/testthat/test-execute_custom_checks.R @@ -24,66 +24,63 @@ test_that("execute_custom_checks works", { ) }) -test_that("execute_custom_checks works from a separate directory", { +test_that("execute_custom_checks sourcing functions from scripts works", { tmp <- withr::local_tempdir() hub <- stand_up_custom_check_hub(new_path = tmp) expect_no_error({ withr::with_tempdir({ - test_custom_checks_caller(hub_path = hub) + res <- test_custom_checks_caller(hub_path = hub) }) }) -}) -test_that("execute_custom_checks sourcing functions from scripts works", { - - expect_snapshot( - test_custom_checks_caller( - validations_cfg_path = testthat::test_path( - "testdata", - "config", - "validations-src.yml" - ) - ) - ) + expect_snapshot(print(res)) }) + test_that("execute_custom_checks return early when appropriate", { # When the first custom check returns an check_error class object, custom check # execution should return early - early_ret_custom <- test_custom_checks_caller( - validations_cfg_path = testthat::test_path( - "testdata", - "config", - "validations-early-ret.yml" + tmp1 <- withr::local_tempdir() + the_check <- testthat::test_path("testdata/src/R/src_simple_example_check.R") + hub1 <- stand_up_custom_check_hub(new_path = tmp1, + check_path = the_check, + args = list( + simple_example_check = list(check = FALSE, error = TRUE), + simple_example_check = list(check = TRUE, error = FALSE) ) ) + early_ret_custom <- test_custom_checks_caller(hub_path = hub1) expect_snapshot(early_ret_custom) expect_length(early_ret_custom, 1L) expect_false("check_2" %in% names(early_ret_custom)) # Same when the first custom check returns an exec_error class object - early_ret_exec_error <- test_custom_checks_caller( - validations_cfg_path = testthat::test_path( - "testdata", - "config", - "validations-exec-error.yml" + tmp2 <- withr::local_tempdir() + hub2 <- stand_up_custom_check_hub(new_path = tmp2, + check_path = the_check, + args = list( + simple_example_check = list(check = FALSE, error = TRUE, exec_error = TRUE), + simple_example_check = list(check = TRUE, error = FALSE) ) ) + early_ret_exec_error <- test_custom_checks_caller(hub2) expect_snapshot(early_ret_exec_error) expect_length(early_ret_exec_error, 1L) - expect_false("check_2" %in% names(early_ret_exec_error)) + expect_false("check_2" %in% names(early_ret_custom)) # When the first custom check returns an check_failure class object, custom check # execution should proceed - no_early_ret_custom <- test_custom_checks_caller( - validations_cfg_path = testthat::test_path( - "testdata", - "config", - "validations-no-early-ret.yml" + tmp3 <- withr::local_tempdir() + hub3 <- stand_up_custom_check_hub(new_path = tmp3, + check_path = the_check, + args = list( + simple_example_check = list(check = FALSE, error = FALSE), + simple_example_check = list(check = TRUE, error = FALSE) ) ) + no_early_ret_custom <- test_custom_checks_caller(hub3) expect_snapshot(no_early_ret_custom) expect_length(no_early_ret_custom, 2L) expect_true("check_2" %in% names(no_early_ret_custom)) From 15a0939932e7aa487e51ca641f5659b303cd3a54 Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar (UMass)" Date: Tue, 29 Oct 2024 15:02:58 -0700 Subject: [PATCH 05/12] remove superseded validations test files --- .../testdata/config/validations-early-ret.yml | 14 -------------- .../testdata/config/validations-exec-error.yml | 15 --------------- .../testdata/config/validations-no-early-ret.yml | 14 -------------- .../testthat/testdata/config/validations-src.yml | 7 ------- 4 files changed, 50 deletions(-) delete mode 100644 tests/testthat/testdata/config/validations-early-ret.yml delete mode 100644 tests/testthat/testdata/config/validations-exec-error.yml delete mode 100644 tests/testthat/testdata/config/validations-no-early-ret.yml delete mode 100644 tests/testthat/testdata/config/validations-src.yml diff --git a/tests/testthat/testdata/config/validations-early-ret.yml b/tests/testthat/testdata/config/validations-early-ret.yml deleted file mode 100644 index b7d12bc9..00000000 --- a/tests/testthat/testdata/config/validations-early-ret.yml +++ /dev/null @@ -1,14 +0,0 @@ -default: - test_custom_checks_caller: - check_1: - fn: "simple_example_check" - source: !expr testthat::test_path("testdata/src/R/src_simple_example_check.R") - args: - check: FALSE - error: TRUE - check_2: - fn: "simple_example_check" - source: !expr testthat::test_path("testdata/src/R/src_simple_example_check.R") - args: - check: TRUE - error: FALSE diff --git a/tests/testthat/testdata/config/validations-exec-error.yml b/tests/testthat/testdata/config/validations-exec-error.yml deleted file mode 100644 index 8232987f..00000000 --- a/tests/testthat/testdata/config/validations-exec-error.yml +++ /dev/null @@ -1,15 +0,0 @@ -default: - test_custom_checks_caller: - check_1: - fn: "simple_example_check" - source: !expr testthat::test_path("testdata/src/R/src_simple_example_check.R") - args: - check: FALSE - error: TRUE - exec_error: TRUE - check_2: - fn: "simple_example_check" - source: !expr testthat::test_path("testdata/src/R/src_simple_example_check.R") - args: - check: TRUE - error: FALSE diff --git a/tests/testthat/testdata/config/validations-no-early-ret.yml b/tests/testthat/testdata/config/validations-no-early-ret.yml deleted file mode 100644 index 3e729c49..00000000 --- a/tests/testthat/testdata/config/validations-no-early-ret.yml +++ /dev/null @@ -1,14 +0,0 @@ -default: - test_custom_checks_caller: - check_1: - fn: "simple_example_check" - source: !expr testthat::test_path("testdata/src/R/src_simple_example_check.R") - args: - check: FALSE - error: FALSE - check_2: - fn: "simple_example_check" - source: !expr testthat::test_path("testdata/src/R/src_simple_example_check.R") - args: - check: TRUE - error: FALSE diff --git a/tests/testthat/testdata/config/validations-src.yml b/tests/testthat/testdata/config/validations-src.yml deleted file mode 100644 index c23aa4ba..00000000 --- a/tests/testthat/testdata/config/validations-src.yml +++ /dev/null @@ -1,7 +0,0 @@ -default: - test_custom_checks_caller: - src_check_works: - fn: "src_check_works" - source: !expr testthat::test_path("testdata/src/R/src_check_works.R") - args: - extra_msg: "Extra arguments passed" From 70d20ffade122f89014ae02432681e3078f3dbd5 Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar (UMass)" Date: Thu, 31 Oct 2024 07:44:53 -0700 Subject: [PATCH 06/12] Revert "remove superseded validations test files" This reverts commit 15a0939932e7aa487e51ca641f5659b303cd3a54. --- .../testdata/config/validations-early-ret.yml | 14 ++++++++++++++ .../testdata/config/validations-exec-error.yml | 15 +++++++++++++++ .../testdata/config/validations-no-early-ret.yml | 14 ++++++++++++++ .../testthat/testdata/config/validations-src.yml | 7 +++++++ 4 files changed, 50 insertions(+) create mode 100644 tests/testthat/testdata/config/validations-early-ret.yml create mode 100644 tests/testthat/testdata/config/validations-exec-error.yml create mode 100644 tests/testthat/testdata/config/validations-no-early-ret.yml create mode 100644 tests/testthat/testdata/config/validations-src.yml diff --git a/tests/testthat/testdata/config/validations-early-ret.yml b/tests/testthat/testdata/config/validations-early-ret.yml new file mode 100644 index 00000000..b7d12bc9 --- /dev/null +++ b/tests/testthat/testdata/config/validations-early-ret.yml @@ -0,0 +1,14 @@ +default: + test_custom_checks_caller: + check_1: + fn: "simple_example_check" + source: !expr testthat::test_path("testdata/src/R/src_simple_example_check.R") + args: + check: FALSE + error: TRUE + check_2: + fn: "simple_example_check" + source: !expr testthat::test_path("testdata/src/R/src_simple_example_check.R") + args: + check: TRUE + error: FALSE diff --git a/tests/testthat/testdata/config/validations-exec-error.yml b/tests/testthat/testdata/config/validations-exec-error.yml new file mode 100644 index 00000000..8232987f --- /dev/null +++ b/tests/testthat/testdata/config/validations-exec-error.yml @@ -0,0 +1,15 @@ +default: + test_custom_checks_caller: + check_1: + fn: "simple_example_check" + source: !expr testthat::test_path("testdata/src/R/src_simple_example_check.R") + args: + check: FALSE + error: TRUE + exec_error: TRUE + check_2: + fn: "simple_example_check" + source: !expr testthat::test_path("testdata/src/R/src_simple_example_check.R") + args: + check: TRUE + error: FALSE diff --git a/tests/testthat/testdata/config/validations-no-early-ret.yml b/tests/testthat/testdata/config/validations-no-early-ret.yml new file mode 100644 index 00000000..3e729c49 --- /dev/null +++ b/tests/testthat/testdata/config/validations-no-early-ret.yml @@ -0,0 +1,14 @@ +default: + test_custom_checks_caller: + check_1: + fn: "simple_example_check" + source: !expr testthat::test_path("testdata/src/R/src_simple_example_check.R") + args: + check: FALSE + error: FALSE + check_2: + fn: "simple_example_check" + source: !expr testthat::test_path("testdata/src/R/src_simple_example_check.R") + args: + check: TRUE + error: FALSE diff --git a/tests/testthat/testdata/config/validations-src.yml b/tests/testthat/testdata/config/validations-src.yml new file mode 100644 index 00000000..c23aa4ba --- /dev/null +++ b/tests/testthat/testdata/config/validations-src.yml @@ -0,0 +1,7 @@ +default: + test_custom_checks_caller: + src_check_works: + fn: "src_check_works" + source: !expr testthat::test_path("testdata/src/R/src_check_works.R") + args: + extra_msg: "Extra arguments passed" From e192fcb403a9d6068987bb2c80e875034a14d04c Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar (UMass)" Date: Thu, 31 Oct 2024 07:49:50 -0700 Subject: [PATCH 07/12] update path in test yamls Using the dynamic test path meant that we could not test these files as they existed in a hub. With this pattern, we can copy the test files over instead of having to do the cumbersome programmatic generation. Less code == better code --- tests/testthat/testdata/config/validations-early-ret.yml | 4 ++-- tests/testthat/testdata/config/validations-exec-error.yml | 4 ++-- tests/testthat/testdata/config/validations-no-early-ret.yml | 4 ++-- tests/testthat/testdata/config/validations-src.yml | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/testthat/testdata/config/validations-early-ret.yml b/tests/testthat/testdata/config/validations-early-ret.yml index b7d12bc9..83fb6483 100644 --- a/tests/testthat/testdata/config/validations-early-ret.yml +++ b/tests/testthat/testdata/config/validations-early-ret.yml @@ -2,13 +2,13 @@ default: test_custom_checks_caller: check_1: fn: "simple_example_check" - source: !expr testthat::test_path("testdata/src/R/src_simple_example_check.R") + source: "src/R/validatons/src_simple_example_check.R" args: check: FALSE error: TRUE check_2: fn: "simple_example_check" - source: !expr testthat::test_path("testdata/src/R/src_simple_example_check.R") + source: "src/R/validatons/src_simple_example_check.R" args: check: TRUE error: FALSE diff --git a/tests/testthat/testdata/config/validations-exec-error.yml b/tests/testthat/testdata/config/validations-exec-error.yml index 8232987f..f616058c 100644 --- a/tests/testthat/testdata/config/validations-exec-error.yml +++ b/tests/testthat/testdata/config/validations-exec-error.yml @@ -2,14 +2,14 @@ default: test_custom_checks_caller: check_1: fn: "simple_example_check" - source: !expr testthat::test_path("testdata/src/R/src_simple_example_check.R") + source: "src/validations/R/src_simple_example_check.R" args: check: FALSE error: TRUE exec_error: TRUE check_2: fn: "simple_example_check" - source: !expr testthat::test_path("testdata/src/R/src_simple_example_check.R") + source: "src/validations/R/src_simple_example_check.R" args: check: TRUE error: FALSE diff --git a/tests/testthat/testdata/config/validations-no-early-ret.yml b/tests/testthat/testdata/config/validations-no-early-ret.yml index 3e729c49..a6e5ff0e 100644 --- a/tests/testthat/testdata/config/validations-no-early-ret.yml +++ b/tests/testthat/testdata/config/validations-no-early-ret.yml @@ -2,13 +2,13 @@ default: test_custom_checks_caller: check_1: fn: "simple_example_check" - source: !expr testthat::test_path("testdata/src/R/src_simple_example_check.R") + source: "src/validations/R/src_simple_example_check.R" args: check: FALSE error: FALSE check_2: fn: "simple_example_check" - source: !expr testthat::test_path("testdata/src/R/src_simple_example_check.R") + source: "src/validations/R/src_simple_example_check.R" args: check: TRUE error: FALSE diff --git a/tests/testthat/testdata/config/validations-src.yml b/tests/testthat/testdata/config/validations-src.yml index c23aa4ba..162a58e0 100644 --- a/tests/testthat/testdata/config/validations-src.yml +++ b/tests/testthat/testdata/config/validations-src.yml @@ -2,6 +2,6 @@ default: test_custom_checks_caller: src_check_works: fn: "src_check_works" - source: !expr testthat::test_path("testdata/src/R/src_check_works.R") + source: "src/validations/R/src_check_works.R" args: extra_msg: "Extra arguments passed" From 4761357afd465b85bca8e69691ebb20f065d9b06 Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar (UMass)" Date: Thu, 31 Oct 2024 08:21:19 -0700 Subject: [PATCH 08/12] dang fingies missspelling fings --- tests/testthat/testdata/config/validations-early-ret.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/testdata/config/validations-early-ret.yml b/tests/testthat/testdata/config/validations-early-ret.yml index 83fb6483..4402822b 100644 --- a/tests/testthat/testdata/config/validations-early-ret.yml +++ b/tests/testthat/testdata/config/validations-early-ret.yml @@ -2,13 +2,13 @@ default: test_custom_checks_caller: check_1: fn: "simple_example_check" - source: "src/R/validatons/src_simple_example_check.R" + source: "src/validations/R/src_simple_example_check.R" args: check: FALSE error: TRUE check_2: fn: "simple_example_check" - source: "src/R/validatons/src_simple_example_check.R" + source: "src/validations/R/src_simple_example_check.R" args: check: TRUE error: FALSE From 65e690d369b9d99a9629af838da0f83f5935706c Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar (UMass)" Date: Thu, 31 Oct 2024 08:23:53 -0700 Subject: [PATCH 09/12] simplify helpers --- tests/testthat/helper-custom-fns.R | 35 ++++++++++++++---------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/tests/testthat/helper-custom-fns.R b/tests/testthat/helper-custom-fns.R index 4bf9604e..9d913a4d 100644 --- a/tests/testthat/helper-custom-fns.R +++ b/tests/testthat/helper-custom-fns.R @@ -16,32 +16,29 @@ stand_up_custom_check_hub <- function( # nolint start hub_path = system.file("testhubs/flusight", package = "hubValidations"), new_path = NULL, - check_path = testthat::test_path("testdata/src/R/src_check_works.R"), - args = list("src_check_works" = list(extra_msg = 'Extra arguments passed')) + check_dir = testthat::test_path("testdata/src/R/"), + yaml_path = testthat::test_path("testdata/config/validations-src.yml") ) { if (is.null(new_path)) { return() } + # make a copy of the hub fs::dir_copy(hub_path, new_path) + + # create the script path new_path <- fs::path(new_path, fs::path_file(hub_path)) - script_path <- fs::path(new_path, "src/validations/R/test-check.R") + script_path <- fs::path(new_path, "src/validations/R") + # NOTE: this creates the `src/validatons` directory because if the `R/` dir + # exists, `dir_copy()` will place the copied directory _inside_ it, which is + # not what we want. fs::dir_create(fs::path_dir(script_path)) - fs::file_copy(check_path, script_path, overwrite = TRUE) - n <- seq_along(args) - fun <- lapply(n, function(fn) { - list( - fn = names(args)[[fn]], - source = fs::path_rel(script_path, start = new_path), - args = args[[fn]] - ) - }) - names(fun) <- paste0("check_", n) - yml <- list( - "default" = list( - "test_custom_checks_caller" = fun - ) - ) + + # Copy the directory of the existing files to the new script path + fs::dir_copy(check_dir, script_path) + + # Copy the provided yaml file to the config folder + new_yaml <- fs::path(new_path, "hub-config", "validations.yml") + fs::file_copy(yaml_path, new_yaml, overwrite = TRUE) # nolint end - writeLines(yaml::as.yaml(yml), fs::path(new_path, "hub-config", "validations.yml")) return(new_path) } From c2ac758dd8969bf10cc1536df29e6127de78896b Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar (UMass)" Date: Thu, 31 Oct 2024 08:24:12 -0700 Subject: [PATCH 10/12] simplify tests --- tests/testthat/test-execute_custom_checks.R | 27 ++++++--------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/tests/testthat/test-execute_custom_checks.R b/tests/testthat/test-execute_custom_checks.R index b93b6c95..bfe1d608 100644 --- a/tests/testthat/test-execute_custom_checks.R +++ b/tests/testthat/test-execute_custom_checks.R @@ -26,15 +26,17 @@ test_that("execute_custom_checks works", { test_that("execute_custom_checks sourcing functions from scripts works", { tmp <- withr::local_tempdir() - hub <- stand_up_custom_check_hub(new_path = tmp) + the_config <- testthat::test_path("testdata/config/validations-src.yml") + + hub <- stand_up_custom_check_hub(new_path = tmp, yaml_path = the_config) expect_no_error({ withr::with_tempdir({ - res <- test_custom_checks_caller(hub_path = hub) + validations_src_external <- test_custom_checks_caller(hub_path = hub) }) }) - expect_snapshot(print(res)) + expect_snapshot(validations_src_external) }) @@ -42,13 +44,8 @@ test_that("execute_custom_checks return early when appropriate", { # When the first custom check returns an check_error class object, custom check # execution should return early tmp1 <- withr::local_tempdir() - the_check <- testthat::test_path("testdata/src/R/src_simple_example_check.R") hub1 <- stand_up_custom_check_hub(new_path = tmp1, - check_path = the_check, - args = list( - simple_example_check = list(check = FALSE, error = TRUE), - simple_example_check = list(check = TRUE, error = FALSE) - ) + yaml_path = testthat::test_path("testdata/config/validations-early-ret.yml") ) early_ret_custom <- test_custom_checks_caller(hub_path = hub1) expect_snapshot(early_ret_custom) @@ -58,11 +55,7 @@ test_that("execute_custom_checks return early when appropriate", { # Same when the first custom check returns an exec_error class object tmp2 <- withr::local_tempdir() hub2 <- stand_up_custom_check_hub(new_path = tmp2, - check_path = the_check, - args = list( - simple_example_check = list(check = FALSE, error = TRUE, exec_error = TRUE), - simple_example_check = list(check = TRUE, error = FALSE) - ) + yaml_path = testthat::test_path("testdata/config/validations-exec-error.yml") ) early_ret_exec_error <- test_custom_checks_caller(hub2) expect_snapshot(early_ret_exec_error) @@ -74,11 +67,7 @@ test_that("execute_custom_checks return early when appropriate", { # execution should proceed tmp3 <- withr::local_tempdir() hub3 <- stand_up_custom_check_hub(new_path = tmp3, - check_path = the_check, - args = list( - simple_example_check = list(check = FALSE, error = FALSE), - simple_example_check = list(check = TRUE, error = FALSE) - ) + yaml_path = testthat::test_path("testdata/config/validations-no-early-ret.yml") ) no_early_ret_custom <- test_custom_checks_caller(hub3) expect_snapshot(no_early_ret_custom) From bd6e899c1932431b5d33684678150216c0c4926c Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar (UMass)" Date: Thu, 31 Oct 2024 08:24:21 -0700 Subject: [PATCH 11/12] SNAP! --- tests/testthat/_snaps/execute_custom_checks.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/_snaps/execute_custom_checks.md b/tests/testthat/_snaps/execute_custom_checks.md index 4d162ebb..196dc078 100644 --- a/tests/testthat/_snaps/execute_custom_checks.md +++ b/tests/testthat/_snaps/execute_custom_checks.md @@ -32,12 +32,12 @@ # execute_custom_checks sourcing functions from scripts works Code - print(res) + validations_src_external Message -- 2023-05-08-hub-ensemble.parquet ---- - i [check_1]: Sourcing custom functions WORKS! Also "Extra arguments passed"!! + i [src_check_works]: Sourcing custom functions WORKS! Also "Extra arguments passed"!! # execute_custom_checks return early when appropriate From 6cac9bbf02cc0e6d5423f77b322fc30bfa463e17 Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar (UMass)" Date: Thu, 31 Oct 2024 08:24:29 -0700 Subject: [PATCH 12/12] update NEWS --- NEWS.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS.md b/NEWS.md index e6c6445c..bc11684c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # hubValidations (development version) +* Custom checks no longer fail if validation is run outside of the root of the + hub (#141) + # hubValidations 0.7.1 * Updated documentation for custom validations: