Skip to content

Commit 2ac16df

Browse files
m7prdependabot-preview[bot]averissimo
authored
430 use expect_no_error in tests instead of expect_error(, NA) (#173)
Part of insightsengineering/coredev-tasks#430 --------- Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com> Co-authored-by: André Veríssimo <211358+averissimo@users.noreply.github.com>
1 parent 5f116f2 commit 2ac16df

10 files changed

+40
-45
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ Encoding: UTF-8
5858
Language: en-US
5959
LazyData: true
6060
Roxygen: list(markdown = TRUE)
61-
RoxygenNote: 7.2.3
61+
RoxygenNote: 7.3.0

tests/testthat/test-all_choices.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
testthat::test_that("all_choices constructor does not throw", {
2-
testthat::expect_error(all_choices(), NA)
2+
testthat::expect_no_error(all_choices())
33
})

tests/testthat/test-data_extract_spec.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
testthat::test_that("data_extract_spec throws when select is not select_spec or NULL", {
2-
expect_error(data_extract_spec("toyDataset", select = c("A", "B")))
2+
testthat::expect_error(data_extract_spec("toyDataset", select = c("A", "B")))
33
})
44

55
testthat::test_that("data_extract_spec works with valid input", {
@@ -301,7 +301,7 @@ testthat::test_that("delayed version of data_extract_spec", {
301301
})
302302

303303
testthat::test_that("data_extract_spec allows both select and filter parameters to be NULL", {
304-
testthat::expect_error(des <- data_extract_spec("ADSL"), NA)
304+
testthat::expect_no_error(des <- data_extract_spec("ADSL"))
305305
})
306306

307307
testthat::test_that("data_extract_spec returns filter_spec with multiple set to TRUE", {

tests/testthat/test-filter_spec.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ testthat::test_that("delayed filter_spec", {
176176
multiple = FALSE
177177
)
178178

179-
expect_equal(names(expected_spec), names(delayed))
179+
testthat::expect_equal(names(expected_spec), names(delayed))
180180

181181
data_list <- list(ADSL = reactive(ADSL))
182182
key_list <- list(ADSL = c("STUDYID", "USUBJID"))
@@ -191,7 +191,7 @@ testthat::test_that("filter_spec with choices_selected where all selected in cho
191191
choices = stats::setNames(LETTERS[1:5], paste("Letter", LETTERS[1:5])),
192192
selected = c("A", "B")
193193
)
194-
testthat::expect_error(filter_spec(vars = valid_cs), regexp = NA)
194+
testthat::expect_no_error(filter_spec(vars = valid_cs))
195195
})
196196

197197

@@ -224,7 +224,7 @@ testthat::test_that("filter_spec_internal contains dataname", {
224224
vars_choices = variable_choices(ADSL)
225225
)
226226

227-
expect_null(x_filter$dataname)
227+
testthat::expect_null(x_filter$dataname)
228228

229229
x <- data_extract_spec(
230230
dataname = "ADSL",
@@ -477,7 +477,7 @@ testthat::test_that(
477477
choices = stats::setNames(LETTERS[1:5], paste("Letter", LETTERS[1:5])),
478478
selected = c("A", "B")
479479
)
480-
testthat::expect_error(filter_spec(vars = valid_cs), regexp = NA)
480+
testthat::expect_no_error(filter_spec(vars = valid_cs))
481481
}
482482
)
483483

tests/testthat/test-format_data_extract.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ required_names <- c("select", "filters", "dataname")
33
testthat::test_that("format_data_extract is a function that accepts a list", {
44
data_extract_fake <- as.list(stats::setNames(nm = required_names))
55
data_extract_fake$filters <- list()
6-
testthat::expect_error(format_data_extract(data_extract_fake), regexp = NA)
6+
testthat::expect_no_error(format_data_extract(data_extract_fake))
77
})
88

99
testthat::test_that("format_data_extract asserts its argument has required names", {
@@ -46,7 +46,7 @@ testthat::test_that("format_data_extract integrates with data_extract_srv", {
4646
data_extract_srv,
4747
args = list(data_extract_spec = simple_des, datasets = sample_data),
4848
expr = {
49-
testthat::expect_error(format_data_extract(session$returned()), regexp = NA)
49+
testthat::expect_no_error(format_data_extract(session$returned()))
5050
}
5151
)
5252
})

tests/testthat/test-merge_expression_module.R

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,12 @@ testthat::test_that(
3737
code = {
3838
shiny::withReactiveDomain(
3939
domain = shiny::MockShinySession$new(),
40-
expr = testthat::expect_error(
40+
expr = testthat::expect_no_error(
4141
merge_expression_module(
4242
data_extract = list(adsl_var = adsl_extract, adlb_var = adlb_extract),
4343
datasets = data_list,
4444
join_keys = join_keys
45-
),
46-
NA
45+
)
4746
)
4847
)
4948
}

tests/testthat/test-merge_expression_srv.R

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,15 @@ testthat::test_that("merge_expression_srv throws error if selector_list is not n
173173

174174
testthat::test_that("merge_expression_srv accepts reactive and character merge_function", {
175175
m_fun <- reactive("dplyr::left_join")
176-
testthat::expect_error(
176+
testthat::expect_no_error(
177177
shiny::testServer(
178178
merge_expression_srv,
179179
args = list(selector_list = selector_list, datasets = data_list, join_keys = join_keys, merge_function = m_fun),
180180
expr = session$returned()
181-
),
182-
NA
181+
)
183182
)
184183

185-
testthat::expect_error(
184+
testthat::expect_no_error(
186185
shiny::testServer(
187186
merge_expression_srv,
188187
args = list(
@@ -192,8 +191,7 @@ testthat::test_that("merge_expression_srv accepts reactive and character merge_f
192191
merge_function = "dplyr::left_join"
193192
),
194193
expr = session$returned()
195-
),
196-
NA
194+
)
197195
)
198196
})
199197

@@ -243,21 +241,19 @@ testthat::test_that("merge_expression_srv throws error if join_keys is not a joi
243241
})
244242

245243
testthat::test_that("merge_expression_srv accepts a list of (reactive) data.frames for datasets argument", {
246-
testthat::expect_error(
244+
testthat::expect_no_error(
247245
shiny::testServer(
248246
merge_expression_srv,
249247
args = list(selector_list = selector_list, datasets = data_list, join_keys = join_keys),
250248
expr = NULL
251-
),
252-
NA
249+
)
253250
)
254251

255-
testthat::expect_error(
252+
testthat::expect_no_error(
256253
shiny::testServer(
257254
merge_expression_srv,
258255
args = list(selector_list = selector_list, datasets = data_list_nr, join_keys = join_keys),
259256
expr = NULL
260-
),
261-
NA
257+
)
262258
)
263259
})

tests/testthat/test-select_spec.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ testthat::test_that("Multiple choices", {
7979

8080
testthat::expect_true(c1$multiple)
8181
testthat::expect_false(c1$fixed)
82-
expect_null(c1$always_selected)
82+
testthat::expect_null(c1$always_selected)
8383
testthat::expect_false(c1$ordered)
8484
testthat::expect_identical(c1$label, "Select")
8585
})

tests/testthat/test-value_choices.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ testthat::test_that("Will output warnings when value_choices applied on datasets
2222
testthat::expect_warning(value_choices(data, var_choices = c("A", "F")))
2323
testthat::expect_error(value_choices(data, var_choices = "K"))
2424
testthat::expect_error(value_choices(data, var_choices = "F", var_label = "K"))
25-
testthat::expect_warning(value_choices(data, var_choices = c("J")), NA)
26-
testthat::expect_warning(value_choices(data, var_choices = c("B")), NA)
25+
testthat::expect_no_warning(value_choices(data, var_choices = c("J")))
26+
testthat::expect_no_warning(value_choices(data, var_choices = c("B")))
2727
})
2828

2929
testthat::test_that("delayed version of value_choices", {
3030
# hard-coded subset
3131
obj <- value_choices("ADSL", var_choices = "ARMCD", var_label = "ARM", subset = c("ARM A", "ARM B"))
32-
expect_equal(
32+
testthat::expect_equal(
3333
obj,
3434
structure(
3535
list(
@@ -131,7 +131,7 @@ testthat::test_that("delayed version of value_choices", {
131131
testthat::test_that("delayed version of value_choices - resolve_delayed", {
132132
# hard-coded subset
133133
obj <- value_choices("ADSL", var_choices = "ARMCD", var_label = "ARM", subset = c("ARM A", "ARM B"))
134-
expect_equal(
134+
testthat::expect_equal(
135135
obj,
136136
structure(
137137
list(

tests/testthat/test-variable_choices.R

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@ test_that("Can create variable_choices with datasets with no or missing labels",
88

99
# no labels given
1010
choice_1 <- variable_choices(example_data, fill = TRUE)
11-
expect_equal(names(choice_1), c("USUBJID: USUBJID", "STUDYID: STUDYID"))
11+
testthat::expect_equal(names(choice_1), c("USUBJID: USUBJID", "STUDYID: STUDYID"))
1212

1313
# one missing label
1414
missing_one_label_data <- example_data
1515
teal.data::col_labels(missing_one_label_data) <- c(as.character(NA), "Label")
1616
choice_2 <- variable_choices(missing_one_label_data, fill = FALSE)
17-
expect_equal(names(choice_2), c("USUBJID: Label Missing", "STUDYID: Label"))
17+
testthat::expect_equal(names(choice_2), c("USUBJID: Label Missing", "STUDYID: Label"))
1818

1919
# all missing label
2020
missing_two_label_data <- example_data
2121
teal.data::col_labels(missing_two_label_data) <- c(as.character(NA), as.character(NA))
2222
choice_2 <- variable_choices(missing_two_label_data, fill = FALSE)
23-
expect_equal(names(choice_2), c("USUBJID: Label Missing", "STUDYID: Label Missing"))
23+
testthat::expect_equal(names(choice_2), c("USUBJID: Label Missing", "STUDYID: Label Missing"))
2424
})
2525

2626
test_that("delayed version of variable_choices", {
2727
# hard-coded subset
2828
obj <- variable_choices("ADSL", subset = c("SEX", "ARMCD", "COUNTRY"))
29-
expect_equal(
29+
testthat::expect_equal(
3030
obj,
3131
structure(
3232
list(data = "ADSL", subset = c("SEX", "ARMCD", "COUNTRY"), key = NULL),
@@ -38,14 +38,14 @@ test_that("delayed version of variable_choices", {
3838
key_list <- list(ADSL = c("STUDYID", "USUBJID"), ADTTE = c("STUDYID", "USUBJID", "PARAMCD"))
3939

4040
res_obj <- isolate(resolve(obj, datasets = data_list, keys = key_list))
41-
expect_equal(
41+
testthat::expect_equal(
4242
res_obj,
4343
variable_choices(ADSL, subset = c("SEX", "ARMCD", "COUNTRY"))
4444
)
4545

4646
# functional subset
4747
obj <- variable_choices("ADSL", subset = function(data) colnames(data)[1:2])
48-
expect_equal(
48+
testthat::expect_equal(
4949
obj,
5050
structure(
5151
list(data = "ADSL", subset = function(data) colnames(data)[1:2], key = NULL),
@@ -54,14 +54,14 @@ test_that("delayed version of variable_choices", {
5454
)
5555

5656
res_obj <- isolate(resolve(obj, datasets = data_list, keys = key_list))
57-
expect_equal(
57+
testthat::expect_equal(
5858
res_obj,
5959
variable_choices(ADSL, subset = colnames(ADSL)[1:2], key = c("STUDYID", "USUBJID"))
6060
)
6161

6262
# non-null key value
6363
obj <- variable_choices("ADSL", key = c("USUBJID", "STUDYID"))
64-
expect_equal(
64+
testthat::expect_equal(
6565
obj,
6666
structure(
6767
list(data = "ADSL", subset = NULL, key = c("USUBJID", "STUDYID")),
@@ -70,7 +70,7 @@ test_that("delayed version of variable_choices", {
7070
)
7171

7272
res_obj <- isolate(resolve(obj, datasets = data_list, keys = key_list))
73-
expect_equal(
73+
testthat::expect_equal(
7474
res_obj,
7575
variable_choices(ADSL, key = c("USUBJID", "STUDYID"))
7676
)
@@ -80,7 +80,7 @@ test_that("delayed version of variable_choices", {
8080
test_that("delayed version of variable_choices - resolve_delayed", {
8181
# hard-coded subset
8282
obj <- variable_choices("ADSL", subset = c("SEX", "ARMCD", "COUNTRY"))
83-
expect_equal(
83+
testthat::expect_equal(
8484
obj,
8585
structure(
8686
list(data = "ADSL", subset = c("SEX", "ARMCD", "COUNTRY"), key = NULL),
@@ -89,15 +89,15 @@ test_that("delayed version of variable_choices - resolve_delayed", {
8989
)
9090

9191
res_obj <- isolate(resolve_delayed(obj, datasets = data_list, keys = primary_keys_list))
92-
expect_equal(
92+
testthat::expect_equal(
9393
res_obj,
9494
variable_choices(ADSL, subset = c("SEX", "ARMCD", "COUNTRY"))
9595
)
9696

9797

9898
# functional subset
9999
obj <- variable_choices("ADSL", subset = function(data) colnames(data)[1:2])
100-
expect_equal(
100+
testthat::expect_equal(
101101
obj,
102102
structure(
103103
list(data = "ADSL", subset = function(data) colnames(data)[1:2], key = NULL),
@@ -106,14 +106,14 @@ test_that("delayed version of variable_choices - resolve_delayed", {
106106
)
107107

108108
res_obj <- isolate(resolve_delayed(obj, datasets = data_list, keys = primary_keys_list))
109-
expect_equal(
109+
testthat::expect_equal(
110110
res_obj,
111111
variable_choices(ADSL, subset = colnames(ADSL)[1:2], key = c("STUDYID", "USUBJID"))
112112
)
113113

114114
# non-null key value
115115
obj <- variable_choices("ADSL", key = c("USUBJID", "STUDYID"))
116-
expect_equal(
116+
testthat::expect_equal(
117117
obj,
118118
structure(
119119
list(data = "ADSL", subset = NULL, key = c("USUBJID", "STUDYID")),
@@ -122,7 +122,7 @@ test_that("delayed version of variable_choices - resolve_delayed", {
122122
)
123123

124124
res_obj <- isolate(resolve_delayed(obj, datasets = data_list, keys = primary_keys_list))
125-
expect_equal(
125+
testthat::expect_equal(
126126
res_obj,
127127
variable_choices(ADSL, key = c("USUBJID", "STUDYID"))
128128
)

0 commit comments

Comments
 (0)