tests/testthat/test-read.R

library(testthat)
library(mdbr)

test_that("tables can be read as data frames", {
  skip_on_cran()
  skip_if_not(has_mdb_tools())
  dat <- read_mdb(mdb_example(), "Flights", col_types = TRUE)
  expect_length(dat, 19)
  expect_s3_class(dat, "tbl")
  expect_s3_class(dat$time_hour, "POSIXt")
  expect_type(dat$year, "integer")
  expect_type(dat$carrier, "character")
})

test_that("tables can be read in memory", {
  skip_on_cran()
  skip_if_not(has_mdb_tools())
  dat <- read_mdb(mdb_example(), "Flights", col_types = TRUE)
  expect_length(dat, 19)
  expect_s3_class(dat, "tbl")
  expect_s3_class(dat$time_hour, "POSIXt")
  expect_type(dat$year, "integer")
  expect_type(dat$carrier, "character")
})

test_that("reading errors without table name", {
  skip_on_cran()
  skip_if_not(has_mdb_tools())
  expect_error(read_mdb(mdb_example()))
})

test_that("reading error when console stdout", {
  skip_on_cran()
  skip_if_not(has_mdb_tools())
  expect_error(read_mdb(mdb_example(), "Flights", stdout = ""))
})

Try the mdbr package in your browser

Any scripts or data that you put into this service are public.

mdbr documentation built on May 29, 2024, 7:27 a.m.