Skip to content

Commit

Permalink
Issue #194: Update tests to expect particular warnings (#422)
Browse files Browse the repository at this point in the history
* Add snapshot test for replacing prior error

* Lint changes
  • Loading branch information
athowes authored Nov 13, 2024
1 parent 6f84c3e commit 258fd13
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
56 changes: 56 additions & 0 deletions tests/testthat/_snaps/utils.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# .replace_prior errors when passed a new prior without a match in old_prior [plain]

Code
.replace_prior(old_prior, new_prior, warn = TRUE)
Condition
Warning:
! One or more priors have no match in existing parameters:
Intercept_shape ~ normal(0, 5)
i To remove this warning consider changing prior specification.
Output
prior class coef group resp dpar nlpar lb ub source
normal(0, 5) Intercept <NA> <NA> user
normal(0, 5) Intercept sigma <NA> <NA> user

# .replace_prior errors when passed a new prior without a match in old_prior [ansi]

Code
.replace_prior(old_prior, new_prior, warn = TRUE)
Condition
Warning:
! One or more priors have no match in existing parameters:
Intercept_shape ~ normal(0, 5)
i To remove this warning consider changing prior specification.
Output
prior class coef group resp dpar nlpar lb ub source
normal(0, 5) Intercept <NA> <NA> user
normal(0, 5) Intercept sigma <NA> <NA> user

# .replace_prior errors when passed a new prior without a match in old_prior [unicode]

Code
.replace_prior(old_prior, new_prior, warn = TRUE)
Condition
Warning:
! One or more priors have no match in existing parameters:
Intercept_shape ~ normal(0, 5)
ℹ To remove this warning consider changing prior specification.
Output
prior class coef group resp dpar nlpar lb ub source
normal(0, 5) Intercept <NA> <NA> user
normal(0, 5) Intercept sigma <NA> <NA> user

# .replace_prior errors when passed a new prior without a match in old_prior [fancy]

Code
.replace_prior(old_prior, new_prior, warn = TRUE)
Condition
Warning:
! One or more priors have no match in existing parameters:
Intercept_shape ~ normal(0, 5)
ℹ To remove this warning consider changing prior specification.
Output
prior class coef group resp dpar nlpar lb ub source
normal(0, 5) Intercept <NA> <NA> user
normal(0, 5) Intercept sigma <NA> <NA> user

7 changes: 5 additions & 2 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ test_that(".replace_prior successfully replaces priors", { # nolint: line_length
expect_s3_class(prior, "data.frame")
})

test_that(".replace_prior errors when passed a new prior without a match in old_prior", { # nolint: line_length_linter.
cli::test_that_cli(".replace_prior errors when passed a new prior without a match in old_prior", { # nolint: line_length_linter.
old_prior <- brms::prior("normal(0, 10)", class = "Intercept") +
brms::prior("normal(0, 10)", class = "Intercept", dpar = "sigma")
new_prior <- brms::prior("normal(0, 5)", class = "Intercept") +
brms::prior("normal(0, 5)", class = "Intercept", dpar = "sigma") +
brms::prior("normal(0, 5)", class = "Intercept", dpar = "shape")
expect_warning(.replace_prior(old_prior, new_prior, warn = TRUE))

expect_snapshot({
.replace_prior(old_prior, new_prior, warn = TRUE)
})
})

test_that(".add_dpar_info works as expected for the lognormal and gamma families", { # nolint: line_length_linter.
Expand Down

0 comments on commit 258fd13

Please sign in to comment.