diff --git a/DESCRIPTION b/DESCRIPTION index 1b8fd862..60f3303c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -31,7 +31,7 @@ Suggests: DBItest, magrittr, RSQLite, - testthat, + testthat (>= 3.0.0), tibble LinkingTo: Rcpp @@ -56,3 +56,4 @@ Collate: 'hidden.R' 'utils.R' 'zzz.R' +Config/testthat/edition: 3 diff --git a/NEWS.md b/NEWS.md index b54348b7..0a69bdfd 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # odbc (development version) + * Modify `odbcDataType.Snowflake` to better reflect Snowflake Data Types documentation (@meztez, #599). * SQL Server: Specialize syntax in sqlCreateTable to avoid failures when writing to (new) local temp tables. (@detule, #601) diff --git a/tests/testthat.R b/tests/testthat.R index 2c97e5a1..e29e2576 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -1,4 +1,12 @@ +# This file is part of the standard setup for testthat. +# It is recommended that you do not modify it. +# +# Where should you do additional test configuration? +# Learn more about the roles of various files in: +# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview +# * https://testthat.r-lib.org/articles/special-files.html + library(testthat) library(odbc) -test_check("odbc", reporter = "summary") +test_check("odbc") diff --git a/tests/testthat/_snaps/show.md b/tests/testthat/_snaps/show.md new file mode 100644 index 00000000..c2b42a08 --- /dev/null +++ b/tests/testthat/_snaps/show.md @@ -0,0 +1,22 @@ +# show method prints only host if no user is defined + + Code + con + Output + localhost + +# show method prints DISCONNECTED if not valid + + Code + con + Output + localhost + DISCONNECTED + +# show method does not print server if it is not available + + Code + con + Output + + diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index 05198a4d..97f652cb 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -56,7 +56,6 @@ skip_if_no_drivers <- function() { #' } test_roundtrip <- function(con = DBItest:::connect(DBItest::get_default_context()), columns = "", invert = TRUE, force_sorted = FALSE) { dbms <- dbGetInfo(con)$dbms.name - testthat::context(paste0("roundtrip[", dbms, "]")) res <- list() testthat::test_that(paste0("[", dbms, "] round tripping data.frames works"), { #on.exit(try(DBI::dbRemoveTable(con, "test_table"), silent = TRUE)) diff --git a/tests/testthat/test-MySQL.R b/tests/testthat/test-MySQL.R index 9482770d..bb2c620a 100644 --- a/tests/testthat/test-MySQL.R +++ b/tests/testthat/test-MySQL.R @@ -74,7 +74,6 @@ test_that("MySQL", { NULL)) test_roundtrip(columns = "logical") - context("custom tests") test_that("odbcPreviewObject", { tblName <- "test_preview" con <- DBItest:::connect(DBItest:::get_default_context()) diff --git a/tests/testthat/test-PostgreSQL.R b/tests/testthat/test-PostgreSQL.R index 02df4b0c..dde5ac93 100644 --- a/tests/testthat/test-PostgreSQL.R +++ b/tests/testthat/test-PostgreSQL.R @@ -4,7 +4,6 @@ test_that("PostgreSQL", { tweaks = DBItest::tweaks(temporary_tables = FALSE, placeholder_pattern = "?"), name = "PostgreSQL") }) - context("custom tests") test_that("show method works as expected with real connection", { skip_on_os("windows") con <- DBItest:::connect(DBItest:::get_default_context()) @@ -28,14 +27,14 @@ test_that("PostgreSQL", { dbWriteTable(con_default, "test", data.frame(a = 1:10L), field.types = c(a = "BIGINT")) on.exit(dbRemoveTable(con_default, "test")) - expect_is(dbReadTable(con_default, "test")$a, "integer64") - expect_is(dbReadTable(con_integer64, "test")$a, "integer64") + expect_s3_class(dbReadTable(con_default, "test")$a, "integer64") + expect_s3_class(dbReadTable(con_integer64, "test")$a, "integer64") - expect_is(dbReadTable(con_integer, "test")$a, "integer") + expect_type(dbReadTable(con_integer, "test")$a, "integer") - expect_is(dbReadTable(con_numeric, "test")$a, "numeric") + expect_type(dbReadTable(con_numeric, "test")$a, "double") - expect_is(dbReadTable(con_character, "test")$a, "character") + expect_type(dbReadTable(con_character, "test")$a, "character") }) # This test checks whether when writing to a table and using @@ -74,7 +73,6 @@ test_that("PostgreSQL", { expect_equal(nrow(res), 3) }) - context("DBI tests") DBItest::test_getting_started(c( "package_name", # Not an error NULL)) diff --git a/tests/testthat/test-SQLite.R b/tests/testthat/test-SQLite.R index 8bc140b3..052ccb53 100644 --- a/tests/testthat/test-SQLite.R +++ b/tests/testthat/test-SQLite.R @@ -118,7 +118,6 @@ test_that("SQLite", { NULL)) - context("custom tests") local({ ## Test that trying to write unsupported types (like complex numbers) throws an ## informative error message diff --git a/tests/testthat/test-drivers.R b/tests/testthat/test-drivers.R index 1e8abc1b..1e3f951a 100644 --- a/tests/testthat/test-drivers.R +++ b/tests/testthat/test-drivers.R @@ -1,5 +1,3 @@ -context("drivers") - test_that("odbcListDrivers() returns available drivers", { skip_on_cran() skip_if_no_drivers() diff --git a/tests/testthat/test-show.R b/tests/testthat/test-show.R index fdc6ec20..bec061e0 100644 --- a/tests/testthat/test-show.R +++ b/tests/testthat/test-show.R @@ -1,31 +1,28 @@ -context("show") - test_that("show method prints only host if no user is defined", { con <- new("OdbcConnection") - with_mock( - `DBI::dbGetInfo` = function(x) c(servername = "localhost", username = "", dbname = "", dbms.name = "", db.version = ""), - `DBI::dbIsValid` = function(x) TRUE, - { - expect_output(show(con), " localhost") - }) + local_mocked_bindings( + dbGetInfo = function(x) c(servername = "localhost", username = "", dbname = "", dbms.name = "", db.version = ""), + dbIsValid = function(x) TRUE + ) + + expect_snapshot(con) }) test_that("show method prints DISCONNECTED if not valid", { con <- new("OdbcConnection") - with_mock( - `DBI::dbGetInfo` = function(x) c(servername = "localhost", username = "", dbname = "", dbms.name = "", db.version = ""), - `DBI::dbIsValid` = function(x) FALSE, - { - expect_output(show(con), " DISCONNECTED") - }) + local_mocked_bindings( + dbGetInfo = function(x) c(servername = "localhost", username = "", dbname = "", dbms.name = "", db.version = ""), + dbIsValid = function(x) FALSE + ) + expect_snapshot(con) }) test_that("show method does not print server if it is not available", { + con <- new("OdbcConnection") - with_mock( - `DBI::dbGetInfo` = function(x) c(servername = "", username = "", dbname = "", dbms.name = "", db.version = ""), - `DBI::dbIsValid` = function(x) TRUE, - { - expect_output(show(con), "$") - }) + local_mocked_bindings( + dbGetInfo = function(x) c(servername = "", username = "", dbname = "", dbms.name = "", db.version = ""), + dbIsValid = function(x) TRUE + ) + expect_snapshot(con) })