From 389e5bf4d1504753b57062754a84d2a84f35334c Mon Sep 17 00:00:00 2001 From: Abinaya Yogasekaram <73252787+ayogasekaram@users.noreply.github.com> Date: Thu, 3 Oct 2024 14:50:14 -0400 Subject: [PATCH] update tests (#220) closes #219 -------------------------------------------------------------------------------- Pre-review Checklist (if item does not apply, mark is as complete) - [x] **All** GitHub Action workflows pass with a :white_check_mark: - [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 :white_check_mark: - [ ] Approve Pull Request - [ ] Merge the PR. Please use "Squash and merge" or "Rebase and merge". --- tests/testthat/_snaps/ard_regression.md | 12 ------------ tests/testthat/test-ard_regression.R | 13 ++++++++----- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/tests/testthat/_snaps/ard_regression.md b/tests/testthat/_snaps/ard_regression.md index 28439ecd..19c55b98 100644 --- a/tests/testthat/_snaps/ard_regression.md +++ b/tests/testthat/_snaps/ard_regression.md @@ -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`. - diff --git a/tests/testthat/test-ard_regression.R b/tests/testthat/test-ard_regression.R index 3ade0fec..d1d8ca46 100644 --- a/tests/testthat/test-ard_regression.R +++ b/tests/testthat/test-ard_regression.R @@ -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", {