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

Issue 228: Use silent = 2 to suppress brms output in tests #230

Merged
merged 1 commit into from
Aug 6, 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
18 changes: 11 additions & 7 deletions tests/testthat/test-int-latent_individual.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test_that("epidist.epidist_latent_individual samples from the prior according to
skip_on_cran()
set.seed(1)
prior_samples <- epidist(
data = prep_obs, fn = brms::brm, sample_prior = "only", seed = 1
data = prep_obs, fn = brms::brm, sample_prior = "only", seed = 1, silent = 2
)
pred <- predict_delay_parameters(prior_samples)
family <- epidist_family(data = prep_obs, family = brms::lognormal())
Expand All @@ -53,7 +53,7 @@ test_that("epidist.epidist_latent_individual fits and the MCMC converges in the
# Note: this test is stochastic. See note at the top of this script
skip_on_cran()
set.seed(1)
fit <- epidist(data = prep_obs, seed = 1)
fit <- epidist(data = prep_obs, seed = 1, silent = 2)
expect_s3_class(fit, "brmsfit")
expect_s3_class(fit, "epidist_fit")
expect_convergence(fit)
Expand All @@ -63,7 +63,7 @@ test_that("epidist.epidist_latent_individual recovers the simulation settings fo
# Note: this test is stochastic. See note at the top of this script
skip_on_cran()
set.seed(1)
fit <- epidist(data = prep_obs, seed = 1)
fit <- epidist(data = prep_obs, seed = 1, silent = 2)
pred <- predict_delay_parameters(fit)
# Unclear the extent to which we should expect parameter recovery here
expect_equal(mean(pred$mu), meanlog, tolerance = 0.1)
Expand Down Expand Up @@ -93,7 +93,8 @@ test_that("epidist.epidist_latent_individual fits and the MCMC converges in the
data = prep_obs_gamma,
family = stats::Gamma(link = "log"),
formula = brms::bf(mu ~ 1, shape ~ 1),
seed = 1
seed = 1,
silent = 2
)
expect_s3_class(fit_gamma, "brmsfit")
expect_s3_class(fit_gamma, "epidist_fit")
Expand All @@ -108,7 +109,8 @@ test_that("epidist.epidist_latent_individual recovers the simulation settings fo
data = prep_obs_gamma,
family = stats::Gamma(link = "log"),
formula = brms::bf(mu ~ 1, shape ~ 1),
seed = 1
seed = 1,
silent = 2
)
# Using the Stan parameterisation of the gamma distribution
draws_gamma <- posterior::as_draws_df(fit_gamma$fit)
Expand Down Expand Up @@ -147,7 +149,8 @@ test_that("epidist.epidist_latent_individual recovers no sex effect when none is
fit_sex <- epidist(
data = prep_obs,
formula = brms::bf(mu ~ 1 + sex, sigma ~ 1 + sex),
seed = 1
seed = 1,
silent = 2
)
draws <- posterior::as_draws_df(fit_sex$fit)
expect_equal(mean(draws$b_sex), 0, tolerance = 0.2)
Expand All @@ -162,7 +165,8 @@ test_that("epidist.epidist_latent_individual fits and the MCMC converges for an
fit_sex <- epidist(
data = prep_obs,
formula = brms::bf(mu ~ 1 + sex, sigma ~ 1 + sex),
seed = 1
seed = 1,
silent = 2
)
expect_s3_class(fit_sex, "brmsfit")
expect_s3_class(fit_sex, "epidist_fit")
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-unit-postprocess.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ test_that("predict_delay_parameters works with NULL newdata and the latent logno
skip_on_cran()
set.seed(1)
prep_obs <- as_latent_individual(sim_obs)
fit <- epidist(data = prep_obs, seed = 1)
fit <- epidist(data = prep_obs, seed = 1, silent = 2)
pred <- predict_delay_parameters(fit)
expect_s3_class(pred, "data.table")
expect_named(pred, c("index", "draw", "mu", "sigma", "mean", "sd"))
Expand All @@ -16,7 +16,7 @@ test_that("predict_delay_parameters accepts newdata arguments", { # nolint: line
skip_on_cran()
set.seed(1)
prep_obs <- as_latent_individual(sim_obs)
fit <- epidist(data = prep_obs, seed = 1)
fit <- epidist(data = prep_obs, seed = 1, silent = 2)
n <- 5
pred <- predict_delay_parameters(fit, newdata = prep_obs[1:n, ])
expect_s3_class(pred, "data.table")
Expand Down