Skip to content

Commit c5294bb

Browse files
committed
tests: only use public functions
1 parent b43aecf commit c5294bb

File tree

2 files changed

+52
-49
lines changed

2 files changed

+52
-49
lines changed

tests/testthat/helper-functions.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
local_logger_threshold <- function(threshold, envir = parent.frame()) {
2+
old <- logger::log_threshold(namespace = "teal.modules.general")
3+
if (!requireNamespace("withr", quietly = FALSE)) {
4+
return(invisible(old))
5+
}
6+
withr::defer(logger::log_threshold(old, namespace = "teal.modules.general"), envir = envir)
7+
logger::log_threshold(threshold, namespace = "teal.modules.general")
8+
invisible(old)
9+
}

tests/testthat/test-utils.R

Lines changed: 43 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,44 @@
11
testthat::test_that("assert_single_selection succeeds if all elements have multiple choices disabled", {
2+
# Suppress logger messages
3+
local_logger_threshold(logger::FATAL)
4+
25
mock_spec <- data_extract_spec(
36
dataname = "MOCK_DATASET",
47
select = teal.transform::select_spec(choices = c("A", "B"), multiple = FALSE)
58
)
69

7-
testthat::expect_true(assert_single_selection(list(mock_spec)))
8-
testthat::expect_true(assert_single_selection(list(mock_spec, mock_spec)))
10+
testthat::expect_s3_class(
11+
tm_g_bivariate(
12+
"a label",
13+
mock_spec,
14+
mock_spec
15+
),
16+
"teal_module"
17+
)
18+
19+
testthat::expect_s3_class(
20+
tm_g_bivariate(
21+
"a label",
22+
list(mock_spec),
23+
mock_spec
24+
),
25+
"teal_module"
26+
)
27+
28+
testthat::expect_s3_class(
29+
tm_g_bivariate(
30+
"a label",
31+
list(mock_spec, mock_spec),
32+
mock_spec
33+
),
34+
"teal_module"
35+
)
936
})
1037

1138
testthat::test_that("assert_single_selection fails when multiple selection is selected in any of the specs", {
39+
# Suppress logger messages
40+
local_logger_threshold(logger::FATAL)
41+
1242
mock_spec <- data_extract_spec(
1343
dataname = "MOCK_DATASET",
1444
select = teal.transform::select_spec(choices = c("A", "B"), multiple = TRUE)
@@ -21,56 +51,20 @@ testthat::test_that("assert_single_selection fails when multiple selection is se
2151
x <- list(mock_spec)
2252

2353
testthat::expect_error(
24-
assert_single_selection(x),
25-
"'x' should not allow multiple selection"
26-
)
27-
testthat::expect_error(
28-
assert_single_selection(list(mock_spec2, mock_spec), .var.name = "x"),
29-
"'x' should not allow multiple selection"
30-
)
31-
})
32-
33-
testthat::test_that("assert_single_selection fails when multiple selection is enabled", {
34-
mock_spec <- data_extract_spec(
35-
dataname = "MOCK_DATASET",
36-
select = teal.transform::select_spec(choices = c("A", "B"), multiple = TRUE)
37-
)
38-
39-
# Suppress logger messages
40-
logger::with_log_threshold(
41-
testthat::expect_error(
42-
tm_g_bivariate(
43-
"a label",
44-
mock_spec,
45-
mock_spec
46-
),
47-
"'x' should not allow multiple selection"
54+
tm_g_bivariate(
55+
"a label",
56+
x,
57+
x
4858
),
49-
threshold = logger::FATAL,
50-
namespace = "teal.modules.general"
51-
)
52-
})
53-
54-
testthat::test_that("assert_single_selection succeeds when multiple selection is disabled", {
55-
mock_spec <- data_extract_spec(
56-
dataname = "ADSL",
57-
select = teal.transform::select_spec(
58-
choices = c("USUBJID", "AGE"),
59-
multiple = FALSE
60-
)
59+
"'x' should not allow multiple selection"
6160
)
6261

63-
# Suppress logger messages
64-
logger::with_log_threshold(
65-
testthat::expect_s3_class(
66-
tm_g_bivariate(
67-
"a label",
68-
mock_spec,
69-
mock_spec
70-
),
71-
"teal_module"
62+
testthat::expect_error(
63+
tm_g_bivariate(
64+
"a label",
65+
list(mock_spec2, mock_spec, data_extract_spec("EMPTY")),
66+
x
7267
),
73-
threshold = logger::FATAL,
74-
namespace = "teal.modules.general"
68+
"'x' should not allow multiple selection"
7569
)
7670
})

0 commit comments

Comments
 (0)