Skip to content

Commit

Permalink
Merge pull request #311 from epiforecasts/all-data-tests
Browse files Browse the repository at this point in the history
Reduce test runtime
  • Loading branch information
seabbs authored Apr 24, 2021
2 parents 8b7e574 + e796d80 commit fb68b52
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 48 deletions.
Binary file modified tests/testthat/custom_data/ecdc.rds
Binary file not shown.
Binary file modified tests/testthat/custom_data/mexico_level_1_snap.rds
Binary file not shown.
Binary file modified tests/testthat/custom_data/mexico_level_2_snap.rds
Binary file not shown.
Binary file modified tests/testthat/custom_data/who.rds
Binary file not shown.
4 changes: 4 additions & 0 deletions tests/testthat/functions/dummy_class.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ dummy_class <- function(class) {
class$data$raw <- purrr::map(class$data$raw, ~ dplyr::slice_tail(., n = 250))
class$data$raw <- purrr::map(class$data$raw, ~ .[, 1:min(20, ncol(.))])
class$clean()
class$data$clean <- dplyr::slice_tail(class$data$clean, n = 250)
class$process()
replacePublicR6Method(class, "download", function() {
return(invisible(NULL))
})
replacePublicR6Method(class, "clean", function() {
return(invisible(NULL))
})
class$verbose <- FALSE
return(class)
}
98 changes: 50 additions & 48 deletions tests/testthat/test-regional-datasets.R
Original file line number Diff line number Diff line change
@@ -1,53 +1,55 @@
# load testing function and tools.
# set up custom tests using:
# custom_tests/regional-dataset-specific.R
source("custom_tests/test-regional-dataset.R")
if (identical(Sys.getenv("NOT_CRAN"), "true")) {
# load testing function and tools.
# set up custom tests using:
# custom_tests/regional-dataset-specific.R
source("custom_tests/test-regional-dataset.R")

# should a single dataset be tested vs all datasets
# set this when implementing a new dataset.
# Can also be set using environment variables
source_of_interest <- NULL
if (!is.null(getOption("testSource"))) {
source_of_interest <- getOption("testSource")
}
# should downloads be tested (defaults to FALSE)
# set this to true when implementing a new data set
# can also be controlled using an environment variable
download <- FALSE
if (!is.null(getOption("testDownload"))) {
download <- getOption("testDownload")
}
# should a single dataset be tested vs all datasets
# set this when implementing a new dataset.
# Can also be set using environment variables
source_of_interest <- NULL
if (!is.null(getOption("testSource"))) {
source_of_interest <- getOption("testSource")
}
# should downloads be tested (defaults to FALSE)
# set this to true when implementing a new data set
# can also be controlled using an environment variable
download <- FALSE
if (!is.null(getOption("testDownload"))) {
download <- getOption("testDownload")
}

# get datasets for testing
sources <- get_available_datasets() %>%
dplyr::filter(.data$type %in%
c("national", "regional")) %>%
dplyr::select(source = class, level_1_region, level_2_region) %>%
tidyr::pivot_longer(
cols = -source,
names_to = "level",
values_to = "regions"
) %>%
dplyr::mutate(
level = stringr::str_split(level, "_"),
level = purrr::map_chr(level, ~ .[2])
) %>%
tidyr::drop_na(regions)
# get datasets for testing
sources <- get_available_datasets() %>%
dplyr::filter(.data$type %in%
c("national", "regional")) %>%
dplyr::select(source = class, level_1_region, level_2_region) %>%
tidyr::pivot_longer(
cols = -source,
names_to = "level",
values_to = "regions"
) %>%
dplyr::mutate(
level = stringr::str_split(level, "_"),
level = purrr::map_chr(level, ~ .[2])
) %>%
tidyr::drop_na(regions)

# filter out target datasets
if (!is.null(source_of_interest)) {
sources <- sources %>%
dplyr::filter(source %in% source_of_interest)
}
# filter out target datasets
if (!is.null(source_of_interest)) {
sources <- sources %>%
dplyr::filter(source %in% source_of_interest)
}

# apply tests to each data source in turn
sources %>%
dplyr::rowwise() %>%
dplyr::group_split() %>%
purrr::walk(
~ test_regional_dataset(
source = .$source[[1]],
level = .$level[[1]],
download = download
# apply tests to each data source in turn
sources %>%
dplyr::rowwise() %>%
dplyr::group_split() %>%
purrr::walk(
~ test_regional_dataset(
source = .$source[[1]],
level = .$level[[1]],
download = download
)
)
)
}

0 comments on commit fb68b52

Please sign in to comment.