Skip to content

Commit

Permalink
Skips more tests if on newer R where warnings are not thrown
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludvig committed Jan 26, 2023
1 parent 926f793 commit a1532f8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 16 deletions.
16 changes: 13 additions & 3 deletions R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,19 @@ skip_test_if_old_R_version <- function(min_R_version = "3.6") {
}
}

skip_test_if_new_R_version <- function(max_major, max_minor) {
if (getRversion()$major > max_major || getRversion()$major == max_major && getRversion()$minor > max_minor) {
testthat::skip(message = paste0("Skipping test as R version is > ", max_major, ".", max_minor, "."))
is_newer_R_version <- function(max_major, max_minor) {
getRversion()$major > max_major ||
getRversion()$major == max_major && getRversion()$minor > max_minor
}
skip_test_if_newer_R_version <- function(max_major, max_minor) {
if (is_newer_R_version(max_major = max_major, max_minor = max_minor)) {
testthat::skip(message = paste0(
"Skipping test as R version is > ",
max_major,
".",
max_minor,
"."
))
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test_cross_validate_fn.R
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ test_that("gaussian lm model works with cross_validate_fn()", {
# Error when formulas have random effects but lm model

# Skips if R version is 4.3 or above
skip_test_if_new_R_version(max_major=4, max_minor=2)
skip_test_if_newer_R_version(max_major=4, max_minor=2)

# Cross-validate the model function
warnings_and_messages <- dplyr::bind_rows(
Expand Down
32 changes: 20 additions & 12 deletions tests/testthat/test_validate_fn.R
Original file line number Diff line number Diff line change
Expand Up @@ -1043,8 +1043,10 @@ test_that("fuzz testing validate_fn()", {
# Testing side effects
# Assigning side effects
side_effects_16417 <- xpectr::capture_side_effects(validate_fn(train_data = dat_ready, formulas = "diagnosis~score+(1|session)", type = "binomial", model_fn = glm_model_fn, predict_fn = glm_predict_fn, test_data = NULL, preprocess_fn = glm_preprocess_fn, preprocess_once = FALSE, hyperparameters = hparams, partitions_col = ".partitions", cutoff = 0.5, positive = 2, metrics = list(all = FALSE, Accuracy = TRUE, Sensitivity = TRUE), rm_nc = FALSE, parallel = FALSE, verbose = FALSE), reset_seed = TRUE)
for (w in side_effects_16417[['warnings']]){
expect_match(xpectr::strip(w), "rank[[:space:]]*deficient", fixed=FALSE)
if (!is_newer_R_version(4,2)){
for (w in side_effects_16417[['warnings']]){
expect_match(xpectr::strip(w), "rank[[:space:]]*deficient", fixed=FALSE)
}
}
expect_equal(
xpectr::strip(side_effects_16417[['messages']]),
Expand Down Expand Up @@ -1077,10 +1079,12 @@ test_that("fuzz testing validate_fn()", {
output_16417[["Convergence Warnings"]],
c(0, 0, 0, 0),
tolerance = 1e-4)
expect_equal(
output_16417[["Other Warnings"]],
c(1, 1, 1, 1),
tolerance = 1e-4)
if (!is_newer_R_version(4,2)){
expect_equal( # Does not throw these warnings in 4.3
output_16417[["Other Warnings"]],
c(1, 1, 1, 1),
tolerance = 1e-4)
}
expect_equal(
output_16417[["Dependent"]],
c("diagnosis", "diagnosis", "diagnosis", "diagnosis"),
Expand Down Expand Up @@ -2357,8 +2361,10 @@ test_that("fuzz testing gaussian lm model with validate_fn()",{
# Testing side effects
# Assigning side effects
side_effects_15190 <- xpectr::capture_side_effects(validate_fn(train_data = dat_ready, formulas = "score ~ diagnosis + (1|session)", type = "gaussian", model_fn = lm_model_fn, predict_fn = lm_predict_fn, test_data = NULL, preprocess_fn = NULL, preprocess_once = FALSE, hyperparameters = list(a = c(1, 2), b = c(2)), partitions_col = ".partitions", metrics = list(all = FALSE, RMSE = TRUE), rm_nc = FALSE, parallel = FALSE, verbose = FALSE), reset_seed = TRUE)
for (w in side_effects_15190[['warnings']]){
expect_match(xpectr::strip(w), "rank[[:space:]]*deficient", fixed=FALSE)
if (!is_newer_R_version(4,2)){
for (w in side_effects_15190[['warnings']]){
expect_match(xpectr::strip(w), "rank[[:space:]]*deficient", fixed=FALSE)
}
}
expect_equal(
xpectr::strip(side_effects_15190[['messages']]),
Expand All @@ -2384,10 +2390,12 @@ test_that("fuzz testing gaussian lm model with validate_fn()",{
output_15190[["Convergence Warnings"]],
c(0, 0),
tolerance = 1e-4)
expect_equal(
output_15190[["Other Warnings"]],
c(1, 1),
tolerance = 1e-4)
if (!is_newer_R_version(4,2)){
expect_equal( # Does not throw these warnings in 4.3
output_15190[["Other Warnings"]],
c(1, 1),
tolerance = 1e-4)
}
expect_equal(
output_15190[["Dependent"]],
c("score", "score"),
Expand Down

0 comments on commit a1532f8

Please sign in to comment.