Skip to content

Commit fb68b52

Browse files
authored
Merge pull request #311 from epiforecasts/all-data-tests
Reduce test runtime
2 parents 8b7e574 + e796d80 commit fb68b52

File tree

6 files changed

+54
-48
lines changed

6 files changed

+54
-48
lines changed

tests/testthat/custom_data/ecdc.rds

358 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.

tests/testthat/custom_data/who.rds

312 Bytes
Binary file not shown.

tests/testthat/functions/dummy_class.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ dummy_class <- function(class) {
1212
class$data$raw <- purrr::map(class$data$raw, ~ dplyr::slice_tail(., n = 250))
1313
class$data$raw <- purrr::map(class$data$raw, ~ .[, 1:min(20, ncol(.))])
1414
class$clean()
15+
class$data$clean <- dplyr::slice_tail(class$data$clean, n = 250)
1516
class$process()
1617
replacePublicR6Method(class, "download", function() {
1718
return(invisible(NULL))
1819
})
20+
replacePublicR6Method(class, "clean", function() {
21+
return(invisible(NULL))
22+
})
1923
class$verbose <- FALSE
2024
return(class)
2125
}
Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,55 @@
1-
# load testing function and tools.
2-
# set up custom tests using:
3-
# custom_tests/regional-dataset-specific.R
4-
source("custom_tests/test-regional-dataset.R")
1+
if (identical(Sys.getenv("NOT_CRAN"), "true")) {
2+
# load testing function and tools.
3+
# set up custom tests using:
4+
# custom_tests/regional-dataset-specific.R
5+
source("custom_tests/test-regional-dataset.R")
56

6-
# should a single dataset be tested vs all datasets
7-
# set this when implementing a new dataset.
8-
# Can also be set using environment variables
9-
source_of_interest <- NULL
10-
if (!is.null(getOption("testSource"))) {
11-
source_of_interest <- getOption("testSource")
12-
}
13-
# should downloads be tested (defaults to FALSE)
14-
# set this to true when implementing a new data set
15-
# can also be controlled using an environment variable
16-
download <- FALSE
17-
if (!is.null(getOption("testDownload"))) {
18-
download <- getOption("testDownload")
19-
}
7+
# should a single dataset be tested vs all datasets
8+
# set this when implementing a new dataset.
9+
# Can also be set using environment variables
10+
source_of_interest <- NULL
11+
if (!is.null(getOption("testSource"))) {
12+
source_of_interest <- getOption("testSource")
13+
}
14+
# should downloads be tested (defaults to FALSE)
15+
# set this to true when implementing a new data set
16+
# can also be controlled using an environment variable
17+
download <- FALSE
18+
if (!is.null(getOption("testDownload"))) {
19+
download <- getOption("testDownload")
20+
}
2021

21-
# get datasets for testing
22-
sources <- get_available_datasets() %>%
23-
dplyr::filter(.data$type %in%
24-
c("national", "regional")) %>%
25-
dplyr::select(source = class, level_1_region, level_2_region) %>%
26-
tidyr::pivot_longer(
27-
cols = -source,
28-
names_to = "level",
29-
values_to = "regions"
30-
) %>%
31-
dplyr::mutate(
32-
level = stringr::str_split(level, "_"),
33-
level = purrr::map_chr(level, ~ .[2])
34-
) %>%
35-
tidyr::drop_na(regions)
22+
# get datasets for testing
23+
sources <- get_available_datasets() %>%
24+
dplyr::filter(.data$type %in%
25+
c("national", "regional")) %>%
26+
dplyr::select(source = class, level_1_region, level_2_region) %>%
27+
tidyr::pivot_longer(
28+
cols = -source,
29+
names_to = "level",
30+
values_to = "regions"
31+
) %>%
32+
dplyr::mutate(
33+
level = stringr::str_split(level, "_"),
34+
level = purrr::map_chr(level, ~ .[2])
35+
) %>%
36+
tidyr::drop_na(regions)
3637

37-
# filter out target datasets
38-
if (!is.null(source_of_interest)) {
39-
sources <- sources %>%
40-
dplyr::filter(source %in% source_of_interest)
41-
}
38+
# filter out target datasets
39+
if (!is.null(source_of_interest)) {
40+
sources <- sources %>%
41+
dplyr::filter(source %in% source_of_interest)
42+
}
4243

43-
# apply tests to each data source in turn
44-
sources %>%
45-
dplyr::rowwise() %>%
46-
dplyr::group_split() %>%
47-
purrr::walk(
48-
~ test_regional_dataset(
49-
source = .$source[[1]],
50-
level = .$level[[1]],
51-
download = download
44+
# apply tests to each data source in turn
45+
sources %>%
46+
dplyr::rowwise() %>%
47+
dplyr::group_split() %>%
48+
purrr::walk(
49+
~ test_regional_dataset(
50+
source = .$source[[1]],
51+
level = .$level[[1]],
52+
download = download
53+
)
5254
)
53-
)
55+
}

0 commit comments

Comments
 (0)