Skip to content

Commit e7f2158

Browse files
authored
Merge pull request #554 from fweber144/testthat_v3.3.0
Adapt tests to testthat v3.3.0
2 parents f67693c + db799c5 commit e7f2158

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

tests/testthat/helpers/expectors.R

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# A customized version of vdiffr::expect_doppelganger() that is needed because
2+
# in 'testthat' versions >= 3.3.0, testthat::expect_snapshot_file() (upon which
3+
# vdiffr::expect_doppelganger() builds) errors if the snapshot file name has
4+
# already been used.
5+
expect_doppelganger_cust <- function(title,
6+
fig,
7+
test_filename = "methods_vsel",
8+
...) {
9+
snap_nm_old <- testthat::test_path(
10+
"_snaps", test_filename, paste0(tolower(gsub("\\.|_", "-", title)), ".svg")
11+
)
12+
if (packageVersion("testthat") >= "3.3.0" && file.exists(snap_nm_old)) {
13+
variant_tmp <- paste0("tmp_doppelganger__",
14+
format(Sys.time(), format = "%Y-%m-%d_%H-%M-%S"))
15+
vdiffr::expect_doppelganger(title, fig, variant = variant_tmp, ...)
16+
snap_nm_new <- sub("_snaps", file.path("_snaps", variant_tmp), snap_nm_old)
17+
expect_true(compare_file_text(old = snap_nm_old,
18+
new = snap_nm_new),
19+
info = title)
20+
file.remove(snap_nm_new)
21+
file.remove(testthat::test_path("_snaps", variant_tmp, test_filename))
22+
file.remove(testthat::test_path("_snaps", variant_tmp))
23+
} else {
24+
vdiffr::expect_doppelganger(title = title, fig = fig, ...)
25+
}
26+
return(invisible(TRUE))
27+
}

tests/testthat/helpers/testers.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2980,7 +2980,7 @@ plot_vsel_tester <- function(
29802980
expect_identical(attr(plot_vsel, "projpred_ranking_abbreviated"),
29812981
attr_abbv_expected, info = info_str)
29822982
if (run_snaps) {
2983-
vdiffr::expect_doppelganger(info_str, plot_vsel)
2983+
expect_doppelganger_cust(info_str, plot_vsel)
29842984
}
29852985

29862986
return(invisible(TRUE))

tests/testthat/setup.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ source(testthat::test_path("helpers", "formul_handlers.R"), local = TRUE)
164164
source(testthat::test_path("helpers", "predictor_handlers.R"), local = TRUE)
165165
source(testthat::test_path("helpers", "dummies.R"), local = TRUE)
166166
source(testthat::test_path("helpers", "creators.R"), local = TRUE)
167+
source(testthat::test_path("helpers", "expectors.R"), local = TRUE)
167168

168169
# Note: The following `mod_nms` refer to *generalized* (linear/additive,
169170
# multilevel) models. This is due to history (when these tests were written,

tests/testthat/test_methods_vsel.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ test_that("`x` of class `cv_proportions` works", {
752752
for (tstsetup in names(plotprs)) {
753753
expect_s3_class(plotprs[[tstsetup]], c("gg", "ggplot"))
754754
if (run_snaps) {
755-
vdiffr::expect_doppelganger(tstsetup, plotprs[[tstsetup]])
755+
expect_doppelganger_cust(tstsetup, plotprs[[tstsetup]])
756756
}
757757
}
758758
})
@@ -768,7 +768,7 @@ test_that("plot.ranking() is a shortcut", {
768768
))
769769
expect_s3_class(plotpr_from_rk, c("gg", "ggplot"))
770770
if (run_snaps) {
771-
vdiffr::expect_doppelganger(tstsetup, plotpr_from_rk)
771+
expect_doppelganger_cust(tstsetup, plotpr_from_rk)
772772
}
773773
}
774774
})

0 commit comments

Comments
 (0)