Skip to content

Commit

Permalink
convert to testthat 3e (#1228)
Browse files Browse the repository at this point in the history
* `usethis::use_testthat(3)`
* update `tolerance`
* transition from `expect_error()`
* transition from `expect_warning()`
* transition from `expect_message()`
* remove calls to `context()`
* add missing `Collate` fields
  • Loading branch information
simonpcouch authored Oct 21, 2024
1 parent 3d89d8f commit d4fc1d1
Show file tree
Hide file tree
Showing 120 changed files with 591 additions and 388 deletions.
5 changes: 4 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ Suggests:
survey,
survival (>= 3.6-4),
systemfit,
testthat (>= 2.1.0),
testthat (>= 3.0.0),
tseries,
vars,
zoo
Expand Down Expand Up @@ -673,6 +673,8 @@ Collate:
'glmnet-glmnet-tidiers.R'
'gmm-tidiers.R'
'hmisc-tidiers.R'
'import-standalone-obj-type.R'
'import-standalone-types-check.R'
'joinerml-tidiers.R'
'kendall-tidiers.R'
'ks-tidiers.R'
Expand Down Expand Up @@ -751,3 +753,4 @@ Collate:
'vars-tidiers.R'
'zoo-tidiers.R'
'zzz.R'
Config/testthat/edition: 3
12 changes: 12 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file is part of the standard setup for testthat.
# It is recommended that you do not modify it.
#
# Where should you do additional test configuration?
# Learn more about the roles of various files in:
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
# * https://testthat.r-lib.org/articles/special-files.html

library(testthat)
library(broom)

test_check("broom")
16 changes: 16 additions & 0 deletions tests/testthat/_snaps/drc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# augment.drc

Code
augment(mod)
Condition
Error:
! Must specify either `data` or `newdata` argument.

---

Code
augment(mod2)
Condition
Error:
! Must specify either `data` or `newdata` argument.

23 changes: 23 additions & 0 deletions tests/testthat/_snaps/ergm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# tidy.ergm

Code
tde <- tidy(gest, conf.int = TRUE, exponentiate = TRUE)
Condition
Warning in `tidy.ergm()`:
Exponentiating but model didn't use log or logit link.

---

Code
td2 <- tidy(gest2, conf.int = TRUE, exponentiate = TRUE)
Condition
Warning in `tidy.ergm()`:
Exponentiating but model didn't use log or logit link.

# glance.ergm

Code
gl3 <- glance(gest, deviance = TRUE, mcmc = TRUE)
Message
Though `glance` was supplied `mcmc = TRUE`, the model was not fittedusing MCMC, so the corresponding columns will be omitted.

27 changes: 27 additions & 0 deletions tests/testthat/_snaps/fixest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# all other fixest estimators run

Code
augment(res_fenegbin, df)
Condition
Error in `augment.fixest()`:
! augment is only supported for fixest models estimated with feols, feglm, or femlm
(supplied model used fenegbin)

---

Code
augment(res_feNmlm, df)
Condition
Error in `augment.fixest()`:
! augment is only supported for fixest models estimated with feols, feglm, or femlm
(supplied model used feNmlm)

---

Code
augment(res_fepois, df)
Condition
Error in `augment.fixest()`:
! augment is only supported for fixest models estimated with feols, feglm, or femlm
(supplied model used fepois)

8 changes: 8 additions & 0 deletions tests/testthat/_snaps/geepack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# tidy.geeglm

Code
td2 <- tidy(fit, conf.int = FALSE, exponentiate = TRUE)
Condition
Warning in `tidy.geeglm()`:
Exponentiating coefficients, but model did not use a log or logit link function

16 changes: 16 additions & 0 deletions tests/testthat/_snaps/joineRML.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# tidy.mjoint

Code
tidy(mjoint_fit, boot_se = "cat")
Condition
Error:
! `boot_se` argument must be a `bootSE` object.

# augment.mjoint

Code
augment(mjoint_fit, data = NULL)
Condition
Error:
! `data` argument is NULL. Try specifying `data` manually.

25 changes: 25 additions & 0 deletions tests/testthat/_snaps/lfe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# tidy.felm

Code
.res <- tidy(fit, robust = TRUE)
Condition
Warning in `tidy.felm()`:
The "robust" argument has been deprecated in tidy.felm and will be ignored. Please use the "se.type" argument instead.

# glance.felm

Code
glance(fit_multi)
Condition
Error:
! Glance does not support linear models with multiple responses.

# augment.felm

Code
augment(fit_multi)
Condition
Error:
! Augment does not support linear models with multiple responses.

24 changes: 24 additions & 0 deletions tests/testthat/_snaps/list-xyz.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# tidy_xyz

Code
tidy(b)
Condition
Error:
! To tidy an xyz list, the length of element `x` must equal the number the number of rows of element `z`, and the length of element `y` must equal the number of columns of element `z`.

---

Code
tidy(c)
Condition
Error:
! To tidy an xyz list, the length of element `x` must equal the number the number of rows of element `z`, and the length of element `y` must equal the number of columns of element `z`.

---

Code
tidy(d)
Condition
Error:
! To tidy an xyz list, `z` must be a matrix.

16 changes: 16 additions & 0 deletions tests/testthat/_snaps/list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# not all lists can be tidied

Code
tidy(nl)
Condition
Error:
! No tidy method recognized for this list.

---

Code
glance(nl)
Condition
Error:
! No glance method recognized for this list.

8 changes: 8 additions & 0 deletions tests/testthat/_snaps/mclust.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# augment.Mclust

Code
augment(fit, 1:10)
Condition
Error:
! `data` must be a data frame or matrix.

120 changes: 120 additions & 0 deletions tests/testthat/_snaps/null-and-default.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# tidy.default

Code
td <- tidy(raw(1))
Condition
Error:
! No tidy method for objects of class raw

---

Code
glance(x)
Condition
Error:
! No glance method for objects of class foo

---

Code
glance(x)
Condition
Error:
! No glance method for objects of class foo

# glance.default

Code
glance(TRUE)
Condition
Error:
! No glance method for objects of class logical

---

Code
glance(1)
Condition
Error:
! No glance method for objects of class numeric

---

Code
glance(1L)
Condition
Error:
! No glance method for objects of class integer

---

Code
glance("a")
Condition
Error:
! No glance method for objects of class character

---

Code
glance(x)
Condition
Error:
! No glance method for objects of class foo

---

Code
glance(x)
Condition
Error:
! No glance method for objects of class foo

# augment.default

Code
augment(TRUE)
Condition
Error:
! No augment method for objects of class logical

---

Code
augment(1)
Condition
Error:
! No augment method for objects of class numeric

---

Code
augment(1L)
Condition
Error:
! No augment method for objects of class integer

---

Code
augment("a")
Condition
Error:
! No augment method for objects of class character

---

Code
augment(x)
Condition
Error:
! No augment method for objects of class foo

---

Code
augment(x)
Condition
Error:
! No augment method for objects of class foo

8 changes: 8 additions & 0 deletions tests/testthat/_snaps/quantreg-rqs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# glance.rqs

Code
glance(fit)
Condition
Error:
! `glance` cannot handle objects of class 'rqs', i.e. models with more than one tau value. Please use a purrr `map`-based workflow with 'rq' models instead.

8 changes: 8 additions & 0 deletions tests/testthat/_snaps/speedglm-speedglm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# augment.speedglm errors

Code
augment(fit)
Condition
Error:
! No augment method for objects of class speedglm

8 changes: 8 additions & 0 deletions tests/testthat/_snaps/speedglm-speedlm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# augment.speedlm

Code
augment(fit3)
Condition
Error:
! Must specify `data` argument or refit speedglm with `fitted = TRUE`.

8 changes: 8 additions & 0 deletions tests/testthat/_snaps/stats-anova.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# tidy.anova

Code
.res <- tidy(loess_anova)
Condition
Warning in `tidy.anova()`:
The following column names in ANOVA output were not recognized or transformed: ENP

8 changes: 8 additions & 0 deletions tests/testthat/_snaps/stats-factanal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# augment.factanal works

Code
augment(fit_none)
Condition
Error:
! Cannot augment factanal objects fit with `scores = 'none'`.

Loading

0 comments on commit d4fc1d1

Please sign in to comment.