From 3707589c7ea249dcc24ac09d1c9be91db059f6b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Tue, 31 Oct 2023 05:30:02 +0100 Subject: [PATCH] test: Skip DBItest tests if not installed --- tests/testthat/helper-DBItest.R | 84 +++++++++++++++++---------------- tests/testthat/test-DBItest.R | 2 + 2 files changed, 45 insertions(+), 41 deletions(-) diff --git a/tests/testthat/helper-DBItest.R b/tests/testthat/helper-DBItest.R index b0df5aa44..e725601dc 100644 --- a/tests/testthat/helper-DBItest.R +++ b/tests/testthat/helper-DBItest.R @@ -1,44 +1,46 @@ -default_skip <- - c( - if (packageVersion("DBItest") < "1.7.1.9004") "column_info_consistent", # https://github.com/r-dbi/DBItest/issues/181 +if (rlang::is_installed("DBItest")) { + default_skip <- + c( + if (packageVersion("DBItest") < "1.7.1.9004") "column_info_consistent", # https://github.com/r-dbi/DBItest/issues/181 - NULL - ) + NULL + ) -if (packageVersion("DBItest") >= "1.6.0") { - DBItest::make_context( - SQLite(), - list(dbname = tempfile("DBItest", fileext = ".sqlite")), - tweaks = DBItest::tweaks( - dbitest_version = "1.7.2", - constructor_relax_args = TRUE, - placeholder_pattern = c("?", "$1", "$name", ":name"), - date_cast = function(x) paste0("'", x, "'"), - time_cast = function(x) paste0("'", x, "'"), - timestamp_cast = function(x) paste0("'", x, "'"), - logical_return = function(x) as.integer(x), - date_typed = FALSE, - time_typed = FALSE, - timestamp_typed = FALSE - ), - name = "RSQLite", - default_skip = default_skip - ) -} else { - DBItest::make_context( - SQLite(), - list(dbname = tempfile("DBItest", fileext = ".sqlite")), - tweaks = DBItest::tweaks( - constructor_relax_args = TRUE, - placeholder_pattern = c("?", "$1", "$name", ":name"), - date_cast = function(x) paste0("'", x, "'"), - time_cast = function(x) paste0("'", x, "'"), - timestamp_cast = function(x) paste0("'", x, "'"), - logical_return = function(x) as.integer(x), - date_typed = FALSE, - time_typed = FALSE, - timestamp_typed = FALSE - ), - name = "RSQLite" - ) + if (packageVersion("DBItest") >= "1.6.0") { + DBItest::make_context( + SQLite(), + list(dbname = tempfile("DBItest", fileext = ".sqlite")), + tweaks = DBItest::tweaks( + dbitest_version = "1.7.2", + constructor_relax_args = TRUE, + placeholder_pattern = c("?", "$1", "$name", ":name"), + date_cast = function(x) paste0("'", x, "'"), + time_cast = function(x) paste0("'", x, "'"), + timestamp_cast = function(x) paste0("'", x, "'"), + logical_return = function(x) as.integer(x), + date_typed = FALSE, + time_typed = FALSE, + timestamp_typed = FALSE + ), + name = "RSQLite", + default_skip = default_skip + ) + } else { + DBItest::make_context( + SQLite(), + list(dbname = tempfile("DBItest", fileext = ".sqlite")), + tweaks = DBItest::tweaks( + constructor_relax_args = TRUE, + placeholder_pattern = c("?", "$1", "$name", ":name"), + date_cast = function(x) paste0("'", x, "'"), + time_cast = function(x) paste0("'", x, "'"), + timestamp_cast = function(x) paste0("'", x, "'"), + logical_return = function(x) as.integer(x), + date_typed = FALSE, + time_typed = FALSE, + timestamp_typed = FALSE + ), + name = "RSQLite" + ) + } } diff --git a/tests/testthat/test-DBItest.R b/tests/testthat/test-DBItest.R index 568903fca..edc12b645 100644 --- a/tests/testthat/test-DBItest.R +++ b/tests/testthat/test-DBItest.R @@ -1,3 +1,5 @@ +skip_if_not_installed("DBItest") + if (identical(Sys.getenv("NOT_CRAN"), "true")) { if (packageVersion("DBItest") >= "1.6.0") { DBItest::test_all()