From e00839256464e0319927fba82a4593a53f11c3dd Mon Sep 17 00:00:00 2001 From: Jeanette Clark Date: Fri, 12 Jul 2024 09:03:45 -0700 Subject: [PATCH 1/8] add package name to options in test setup and remove it when tests are complete --- tests/testthat/setup.R | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 tests/testthat/setup.R diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R new file mode 100644 index 000000000..6ac2732ed --- /dev/null +++ b/tests/testthat/setup.R @@ -0,0 +1,3 @@ +options(package_name = "RSQLite") + +withr::defer(options(package_name = NULL), teardown_env()) From 1a4045a09e3e252b005f149532c8695f882219ac Mon Sep 17 00:00:00 2001 From: Jeanette Clark Date: Fri, 12 Jul 2024 09:04:18 -0700 Subject: [PATCH 2/8] don't check for dbConnect it isn't on CRAN or in the suggests list --- R/dbConnect_SQLiteDriver.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/dbConnect_SQLiteDriver.R b/R/dbConnect_SQLiteDriver.R index 21ea64f9d..b5715b17f 100644 --- a/R/dbConnect_SQLiteDriver.R +++ b/R/dbConnect_SQLiteDriver.R @@ -106,7 +106,7 @@ dbConnect_SQLiteDriver <- function(drv, dbname = "", ..., loadable.extensions = extended_types <- isTRUE(extended_types) if (extended_types) { - check_suggested("hms", "dbConnect") + check_suggested("hms") } conn <- new("SQLiteConnection", ptr = connection_connect(dbname, loadable.extensions, flags, vfs, extended_types), From 6a39367e9563e26eb57295eec1d9a197f40b9eb5 Mon Sep 17 00:00:00 2001 From: Jeanette Clark Date: Fri, 12 Jul 2024 09:08:30 -0700 Subject: [PATCH 3/8] minor doc change after running R CMD check --- NAMESPACE | 1 + 1 file changed, 1 insertion(+) diff --git a/NAMESPACE b/NAMESPACE index 7d2daab12..e96ef151a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -84,6 +84,7 @@ exportMethods(sqlData) import(DBI) import(methods) import(rlang) +importFrom(DBI,Id) importFrom(bit64,integer64) importFrom(bit64,is.integer64) importFrom(blob,blob) From 67aaabe53c17b4884d868ca633c81935a915d5b7 Mon Sep 17 00:00:00 2001 From: Jeanette Clark Date: Mon, 15 Jul 2024 10:04:32 -0700 Subject: [PATCH 4/8] Revert "don't check for dbConnect" This reverts commit 1a4045a09e3e252b005f149532c8695f882219ac. --- R/dbConnect_SQLiteDriver.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/dbConnect_SQLiteDriver.R b/R/dbConnect_SQLiteDriver.R index b5715b17f..21ea64f9d 100644 --- a/R/dbConnect_SQLiteDriver.R +++ b/R/dbConnect_SQLiteDriver.R @@ -106,7 +106,7 @@ dbConnect_SQLiteDriver <- function(drv, dbname = "", ..., loadable.extensions = extended_types <- isTRUE(extended_types) if (extended_types) { - check_suggested("hms") + check_suggested("hms", "dbConnect") } conn <- new("SQLiteConnection", ptr = connection_connect(dbname, loadable.extensions, flags, vfs, extended_types), From d0901e37d0f85e526f2feb27a3a53fa4213ebb24 Mon Sep 17 00:00:00 2001 From: Jeanette Clark Date: Mon, 15 Jul 2024 10:11:02 -0700 Subject: [PATCH 5/8] use local_options with teardown MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kirill Müller --- tests/testthat/setup.R | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R index 6ac2732ed..891dcedd4 100644 --- a/tests/testthat/setup.R +++ b/tests/testthat/setup.R @@ -1,3 +1 @@ -options(package_name = "RSQLite") - -withr::defer(options(package_name = NULL), teardown_env()) +rlang::local_options(test_package_name = "RSQLite", .frame = teardown_env()) From a3592e9b3c59bc6d1eef78a99a75b358c5d01323 Mon Sep 17 00:00:00 2001 From: Jeanette Clark Date: Tue, 16 Jul 2024 13:52:35 -0700 Subject: [PATCH 6/8] check for package name option in check_suggested also fix the formatting of the message --- DESCRIPTION | 1 + R/import-standalone-check_suggested.R | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1d6f0c5b7..ea58b2351 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -42,6 +42,7 @@ Imports: rlang Suggests: callr, + cli, DBItest (>= 1.8.0), gert, gh, diff --git a/R/import-standalone-check_suggested.R b/R/import-standalone-check_suggested.R index e9ad8efa5..3bbaf2f0e 100644 --- a/R/import-standalone-check_suggested.R +++ b/R/import-standalone-check_suggested.R @@ -58,9 +58,9 @@ check_suggested <- function(packages, top_level_fun, use = TRUE) { # Skip if some packages are not installed when testing # And say which package was not installed. - if (identical(Sys.getenv("TESTTHAT"), "true")) { + if (identical(Sys.getenv("TESTTHAT"), "true") && identical(getOption("test_package_name"), "RSQLite")) { pkgs_not_installed <- packages[!installed] - message <- "{.fn {top_level_fun}} needs the {.pkg {.val {pkgs_not_installed}}} package{?s}." + message <- cli::cli_li("{.fn {top_level_fun}} needs the {.pkg {.val {pkgs_not_installed}}} package{?s}.") testthat::skip(message) } From 39520478eb18c7a0ab424fd5177257a3a12fedc5 Mon Sep 17 00:00:00 2001 From: Jeanette Clark Date: Tue, 16 Jul 2024 14:32:30 -0700 Subject: [PATCH 7/8] dynamically get package name and update header --- R/import-standalone-check_suggested.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/import-standalone-check_suggested.R b/R/import-standalone-check_suggested.R index 3bbaf2f0e..e6d8b61b0 100644 --- a/R/import-standalone-check_suggested.R +++ b/R/import-standalone-check_suggested.R @@ -6,9 +6,9 @@ # --- # repo: cynkra/dm # file: standalone-check_suggested.R -# last-updated: 2023-02-23 +# last-updated: 2024-07-16 # license: https://unlicense.org -# imports: rlang, cli, glue +# imports: rlang, cli # --- # # This file provides a wrapper around `rlang::check_installed()` that skips tests @@ -58,7 +58,7 @@ check_suggested <- function(packages, top_level_fun, use = TRUE) { # Skip if some packages are not installed when testing # And say which package was not installed. - if (identical(Sys.getenv("TESTTHAT"), "true") && identical(getOption("test_package_name"), "RSQLite")) { + if (identical(Sys.getenv("TESTTHAT"), "true") && identical(getOption("test_package_name"), getPackageName())) { pkgs_not_installed <- packages[!installed] message <- cli::cli_li("{.fn {top_level_fun}} needs the {.pkg {.val {pkgs_not_installed}}} package{?s}.") testthat::skip(message) From 14f1cfb01df8a6a2193620dcd30d229d05632084 Mon Sep 17 00:00:00 2001 From: Jeanette Clark Date: Wed, 17 Jul 2024 10:58:58 -0700 Subject: [PATCH 8/8] update changelog and replace getPackageName --- R/import-standalone-check_suggested.R | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/R/import-standalone-check_suggested.R b/R/import-standalone-check_suggested.R index e6d8b61b0..5dc8985ae 100644 --- a/R/import-standalone-check_suggested.R +++ b/R/import-standalone-check_suggested.R @@ -6,7 +6,7 @@ # --- # repo: cynkra/dm # file: standalone-check_suggested.R -# last-updated: 2024-07-16 +# last-updated: 2024-07-17 # license: https://unlicense.org # imports: rlang, cli # --- @@ -20,6 +20,8 @@ # # 2023-10-19: # * Initial +# 2024-07-17: +# * Skip tests only when the test env is for this package, and correctly format the message # nocov start @@ -58,7 +60,7 @@ check_suggested <- function(packages, top_level_fun, use = TRUE) { # Skip if some packages are not installed when testing # And say which package was not installed. - if (identical(Sys.getenv("TESTTHAT"), "true") && identical(getOption("test_package_name"), getPackageName())) { + if (identical(Sys.getenv("TESTTHAT"), "true") && identical(getOption("test_package_name"), environmentName(topenv()))) { pkgs_not_installed <- packages[!installed] message <- cli::cli_li("{.fn {top_level_fun}} needs the {.pkg {.val {pkgs_not_installed}}} package{?s}.") testthat::skip(message)