Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Oct 19, 2024
1 parent 9190572 commit 25d76df
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions tests/testthat/test-data_read.R
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ test_that("data_read - RDS file, matrix, coercible", {
httr::stop_for_status(request)
writeBin(httr::content(request, type = "raw"), temp_file)

expect_message(expect_message(expect_message({
expect_message({
d <- data_read(
temp_file,
verbose = TRUE
)
})), regex = "0 out of 5")
})

expect_s3_class(d, "data.frame")
expect_identical(dim(d), c(2L, 5L))
Expand All @@ -155,6 +155,29 @@ test_that("data_read - RDS file, matrix, coercible", {



# RDS file, preserve class /types -----------------------------------

test_that("data_read - RDS file, preserve class", {
withr::with_tempfile("temp_file", fileext = ".rds", code = {
request <- httr::GET("https://raw.github.com/easystats/circus/main/data/hiv.rds")
httr::stop_for_status(request)
writeBin(httr::content(request, type = "raw"), temp_file)

d <- data_read(temp_file)
expect_s3_class(d, "data.frame")
expect_identical(
sapply(d, class),
c(
village = "integer", outcome = "integer", distance = "numeric",
amount = "numeric", incentive = "integer", age = "integer",
hiv2004 = "integer", agecat = "factor"
)
)
})
})



# RData -----------------------------------

test_that("data_read - no warning for RData", {
Expand Down

0 comments on commit 25d76df

Please sign in to comment.