Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
realxinzhao committed Nov 8, 2023
1 parent a3f146a commit fcb1121
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
14 changes: 9 additions & 5 deletions tests/testthat/test_datautil.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test_that("handle empty input", {

test_that("return_data works", {
d <- return_data(cars, iris)
expect_is(d, "list")
expect_type(d, "list")
expect_identical(names(d), c("cars", "iris"))

# test it does not allow grouped data
Expand Down Expand Up @@ -72,16 +72,20 @@ test_that("same_attributes_as works", {

test_that("prebuilt_data works", {
pb <- list(x = 1, y = 2)
expect_null(extract_prebuilt_data("not_prebuild_data"))
expect_warning(expect_null(extract_prebuilt_data("not_prebuild_data")))

obj <- extract_prebuilt_data(names(pb)[1], pb = pb)
expect_equivalent(obj, pb[[1]])
expect_is(get_comments(obj), "character") # should have a comment attached
expect_equal(obj, pb[[1]], ignore_attr = TRUE)
expect_type(get_comments(obj), "character") # should have a comment attached
})

test_that("verify_identical_prebuilt works", {
pb <- list(x = 1, y = 2)
x <- 1
expect_silent(verify_identical_prebuilt(x, pb = pb))
expect_warning(verify_identical_prebuilt(zzz = 1, pb = pb))

expect_warning(
expect_warning(verify_identical_prebuilt(zzz = 1, pb = pb))
)

})
14 changes: 8 additions & 6 deletions tests/testthat/test_driver_drake.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,18 @@ test_that("plan is a dataframe",{
skip("No drake package - skipping test")
}
plan <- driver_drake(stop_before = c("module_xfaostat_L103_ProducerPrices"), return_plan_only = TRUE)
expect_is(plan, "data.frame")
expect_type(plan, "list")
})

test_that("load_from_cache works", {
if(!hasdrake) {
skip("No drake package - skipping test")
}
data <- load_from_cache(outputs_of("module_xfaostat_L103_ProducerPrices"))

expect_type(data, "list")
tryCatch({
data <- load_from_cache(outputs_of("module_xfaostat_L105_DataConnectionToSUA"))

expect_type(data, "list")
}, error = function(e) {
skip("No drake package - skipping test")
})

})

0 comments on commit fcb1121

Please sign in to comment.