Skip to content

Commit 52301d2

Browse files
authored
Merge pull request #134 from mllg/master
Fix tests for upcoming checkmate
2 parents 5561fd2 + 65a827c commit 52301d2

File tree

4 files changed

+18
-36
lines changed

4 files changed

+18
-36
lines changed

tests/testthat/test-double_ml_data.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ test_that("Unit tests for DoubleMLData", {
371371
d_cols = d_indx,
372372
z_cols = z_indx)
373373

374-
msg12 = "Assertion on 'treatment_var' failed: Must be a subset of \\{'d'\\}, but is \\{'X1'\\}."
374+
msg12 = "Assertion on 'treatment_var' failed: Must be a subset of \\{'d'\\}"
375375
expect_error(D11$set_data_model(X_cols1[1]),
376376
regexp = msg12)
377377
}

tests/testthat/test-double_ml_data_active_bindings.R

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ test_that("x_cols setter", {
1818

1919
msg = paste0(
2020
"Assertion on 'x_cols' failed: Must be a subset of",
21-
" \\{'X1','X2','X3','X4','X5','X6','X7','X8','X9','X10','X11','X12','X13','X14','X15','X16','X17','X18','X19','X20','y','d'\\},",
22-
" but is \\{'X1','X11','A13'\\}.")
21+
" \\{'X1','X2','X3','X4','X5','X6','X7','X8','X9','X10','X11','X12','X13','X14','X15','X16','X17','X18','X19','X20','y','d'\\}")
2322
expect_error(dml_data$x_cols <- c("X1", "X11", "A13"),
2423
regexp = msg)
2524

@@ -55,15 +54,13 @@ test_that("d_cols setter", {
5554

5655
msg = paste0(
5756
"Assertion on 'd_cols' failed: Must be a subset of",
58-
" \\{'X1','X2','X3','X4','X5','X6','X7','y','d1','d2'\\},",
59-
" but is \\{'d1','d13'\\}.")
57+
" \\{'X1','X2','X3','X4','X5','X6','X7','y','d1','d2'\\}")
6058
expect_error(dml_data$d_cols <- c("d1", "d13"),
6159
regexp = msg)
6260

6361
msg = paste0(
6462
"Assertion on 'd_cols' failed: Must be a subset of",
65-
" \\{'X1','X2','X3','X4','X5','X6','X7','y','d1','d2'\\},",
66-
" but is \\{'d13'\\}.")
63+
" \\{'X1','X2','X3','X4','X5','X6','X7','y','d1','d2'\\}")
6764
expect_error(dml_data$d_cols <- "d13",
6865
regexp = msg)
6966

@@ -99,15 +96,13 @@ test_that("z_cols setter", {
9996

10097
msg = paste0(
10198
"Assertion on 'z_cols' failed: Must be a subset of",
102-
" \\{'X1','X2','X3','X4','z1','z2','z3','y','d1','d2'\\},",
103-
" but is \\{'z1','a13'\\}.")
99+
" \\{'X1','X2','X3','X4','z1','z2','z3','y','d1','d2'\\}")
104100
expect_error(dml_data$z_cols <- c("z1", "a13"),
105101
regexp = msg)
106102

107103
msg = paste0(
108104
"Assertion on 'z_cols' failed: Must be a subset of",
109-
" \\{'X1','X2','X3','X4','z1','z2','z3','y','d1','d2'\\},",
110-
" but is \\{'a13'\\}.")
105+
" \\{'X1','X2','X3','X4','z1','z2','z3','y','d1','d2'\\}")
111106
expect_error(dml_data$z_cols <- "a13",
112107
regexp = msg)
113108

@@ -151,8 +146,7 @@ test_that("y_col setter", {
151146

152147
msg = paste0(
153148
"Assertion on 'y_col' failed: Must be a subset of",
154-
" \\{'X1','X2','X3','X4','X5','X6','X7','y','y123','d'\\},",
155-
" but is \\{'d13'\\}.")
149+
" \\{'X1','X2','X3','X4','X5','X6','X7','y','y123','d'\\}")
156150
expect_error(dml_data$y_col <- "d13",
157151
regexp = msg)
158152

@@ -181,15 +175,13 @@ test_that("cluster_cols setter", {
181175

182176
msg = paste0(
183177
"Assertion on 'cluster_cols' failed: Must be a subset of",
184-
" \\{'X1','X2','X3','X4','X5','y','d1','d2','c1','c2'\\},",
185-
" but is \\{'c1','c13'\\}.")
178+
" \\{'X1','X2','X3','X4','X5','y','d1','d2','c1','c2'\\}")
186179
expect_error(dml_data$cluster_cols <- c("c1", "c13"),
187180
regexp = msg)
188181

189182
msg = paste0(
190183
"Assertion on 'cluster_cols' failed: Must be a subset of",
191-
" \\{'X1','X2','X3','X4','X5','y','d1','d2','c1','c2'\\},",
192-
" but is \\{'c13'\\}.")
184+
" \\{'X1','X2','X3','X4','X5','y','d1','d2','c1','c2'\\}")
193185
expect_error(dml_data$cluster_cols <- "c13",
194186
regexp = msg)
195187

@@ -239,7 +231,7 @@ test_that("Tests for use_other_treat_as_covariate", {
239231
expect_error(dml_data$use_other_treat_as_covariate <- 5,
240232
regexp = msg)
241233

242-
msg = "Assertion on 'treatment_var' failed: Must be a subset of \\{'d1','d2'\\}, but is \\{'d3'\\}."
234+
msg = "Assertion on 'treatment_var' failed: Must be a subset of \\{'d1','d2'\\}"
243235
expect_error(dml_data$set_data_model("d3"),
244236
regexp = msg)
245237

tests/testthat/test-double_ml_plr_classifier.R

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ test_that("Unit tests for exception handling of PLR with classifier for ml_m:",
102102
ml_g = mlr3::lrn("regr.rpart"),
103103
ml_m = mlr3::lrn("classif.rpart"))
104104
msg = paste(
105-
"Assertion on 'levels\\(data\\[\\[target\\]\\])' failed:",
106-
"Must be equal to set \\{'0','1'\\}, but is \\{'0','2'\\}.")
105+
"Assertion on 'levels\\(data\\[\\[target\\]\\])' failed: .* set \\{'0','1'\\}")
107106
expect_error(double_mlplr_obj$fit(),
108107
regexp = msg)
109108

@@ -116,8 +115,7 @@ test_that("Unit tests for exception handling of PLR with classifier for ml_m:",
116115
ml_g = mlr3::lrn("regr.rpart"),
117116
ml_m = mlr3::lrn("classif.rpart"))
118117
msg = paste(
119-
"Assertion on 'levels\\(data\\[\\[target\\]\\])' failed:",
120-
"Must be equal to set \\{'0','1'\\}, but is \\{'1','1.5'\\}.")
118+
"Assertion on 'levels\\(data\\[\\[target\\]\\])' failed: .* set \\{'0','1'\\}")
121119
expect_error(double_mlplr_obj$fit(),
122120
regexp = msg)
123121
}

tests/testthat/test-double_ml_set_sample_splitting.R

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ test_that("Unit tests for the method set_sample_splitting of class DoubleML", {
3535
test_ids = list(c(6, 7)),
3636
ids = list(c(8, 9, 10)))
3737
msg = paste(
38-
"Assertion on 'names\\(smpl\\)' failed: Must be equal to set",
39-
"\\{'train_ids','test_ids'\\}, but is",
40-
"\\{'train_ids','test_ids','ids'\\}.")
38+
"Assertion on 'names\\(smpl\\)' failed: .* set \\{'train_ids','test_ids'\\}")
4139
expect_error(dml_plr$set_sample_splitting(smpls),
4240
regexp = msg)
4341

@@ -214,8 +212,7 @@ test_that("Unit tests for the method set_sample_splitting of class DoubleML (inv
214212
test_ids = list(c(2, 4, 6, 8, 10), c(1, 3, 5, 7, 9))))
215213
msg = paste(
216214
"Assertion on 'train_ids' failed: Must be a subset of",
217-
"\\{'1','2','3','4','5','6','7','8','9','10'\\},",
218-
"but is \\{'1','2.2','3','4','5'\\}.")
215+
"\\{'1','2','3','4','5','6','7','8','9','10'\\}")
219216
expect_error(dml_plr$set_sample_splitting(smpls),
220217
regexp = msg)
221218

@@ -228,8 +225,7 @@ test_that("Unit tests for the method set_sample_splitting of class DoubleML (inv
228225
test_ids = list(c(2, 4, 6, 8, 10), c(1, 3, 5, 7, 9))))
229226
msg = paste(
230227
"Assertion on 'train_ids' failed: Must be a subset of",
231-
"\\{'1','2','3','4','5','6','7','8','9','10'\\},",
232-
"but is \\{'2','4.5','6','8','10'\\}.")
228+
"\\{'1','2','3','4','5','6','7','8','9','10'\\}")
233229
expect_error(dml_plr$set_sample_splitting(smpls),
234230
regexp = msg)
235231

@@ -241,9 +237,7 @@ test_that("Unit tests for the method set_sample_splitting of class DoubleML (inv
241237
train_ids = list(c(1, 3, 4, 5, 7, 9), c(2, 4, 6, 8, 10)),
242238
test_ids = list(c(2, 4, 6, 8, 10), c(1, 3, 5, 7, 9))))
243239
msg = paste(
244-
"Assertion on 'smpl\\$train_ids\\[\\[i_fold\\]\\]' failed:",
245-
"Must be disjunct from set \\{'2','4','6','8','10'\\},",
246-
"but has \\{'4'\\}.")
240+
"Assertion on 'smpl\\$train_ids\\[\\[i_fold\\]\\]' failed: .* \\{'2','4','6','8','10'\\}")
247241
expect_error(dml_plr$set_sample_splitting(smpls),
248242
regexp = msg)
249243

@@ -282,8 +276,7 @@ test_that("Unit tests for the method set_sample_splitting of class DoubleML (inv
282276
test_ids = list(c(2, 4, 6, 8, 10), c(1, 3, 5, 7, 9))))
283277
msg = paste(
284278
"Assertion on 'train_ids' failed: Must be a subset of",
285-
"\\{'1','2','3','4','5','6','7','8','9','10'\\},",
286-
"but is \\{'1','2','3','4','5','20'\\}.")
279+
"\\{'1','2','3','4','5','6','7','8','9','10'\\}")
287280
expect_error(dml_plr$set_sample_splitting(smpls),
288281
regexp = msg)
289282

@@ -296,8 +289,7 @@ test_that("Unit tests for the method set_sample_splitting of class DoubleML (inv
296289
test_ids = list(c(2, 4, 6, 8, 10), c(1, 3, 5, 7, 9))))
297290
msg = paste(
298291
"Assertion on 'test_ids' failed: Must be a subset of",
299-
"\\{'1','2','3','4','5','6','7','8','9','10'\\},",
300-
"but is \\{'6','-7','8','9','10'\\}.")
292+
"\\{'1','2','3','4','5','6','7','8','9','10'\\}")
301293
expect_error(dml_plr$set_sample_splitting(smpls),
302294
regexp = msg)
303295
}

0 commit comments

Comments
 (0)