Skip to content

Commit

Permalink
expect_no_error btw
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksander Chlebowski committed Oct 17, 2023
1 parent 43b29e3 commit a735fd3
Showing 1 changed file with 54 additions and 48 deletions.
102 changes: 54 additions & 48 deletions tests/testthat/test-init.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ mods <- teal:::example_modules()
testthat::test_that("init data accepts TealData objects", {
teal_data_object <- teal.data::teal_data(dataset_1)
cdisc_data_object <- teal.data::cdisc_data(adsl_dataset)
testthat::expect_error(init(data = teal_data_object, modules = mods), NA)
testthat::expect_error(init(data = cdisc_data_object, modules = mods), NA)
testthat::expect_no_error(init(data = teal_data_object, modules = mods))
testthat::expect_no_error(init(data = cdisc_data_object, modules = mods))
})

testthat::test_that("init data throws an error with input other than accepted input", {
Expand All @@ -27,16 +27,15 @@ testthat::test_that("init data throws an error with input other than accepted in
})

testthat::test_that("init data accepts a single TealDataset/CDISCTealDataset", {
testthat::expect_error(init(data = teal.data::dataset("iris", head(iris)), modules = mods), NA)
testthat::expect_error(
testthat::expect_no_error(init(data = teal.data::dataset("iris", head(iris)), modules = mods))
testthat::expect_no_error(
init(
data = teal.data::cdisc_dataset("ADSL", adsl_df, parent = character(0), keys = teal.data::get_cdisc_keys("ADSL")),
modules = mods
),
NA
)
)
testthat::expect_error(init(data = dataset_1, modules = mods), NA)
testthat::expect_error(init(data = adsl_dataset, modules = mods), NA)
testthat::expect_no_error(init(data = dataset_1, modules = mods))
testthat::expect_no_error(init(data = adsl_dataset, modules = mods))
})

testthat::test_that("init data accepts a list of single TealDataset/CDISCTealDataset without renaming", {
Expand All @@ -45,104 +44,111 @@ testthat::test_that("init data accepts a list of single TealDataset/CDISCTealDat
teal.data::cdisc_dataset("ADSL", adsl_df, parent = character(0), keys = teal.data::get_cdisc_keys("ADSL"))
)

testthat::expect_error(init(data = list(teal.data::dataset("iris", head(iris))), modules = mods), NA)
testthat::expect_error(init(
data = list(
teal.data::cdisc_dataset("ADSL", adsl_df, parent = character(0), keys = teal.data::get_cdisc_keys("ADSL"))
),
modules = mods
), NA)
testthat::expect_error(init(data = dataset_list, modules = mods), NA)
testthat::expect_error(init(data = cdisc_dataset_list, modules = mods), NA)
testthat::expect_no_error(init(data = list(teal.data::dataset("iris", head(iris))), modules = mods))
testthat::expect_no_error(
init(
data = list(
teal.data::cdisc_dataset("ADSL", adsl_df, parent = character(0), keys = teal.data::get_cdisc_keys("ADSL"))
),
modules = mods
)
)
testthat::expect_no_error(init(data = dataset_list, modules = mods))
testthat::expect_no_error(init(data = cdisc_dataset_list, modules = mods))
})

testthat::test_that("init data accepts a single dataframe", {
testthat::expect_error(init(data = adsl_df, modules = mods), NA)
testthat::expect_no_error(init(data = adsl_df, modules = mods))
})

testthat::test_that("init data accepts a list of single dataframe without renaming", {
testthat::expect_error(init(data = list(adsl_df), modules = mods), NA)
testthat::expect_no_error(init(data = list(adsl_df), modules = mods))
})

testthat::test_that("init data accepts a list of single dataframe with renaming", {
adsl_list <- list(data1 = adsl_df)
testthat::expect_error(init(data = list(data1 = adsl_df), modules = mods), NA)
testthat::expect_error(init(data = adsl_list, modules = mods), NA)
testthat::expect_no_error(init(data = list(data1 = adsl_df), modules = mods))
testthat::expect_no_error(init(data = adsl_list, modules = mods))
})

testthat::test_that("init data accepts a list of a TealDataset and a dataframe without renaming", {
testthat::expect_error(init(data = list(dataset_1, adsl_df), modules = mods), NA)
testthat::expect_no_error(init(data = list(dataset_1, adsl_df), modules = mods))
})

testthat::test_that("init data accepts a single MultiAssayExperiment object", {
utils::data(miniACC, package = "MultiAssayExperiment")
testthat::expect_error(init(data = miniACC, modules = mods), NA)
testthat::expect_no_error(init(data = miniACC, modules = mods))
})

testthat::test_that("init data accepts a list of a single MultiAssayExperiment object without renaming", {
utils::data(miniACC, package = "MultiAssayExperiment")
testthat::expect_error(init(data = list(miniACC), modules = mods), NA)
testthat::expect_no_error(init(data = list(miniACC), modules = mods))
})

testthat::test_that("init data accepts a list of a single MultiAssayExperiment object with renaming", {
utils::data(miniACC, package = "MultiAssayExperiment")
testthat::expect_error(init(data = list(x = miniACC), modules = mods), NA)
testthat::expect_no_error(init(data = list(x = miniACC), modules = mods))
})

testthat::test_that("init data acceptsa mixed list of MultiAssayExperiment object and data.frame", {
utils::data(miniACC, package = "MultiAssayExperiment")
testthat::expect_error(init(data = list(x = miniACC, y = head(iris)), modules = mods), NA)
testthat::expect_no_error(init(data = list(x = miniACC, y = head(iris)), modules = mods))
})

testthat::test_that("init data accepts a list of a TealDataset and a dataframe with renaming", {
testthat::expect_error(init(
data = list(
data1 = teal.data::dataset("iris", head(iris)),
data2 = as.data.frame(as.list(setNames(nm = teal.data::get_cdisc_keys("ADSL"))))
),
modules = mods
), NA)
testthat::expect_error(init(data = list(data1 = dataset_1, data2 = adsl_df), modules = mods), NA)
testthat::expect_no_error(
init(
data = list(
data1 = teal.data::dataset("iris", head(iris)),
data2 = as.data.frame(as.list(setNames(nm = teal.data::get_cdisc_keys("ADSL"))))
),
modules = mods
)
)
testthat::expect_no_error(init(data = list(data1 = dataset_1, data2 = adsl_df), modules = mods))
})

testthat::test_that("init data accepts a list of mixed TealDataset and dataframe with mixed renaming", {
testthat::expect_error(init(data = list(data1 = teal.data::dataset("iris", head(iris)), adsl_df), modules = mods), NA)
testthat::expect_error(init(data = list(dataset_1, data2 = adsl_df), modules = mods), NA)
testthat::expect_no_error(init(data = list(data1 = teal.data::dataset("iris", head(iris)), adsl_df), modules = mods))
testthat::expect_no_error(init(data = list(dataset_1, data2 = adsl_df), modules = mods))
})

testthat::test_that("init data accepts TealDatasetConnector object", {
dsc1 <- teal.data::dataset_connector("iris", teal.data::callable_function(function() head(iris)))
testthat::expect_error(init(data = dsc1, modules = mods), NA)
testthat::expect_error(init(
data = teal.data::dataset_connector("iris", teal.data::callable_function(function() head(iris))),
modules = mods
), NA)
testthat::expect_no_error(init(data = dsc1, modules = mods))
testthat::expect_no_error(
init(
data = teal.data::dataset_connector("iris", teal.data::callable_function(function() head(iris))),
modules = mods
)
)
})

testthat::test_that("init data accepts a list of TealDatasetConnector object", {
dsc1 <- list(teal.data::dataset_connector("iris", teal.data::callable_function(function() head(iris))))
testthat::expect_error(init(data = dsc1, modules = mods), NA)
testthat::expect_error(
testthat::expect_no_error(init(data = dsc1, modules = mods))
testthat::expect_no_error(
init(data = list(
teal.data::dataset_connector("iris", teal.data::callable_function(function() head(iris)))
), modules = mods),
NA
),
modules = mods
)
)
})

testthat::test_that("init modules accepts a teal_modules object", {
mods <- modules(example_module(), example_module())
testthat::expect_error(init(data = iris, modules = mods), NA)
testthat::expect_no_error(init(data = iris, modules = mods))
})

testthat::test_that("init modules accepts a list of teal_module elements", {
mods <- list(example_module(), example_module())
testthat::expect_error(init(data = iris, modules = mods), NA)
testthat::expect_no_error(init(data = iris, modules = mods))
})

testthat::test_that("init modules accepts a teal_module object", {
mods <- example_module()
testthat::expect_error(init(data = iris, modules = mods), NA)
testthat::expect_no_error(init(data = iris, modules = mods))
})

testthat::test_that("init filter accepts named list or `teal_slices`", {
Expand Down

0 comments on commit a735fd3

Please sign in to comment.