File: test-tbl-lazy.R

package info (click to toggle)
r-cran-dbplyr 2.3.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,376 kB
  • sloc: sh: 13; makefile: 2
file content (42 lines) | stat: -rw-r--r-- 1,074 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
test_that("adds src class", {
  tb <- tbl_lazy(mtcars, con = simulate_sqlite())
  expect_s3_class(tb, "tbl_SQLiteConnection")
})

test_that("argument src is deprecated", {
  expect_snapshot(dummy <- tbl_lazy(mtcars, src = simulate_sqlite()))
})

test_that("cannot convert tbl_lazy to data.frame", {
  expect_snapshot(
    error = TRUE,
    as.data.frame(tbl_lazy(mtcars, src = simulate_sqlite()))
  )
})

test_that("dim() works for tbl_lazy", {
  expect_equal(dim(tbl_lazy(mtcars)), c(NA, 11))
})

test_that("has print method", {
  expect_snapshot(tbl_lazy(mtcars))
})

test_that("support colwise variants", {
  mf <- memdb_frame(x = 1:5, y = factor(letters[1:5]))
  exp <- mf %>% collect() %>% mutate(y = as.character(y))

  expect_message(
    mf1 <- dplyr::mutate_if(mf, is.factor, as.character),
    "on the first 100 rows"
  )
  compare_tbl(mf1, exp)

  mf2 <- dplyr::mutate_at(mf, "y", as.character)
  compare_tbl(mf2, exp)
})

test_that("base source of tbl_lazy is always 'df'", {
  out <- lazy_frame(x = 1, y = 5) %>% sql_build()
  expect_equal(out, ident("df"))
})