Skip to content

Commit

Permalink
update tests (#220)
Browse files Browse the repository at this point in the history
closes #219 

--------------------------------------------------------------------------------

Pre-review Checklist (if item does not apply, mark is as complete)
- [x] **All** GitHub Action workflows pass with a ✅
- [x] PR branch has pulled the most recent updates from master branch:
`usethis::pr_merge_main()`
- [x] If a bug was fixed, a unit test was added.
- [ ] If a new `ard_*()` function was added, it passes the ARD
structural checks from `cards::check_ard_structure()`.
- [ ] If a new `ard_*()` function was added, `set_cli_abort_call()` has
been set.
- [ ] If a new `ard_*()` function was added and it depends on another
package (such as, `broom`), `is_pkg_installed("broom", reference_pkg =
"cardx")` has been set in the function call and the following added to
the roxygen comments: `@examplesIf
do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom"",
reference_pkg = "cardx"))`
- [ ] Code coverage is suitable for any new functions/features
(generally, 100% coverage for new code): `devtools::test_coverage()`

Reviewer Checklist (if item does not apply, mark is as complete)

- [ ] If a bug was fixed, a unit test was added.
- [ ] Code coverage is suitable for any new functions/features:
`devtools::test_coverage()`

When the branch is ready to be merged:
- [ ] Update `NEWS.md` with the changes from this pull request under the
heading "`# cardx (development version)`". If there is an issue
associated with the pull request, reference it in parentheses at the end
update (see `NEWS.md` for examples).
- [ ] **All** GitHub Action workflows pass with a ✅
- [ ] Approve Pull Request
- [ ] Merge the PR. Please use "Squash and merge" or "Rebase and merge".
  • Loading branch information
ayogasekaram authored Oct 3, 2024
1 parent d2be5dd commit 389e5bf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
12 changes: 0 additions & 12 deletions tests/testthat/_snaps/ard_regression.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,3 @@
7 cyl.sd__(Intercept) cyl.sd__(Intercept) estimate 4.023 NULL NULL
8 Residual.sd__Observation Residual.sd__Observation estimate 3.149 NULL NULL

# ard_regression() warnings and errors return correctly

Code
as.data.frame(ard_regression(mod))
Output
variable context stat_name stat_label stat fmt_fn
1 model_1 regression estimate Coefficient NULL NULL
warning
1 Could not access test statistic of model parameters., Could not access test statistic of model parameters.
error
1 Error: ! Unable to tidy `x`.

13 changes: 8 additions & 5 deletions tests/testthat/test-ard_regression.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,17 @@ test_that("ard_regression() does not produce `variable_level` column where not a
})

test_that("ard_regression() warnings and errors return correctly", {
skip_if_not(is_pkg_installed(pkg = "parameters", reference_pkg = "cardx"))
# constructed a model where broom.helpers fails,
# fall back method uses parameters which returns different messaging.
mod <- lm(AGE ~ ARM, data = cards::ADSL)
mod$coefficients <- NULL
df <- mod |>
ard_regression() |>
as.data.frame()

expect_snapshot(
mod |>
ard_regression() |>
as.data.frame()
)
expect_false(is_empty(df$error))
expect_true(is_empty(df$stat[[1]]))
})

test_that("ard_regression() follows ard structure", {
Expand Down

0 comments on commit 389e5bf

Please sign in to comment.