Skip to content

Commit 4be1269

Browse files
committed
a few more cases
1 parent 3af034b commit 4be1269

File tree

6 files changed

+28
-20
lines changed

6 files changed

+28
-20
lines changed

tests/testthat/test-fit-laplace.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
context("fitted-vb")
1+
context("fitted-laplace")
22

33
set_cmdstan_path()
44
fit_laplace <- testing_fit("logistic", method = "laplace", seed = 100)

tests/testthat/test-fit-shared.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ test_that("sampling with inits works with include_paths", {
462462
include_paths = test_path("resources", "stan"))
463463

464464
data_list <- list(N = 10, y = c(0,1,0,0,0,0,0,0,0,1))
465-
expect_no_error(
465+
expect_no_error(utils::capture.output(
466466
fit <- mod_w_include$sample(
467467
data = data_list,
468468
seed = 123,
@@ -474,7 +474,7 @@ test_that("sampling with inits works with include_paths", {
474474
list(theta = 0.25),
475475
list(theta = 0.25))
476476
)
477-
)
477+
))
478478
})
479479

480480
test_that("CmdStanModel created with exe_file works", {

tests/testthat/test-model-compile.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ test_that("dirname of stan_file is used as include path if no other paths suppli
837837

838838
mod_tmp <- cmdstan_model(stan_file, compile = FALSE)
839839
expect_true(mod_tmp$check_syntax())
840-
expect_true(mod_tmp$format())
840+
utils::capture.output(expect_true(mod_tmp$format()))
841841
expect_s3_class(mod_tmp$compile(), "CmdStanModel")
842842
})
843843

tests/testthat/test-model-laplace.R

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ test_that("laplace() method errors for any invalid argument before calling cmdst
3636
for (nm in names(bad_arg_values)) {
3737
args <- ok_arg_values
3838
args[[nm]] <- bad_arg_values[[nm]]
39-
expect_error(do.call(mod$laplace, args), regexp = nm, info = nm)
39+
utils::capture.output(
40+
expect_error(do.call(mod$laplace, args), regexp = nm, info = nm)
41+
)
4042
}
4143
args <- ok_arg_values
4244
args$opt_args <- list(iter = "NOT_A_NUMBER")
@@ -129,14 +131,15 @@ test_that("laplace() errors with bad combinations of arguments", {
129131

130132
test_that("laplace() errors if optimize() fails", {
131133
mod_schools <- testing_model("schools")
132-
expect_error(
133-
expect_warning(
134-
expect_message(
135-
mod_schools$laplace(data = testing_data("schools"), refresh = 0),
136-
"Line search failed to achieve a sufficient decrease"
134+
utils::capture.output(
135+
expect_error(
136+
expect_warning(
137+
expect_message(
138+
mod_schools$laplace(data = testing_data("schools"), refresh = 0),
139+
"Line search failed to achieve a sufficient decrease"
140+
),
141+
"Fitting finished unexpectedly"
137142
),
138-
"Fitting finished unexpectedly"
139-
),
140-
"Optimization failed"
141-
)
143+
"Optimization failed"
144+
))
142145
})

tests/testthat/test-model-pathfinder.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ data_list <- testing_data("bernoulli")
1111
data_file_r <- test_path("resources", "data", "bernoulli.data.R")
1212
data_file_json <- test_path("resources", "data", "bernoulli.data.json")
1313

14-
# these are all valid for sample()
14+
# these are all valid for pathfinder()
1515
ok_arg_values <- list(
1616
data = data_list,
1717
output_dir = tempdir(),
@@ -32,9 +32,10 @@ ok_arg_values <- list(
3232
max_lbfgs_iters = 100,
3333
save_single_paths = FALSE,
3434
calculate_lp = TRUE,
35-
psis_resample=TRUE)
35+
psis_resample=TRUE
36+
)
3637

37-
# using any one of these should cause sample() to error
38+
# using any one of these should cause pathfinder() to error
3839
bad_arg_values <- list(
3940
data = "NOT_A_FILE",
4041
output_dir = "NOT_A_DIRECTORY",

tests/testthat/test-threads.R

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,13 @@ test_that("correct output when stan_threads not TRUE", {
172172
fixed = TRUE
173173
)
174174
mod <- cmdstan_model(stan_program, cpp_options = list(stan_threads = FALSE), force_recompile = TRUE)
175-
expect_warning(
176-
mod$sample(data = data_file_json, threads_per_chain = 4),
177-
"'threads_per_chain' is set but the model was not compiled with 'cpp_options = list(stan_threads = TRUE)' so 'threads_per_chain' will have no effect!",
175+
expect_output(
176+
expect_warning(
177+
mod$sample(data = data_file_json, threads_per_chain = 4),
178+
"'threads_per_chain' is set but the model was not compiled with 'cpp_options = list(stan_threads = TRUE)' so 'threads_per_chain' will have no effect!",
179+
fixed = TRUE
180+
),
181+
"Running MCMC with 4 sequential chains",
178182
fixed = TRUE
179183
)
180184
})

0 commit comments

Comments
 (0)