Skip to content

Commit

Permalink
chore: Fix tests when dplyr is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Oct 11, 2023
1 parent 4625214 commit bf2886e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion R/backend-dbplyr__duckdb_connection.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#'
#' @name backend-duckdb
#' @aliases NULL
#' @examples
#' @examplesIf rlang::is_installed("dbplyr")
#' library(dplyr, warn.conflicts = FALSE)
#' con <- DBI::dbConnect(duckdb(), path = ":memory:")
#'
Expand Down
2 changes: 2 additions & 0 deletions man/backend-duckdb.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion tests/testthat/test_tbl__duckdb_connection.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ skip_on_cran()
`%>%` <- dplyr::`%>%`

test_that("Parquet files can be registered with dplyr::tbl()", {
skip_if_not_installed("dplyr")

con <- DBI::dbConnect(duckdb())
on.exit(DBI::dbDisconnect(con, shutdown = TRUE))

Expand All @@ -24,6 +26,8 @@ test_that("Parquet files can be registered with dplyr::tbl()", {


test_that("Object cache can be enabled for parquet files with dplyr::tbl()", {
skip_if_not_installed("dplyr")

con <- DBI::dbConnect(duckdb())
on.exit(DBI::dbDisconnect(con, shutdown = TRUE))

Expand All @@ -38,6 +42,8 @@ test_that("Object cache can be enabled for parquet files with dplyr::tbl()", {


test_that("CSV files can be registered with dplyr::tbl()", {
skip_if_not_installed("dplyr")

path <- file.path(tempdir(), "duckdbtest.csv")
write.csv(iris, file = path)
on.exit(unlink(path))
Expand All @@ -55,6 +61,8 @@ test_that("CSV files can be registered with dplyr::tbl()", {
})

test_that("Other replacement scans or functions can be registered with dplyr::tbl()", {
skip_if_not_installed("dplyr")

con <- DBI::dbConnect(duckdb())
on.exit(DBI::dbDisconnect(con, shutdown = TRUE))

Expand All @@ -64,9 +72,11 @@ test_that("Other replacement scans or functions can be registered with dplyr::tb
})

test_that("Strings tagged as SQL will be handled correctly with dplyr::tbl()", {
skip_if_not_installed("dplyr")

con <- DBI::dbConnect(duckdb())
on.exit(DBI::dbDisconnect(con, shutdown = TRUE))

rs <- dplyr::tbl(con, dplyr::sql("SELECT 1"))
expect_true(inherits(rs, "tbl_duckdb_connection"))
expect_true(rs %>% dplyr::collect() == 1)
Expand Down

0 comments on commit bf2886e

Please sign in to comment.