Skip to content

Commit 975c289

Browse files
Add prelim tests with dummy test data
1 parent 9278beb commit 975c289

File tree

4 files changed

+120
-0
lines changed

4 files changed

+120
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
scenario_type,scenario_type_description,scenario,scenario_description,file
2+
disease-rout,Routine Only,disease-rout,disease-rout,no-vaccination.csv
3+
novac,No Vaccination,disease-no-vaccination,No vaccination,with-vaccination.csv
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"scenario_type","scenario_type_description","scenario","scenario_description","coverage_set","gavi_support_level","source_from","disease","vaccine","activity_type","year","country","age_from","age_to","age_range_verbatim","target","coverage","gender","proportion_risk"
2+
"disease_rout","Routine Only","disease_rout","disease_rout","disease : disease , routine ,with: disease_rout","with","scenario_source","disease","disease","routine",2030,"RFP",0,0,"default routine age","NA",0.8,"Both",1
3+
"disease_rout","Routine Only","disease_rout","disease_rout","disease : disease , routine ,with: disease_rout","with","scenario_source","disease","disease","routine",2031,"RFP",0,0,"default routine age","NA",0.8,"Both",1
4+
"disease_rout","Routine Only","disease_rout","disease_rout","disease : disease , routine ,with: disease_rout","with","scenario_source","disease","disease","routine",2032,"RFP",0,0,"default routine age","NA",0.8,"Both",1
5+
"disease_rout","Routine Only","disease_rout","disease_rout","disease : disease , routine ,with: disease_rout","with","scenario_source","disease","disease","routine",2033,"RFP",0,0,"default routine age","NA",0.8,"Both",1
6+
"disease_rout","Routine Only","disease_rout","disease_rout","disease : disease , routine ,with: disease_rout","with","scenario_source","disease","disease","routine",2034,"RFP",0,0,"default routine age","NA",0.8,"Both",1
7+
"disease_rout","Routine Only","disease_rout","disease_rout","disease : disease , routine ,with: disease_rout","with","scenario_source","disease","disease","routine",2035,"RFP",0,0,"default routine age","NA",0.8,"Both",1
8+
"disease_rout","Routine Only","disease_rout","disease_rout","disease : disease , routine ,with: disease_rout","with","scenario_source","disease","disease","routine",2036,"RFP",0,0,"default routine age","NA",0.8,"Both",1
9+
"disease_rout","Routine Only","disease_rout","disease_rout","disease : disease , routine ,with: disease_rout","with","scenario_source","disease","disease","routine",2037,"RFP",0,0,"default routine age","NA",0.8,"Both",1
10+
"disease_rout","Routine Only","disease_rout","disease_rout","disease : disease , routine ,with: disease_rout","with","scenario_source","disease","disease","routine",2038,"RFP",0,0,"default routine age","NA",0.8,"Both",1
11+
"disease_rout","Routine Only","disease_rout","disease_rout","disease : disease , routine ,with: disease_rout","with","scenario_source","disease","disease","routine",2039,"RFP",0,0,"default routine age","NA",0.8,"Both",1
12+
"disease_rout","Routine Only","disease_rout","disease_rout","disease : disease , routine ,with: disease_rout","with","scenario_source","disease","disease","routine",2040,"RFP",0,0,"default routine age","NA",0.8,"Both",1
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
test_that("`validate_file_dict_template()` works", {
2+
# set up local tempdir to test missing bad file error msg
3+
wd <- withr::local_tempdir()
4+
5+
path_burden <- file.path(wd, "incoming_burden_estimates")
6+
dir.create(path_burden)
7+
file_dict <- file.path(path_burden, "file_dictionary.csv")
8+
dummy_data <- data.frame()
9+
readr::write_csv(dummy_data, file_dict)
10+
11+
success_msg <- glue::glue(
12+
"(File dictionary found at)*({file_dict})*(no action needed)"
13+
)
14+
fail_msg <- "(File dictionary found)*(but it is not well formed)"
15+
16+
expect_error(
17+
validate_file_dict_template(
18+
disease,
19+
path_burden
20+
),
21+
fail_msg
22+
)
23+
24+
# check success segment
25+
path_burden <- test_path("incoming_burden_estimates")
26+
expect_message(
27+
validate_file_dict_template(
28+
disease,
29+
path_burden
30+
),
31+
success_msg
32+
)
33+
34+
validate_file_dict_template(
35+
"dummy_disease",
36+
test_path("incoming_burden_estimates")
37+
)
38+
39+
# TODO: check other branch of if-else ladder
40+
})
41+
42+
test_that("`validate_complete_incoming_files()`", {
43+
# set up local tempdir with bad file dictionary to check errors
44+
wd <- withr::local_tempdir()
45+
46+
path_burden <- file.path(wd, "incoming_burden_estimates")
47+
dir.create(path_burden)
48+
49+
fail_msg <- "(Expected a file dictionary)*(but it was not found)"
50+
expect_error(
51+
validate_complete_incoming_files(path_burden),
52+
fail_msg
53+
)
54+
55+
file_dict <- file.path(path_burden, "file_dictionary.csv")
56+
dummy_data <- make_novax_scenario("dummy_disease")
57+
dummy_data <- rbind(dummy_data, dummy_data)
58+
n_duplicates <- anyDuplicated(dummy_data)
59+
readr::write_csv(dummy_data, file_dict)
60+
61+
fail_msg <- glue::glue(
62+
"(Expected)*(non-duplicate entries)*(found {n_duplicates} duplicated rows)"
63+
)
64+
expect_error(
65+
validate_complete_incoming_files(path_burden),
66+
fail_msg
67+
)
68+
69+
# check error on duplicated filenames
70+
dummy_data <- readr::read_csv(
71+
test_path("incoming_burden_estimates", "file_dictionary.csv")
72+
)
73+
dummy_data$file <- "dummy_file.csv"
74+
readr::write_csv(dummy_data, file_dict)
75+
76+
fail_msg <- "(Expected)*(non-duplicate scenario filenames)"
77+
expect_error(
78+
validate_complete_incoming_files(path_burden),
79+
fail_msg
80+
)
81+
82+
# check error on missing scenario files
83+
dummy_data <- readr::read_csv(
84+
test_path("incoming_burden_estimates", "file_dictionary.csv")
85+
)
86+
readr::write_csv(dummy_data, file_dict)
87+
fail_msg <- "Expected as many scenario data files as scenarios"
88+
expect_error(
89+
validate_complete_incoming_files(path_burden),
90+
fail_msg
91+
)
92+
})

tests/testthat/test-helpers.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Basic checks on internal functions. These are mostly checked via exported
2+
# functions for a smaller testing surface
3+
test_that("`make_novax_scenario()` works", {
4+
disease <- "dummy"
5+
expect_no_condition(
6+
make_novax_scenario(disease)
7+
)
8+
df <- make_novax_scenario(disease)
9+
expect_named(
10+
df,
11+
file_dict_colnames
12+
)
13+
})

0 commit comments

Comments
 (0)