Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

430 use expect_no_error in tests instead of expect_error(, NA) #936

Merged
merged 5 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Suggests:
knitr,
lubridate,
nestcolor (>= 0.1.0),
testthat (>= 3.0)
testthat (>= 3.1.5)
VignetteBuilder:
knitr
Config/Needs/website: insightsengineering/nesttemplate
Expand All @@ -78,4 +78,4 @@ Encoding: UTF-8
Language: en-US
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.0
33 changes: 33 additions & 0 deletions man/teal.modules.clinical.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/test-string_ops.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
test_that("`as_num` as a wide interpretation of input to extract numerics.", {
testthat::test_that("`as_num` as a wide interpretation of input to extract numerics.", {
dta <- list(
character = c("text10,20.5letter30.!", "!-.40$$-50e5[", NA),
factor = factor(c("]+60e-6, 7.7%%8L", "%90sep.100\"1L", NA_character_)),
Expand Down
36 changes: 18 additions & 18 deletions tests/testthat/test-substitute_names.R
Original file line number Diff line number Diff line change
@@ -1,76 +1,76 @@
test_that("substitute_q works as expected", {
testthat::test_that("substitute_q works as expected", {
result <- substitute_q(
qexpr = quote(a <- c + d),
env = list(c = 5, d = 3)
)
expected <- quote(a <- 5 + 3)
expect_identical(result, expected)
testthat::expect_identical(result, expected)
})

test_that("substitute_q fails on unquoted call", {
expect_error(substitute_q(c + d, env = list(c = 5, d = 3)))
testthat::test_that("substitute_q fails on unquoted call", {
testthat::expect_error(substitute_q(c + d, env = list(c = 5, d = 3)))
})

test_that("h_subst_lhs_names works as expected", {
testthat::test_that("h_subst_lhs_names works as expected", {
result <- h_subst_lhs_names(
qexpr = quote(c(a = d, b = 3, z = "foo")),
names = list(a = as.name("x"), z = as.name("y"))
)
expected <- quote(c(x = d, b = 3, y = "foo"))
expect_identical(result, expected)
testthat::expect_identical(result, expected)
})

test_that("substitute_lhs_names works as expected with nested expressions", {
testthat::test_that("substitute_lhs_names works as expected with nested expressions", {
result <- substitute_lhs_names(
qexpr = quote(anl <- anl %>% mutate(a = factor(a))),
names = list(a = as.name("AEBODSYS"))
)
expected <- quote(anl <- anl %>% mutate(AEBODSYS = factor(a)))
expect_identical(result, expected)
testthat::expect_identical(result, expected)
})

test_that("substitute_lhs_names does not lead to infinite recursion", {
testthat::test_that("substitute_lhs_names does not lead to infinite recursion", {
result <- substitute_lhs_names(
qexpr = quote(c(a = d, b = 3, z = "foo")),
names = list(b = as.name("x"), z = as.name("y"))
)
expected <- quote(c(a = d, x = 3, y = "foo"))
expect_identical(result, expected)
testthat::expect_identical(result, expected)
})

test_that("substitute_rhs works as expected", {
testthat::test_that("substitute_rhs works as expected", {
result <- substitute_rhs(
qexpr = quote(c(a = d, b = 3, z = "foo")),
env = list(d = as.name("x"), z = as.name("y"))
)
expected <- quote(c(a = x, b = 3, z = "foo"))
expect_identical(result, expected)
testthat::expect_identical(result, expected)
})

test_that("substitute_names works as expected", {
testthat::test_that("substitute_names works as expected", {
result <- substitute_names(
expr = c(a = d, b = 3, z = "foo"),
names = list(d = as.name("x"), z = as.name("y"))
)
expected <- quote(c(a = x, b = 3, y = "foo"))
expect_identical(result, expected)
testthat::expect_identical(result, expected)
})

test_that("substitute_names can also substitute other expressions if requested", {
testthat::test_that("substitute_names can also substitute other expressions if requested", {
result <- substitute_names(
expr = c(a = d, b = 3, z = doo),
names = list(d = as.name("x"), z = as.name("y")),
others = list(doo = "loo")
)
expected <- quote(c(a = x, b = 3, y = "loo"))
expect_identical(result, expected)
testthat::expect_identical(result, expected)
})

test_that("substitute_names works as expected with nested expressions", {
testthat::test_that("substitute_names works as expected with nested expressions", {
result <- substitute_names(
expr = anl <- anl %>% mutate(a = factor(a)),
names = list(a = as.name("AEBODSYS"))
)
expected <- quote(anl <- anl %>% mutate(AEBODSYS = factor(AEBODSYS)))
expect_identical(result, expected)
testthat::expect_identical(result, expected)
})
10 changes: 4 additions & 6 deletions tests/testthat/test-validate_standard_inputs.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@ testthat::test_that("validate_arm throws specific shiny error if arm_vec has jus
})

testthat::test_that("validate_arm throws no error if arm_vec is a factor", {
testthat::expect_error(
validate_arm(factor(c("A", "B"), levels = c("A", "B"))),
NA
testthat::expect_no_error(
validate_arm(factor(c("A", "B"), levels = c("A", "B")))
)

testthat::expect_error(
validate_arm(factor(c("A", "B"), levels = c("A", "B", "C"))),
NA
testthat::expect_no_error(
validate_arm(factor(c("A", "B"), levels = c("A", "B", "C")))
)
})
Loading