Skip to content

Commit

Permalink
removing some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
larmarange committed Aug 23, 2024
1 parent e47e277 commit 2d6cabc
Showing 1 changed file with 0 additions and 203 deletions.
203 changes: 0 additions & 203 deletions tests/testthat/test-select_helpers.R
Original file line number Diff line number Diff line change
@@ -1,39 +1,3 @@
test_that("select_helpers: .select_to_varnames", {
expect_error(
.select_to_varnames(mpg)
)

expect_equal(
.select_to_varnames(select = c(hp, mpg), data = mtcars),
dplyr::select(mtcars, hp, mpg) |> colnames()
)

expect_equal(
.select_to_varnames(select = mpg, data = mtcars),
dplyr::select(mtcars, mpg) |> colnames()
)

expect_equal(
.select_to_varnames(select = "mpg", data = mtcars),
dplyr::select(mtcars, "mpg") |> colnames()
)

expect_equal(
.select_to_varnames(select = c("hp", "mpg"), data = mtcars),
dplyr::select(mtcars, c("hp", "mpg")) |> colnames()
)

expect_equal(
.select_to_varnames(select = c(hp, mpg), data = mtcars),
dplyr::select(mtcars, c(hp, mpg)) |> colnames()
)

expect_equal(
.select_to_varnames(select = NULL, data = mtcars),
NULL
)
})

test_that("select_helpers: all_*()", {
mod <- glm(response ~ age * trt + grade, gtsummary::trial, family = binomial)
mod_tidy <- tidy_and_attach(mod)
Expand Down Expand Up @@ -251,172 +215,5 @@ test_that("select_helpers: tidy_add_variable_labels", {
)
})

test_that("select_helpers: .select_to_varnames", {
expect_error(
.select_to_varnames(c(mpg, hp), data = mtcars, select_single = TRUE)
)
})

test_that("select_helpers: .formula_list_to_named_list ", {
mod <- glm(response ~ age * trt + grade, gtsummary::trial, family = binomial)
tidy_mod <- tidy_plus_plus(mod)

expect_error(
.formula_list_to_named_list(list(age ~ "Age", TRUE), var_info = tidy_mod)
)

expect_error(
.formula_list_to_named_list(list(age ~ "Age"),
var_info = tidy_mod,
type_check = is.character
),
NA
)
expect_error(
.formula_list_to_named_list(list(age ~ "Age"),
var_info = tidy_mod,
type_check = is.logical
)
)
expect_error(
.formula_list_to_named_list(letters,
var_info = tidy_mod,
type_check = is.logical
)
)

expect_equal(
.formula_list_to_named_list(age ~ "Age", var_info = tidy_mod),
list(age = "Age")
)

expect_equal(
.formula_list_to_named_list(~"Age", var_info = tidy_mod),
list(age = "Age", trt = "Age", grade = "Age", `age:trt` = "Age")
)
expect_equal(
.formula_list_to_named_list(list(~"Age", `age:trt` = "interact"), var_info = tidy_mod),
list(age = "Age", trt = "Age", grade = "Age", `age:trt` = "interact")
)

expect_error(
.formula_list_to_named_list(list(age ~ "Age"),
var_info = tidy_mod, type_check = is.logical,
arg_name = "label"
)
)
expect_error(
.formula_list_to_named_list(list(age ~ "Age"),
var_info = tidy_mod,
type_check = is.logical, arg_name = "label",
type_check_msg = "Age msg error"
),
"Age msg error"
)
expect_error(
.formula_list_to_named_list("Age",
var_info = tidy_mod,
type_check = rlang::is_string,
arg_name = "label"
),
"Did you mean `everything"
)
expect_error(
.formula_list_to_named_list("Age",
var_info = tidy_mod,
type_check = rlang::is_string,
arg_name = "label"
),
"Age"
)
expect_error(
.formula_list_to_named_list(~"Age",
var_info = tidy_mod,
type_check = rlang::is_string,
arg_name = "label"
),
NA
)

expect_error(
.formula_list_to_named_list(list(age ~ NULL),
var_info = tidy_mod,
type_check = is.logical
),
NA
)
expect_error(
.formula_list_to_named_list(list(age ~ NULL),
var_info = tidy_mod,
type_check = is.logical, null_allowed = FALSE
)
)
expect_error(
select_test <-
.formula_list_to_named_list(
list(response = "Response", dplyr::contains("age") ~ "?AGE?", trt = NULL),
data = gtsummary::trial,
arg_name = "label",
type_check = rlang::is_string,
type_check_msg = NULL,
null_allowed = TRUE
),
NA
)
expect_equal(
select_test,
list(response = "Response", age = "?AGE?", stage = "?AGE?", trt = NULL)
)

expect_error(
.formula_list_to_named_list(
list(response = "Response", dplyr::contains("age") ~ "?AGE?", trt = NULL),
data = gtsummary::trial,
arg_name = "label",
type_check = rlang::is_string,
type_check_msg = NULL,
null_allowed = FALSE
)
)

expect_error(
.formula_list_to_named_list(
list(response = "Response", dplyr::contains("age") ~ "?AGE?", trt = NULL),
data = gtsummary::trial,
arg_name = "label",
select_single = TRUE
)
)
expect_error(
.formula_list_to_named_list(
list(response = "Response", dplyr::contains("age") ~ "?AGE?", trt = NULL),
data = gtsummary::trial,
select_single = TRUE
)
)
})


test_that("select_helpers: .scope_var_info", {
mod_tidy <- lm(mpg ~ hp, mtcars) |> tidy_and_attach()

# can scope a data frame with no variable
expect_error(
.scope_var_info(mod_tidy |> tidy_identify_variables()), NA
)

# no error when non-data frame is scoped
expect_error(
.scope_var_info(mod_tidy$term), NA
)
})


test_that("select_helpers: .var_info_to_df ", {
mod_tidy <- lm(mpg ~ hp, mtcars) |> tidy_and_attach()

# can convert a tibble without a var_class column
expect_error(
.var_info_to_df(mod_tidy |> tidy_identify_variables() |> dplyr::select(-var_class)), NA
)
})

0 comments on commit 2d6cabc

Please sign in to comment.