Skip to content

Commit 5716803

Browse files
authored
update to testthat 3e + consolidate translate() tests (#699)
* bump testthat version * drop calls to `context()` if `context()` wasn't redundant with file name, convert to comment * remove usage of `expect_equivalent()` mostly just switching to `expect_equal` and updating attributes as needed. it also seems that `expect_warning()` (and other prompt friends) return the prompt rather than output--changed one of these that was related to `expect_equivalent, but will need to do a more thorough sweep when switching to `expect_snapshot` * favor `expect_equal` args over ad-hoc deattr * drop calls to `source`, standardize header * drop `library` calls, namespace w `::` when needed * drop `new_empty_quosure()` `quo` does the trick in most of these situations, and any exceptions ought to be transitioned to `expect_snapshot`. still a good few errors related to function environment. * add `test_translate` skeleton, spec out with `linear_reg` * add helper for `expect_snapshot`ting translate `args` I think that it helps to standardize indentation + simplify figuring out what a snapshot is capturing, and it cuts down on lines quite a bit, but I could also see the argument that it obscures a bit too much. Implemented primary argument checks for three models, dropping the rest. * adjust layout of `test_translate.R` it looks like just about every model type has associated changes to translation of primary arguments, so pulling back from the "selected methods" approach to testing each. * condense primary arguments testing * refactor engine arguments tests * `expect_warning` -> `expect_snapshot` when `regex` arg present also transitioned on output of `translate` * revert cc6bb34 given how large this PR will be already, and the brittleness of `expect_snapshot` as compared to `expect_warning` (and `expect_error`), reverting the change `expect_warning` <- `expect_snapshot`. * `expect_output` -> `expect_snapshot` * revert to simpler expectation following Hannah's lead--we just want to make sure we get a model object back, and `expect_snapshot` will pick up differences in fit time etc * add snaps * misc bug fixes a good bit of `expect_warning` output changes affecting assignments. some namespacing, some environment variable tomfoolery as well. * adjust helper interface ended up running into issues with `expect_snapshot` call environments—not worth the loss in interpretability of errors to wrap `expect_snapshot` itself. still trying to figure out the best way to ignore function environments here. * make envs reproducible, update snaps wipe the environment from quosures in the translation helper so that `expect_snapshot` is reproducible! * small `r cmd check` fixes * typo fix * invoke `lung` outside of test body for whatever reason, `oldrel-2` can't find `lung` inside of the tests here. thinking this might be some kind of scoping issue—from what i can tell on the `survival` repo, this shouldn't be due to changes in that package, though it's hard to trace source history from there. * load `lung` data conditionally for `oldrel-2` and older, pak uses survival 3.1-8 via R 3.6.3. in these versions of survival, loading the lung data with `data(lung` seems to have worked (though was not preferred? ¯\_(ツ)_/¯) * transition `$fit` to `extract_fit_*()` exceptions: * when assigning (i.e. no `extract_fit_*<-()`) * when subsetted into `$method` * when testing `NULL` * transition `update()` tests to snapshots * transition last bits of `rlang` nastiness to `expect_snapshot()` * revert to `quo` for ignoring env * drop outdated snapshot
1 parent 5e79150 commit 5716803

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+4109
-2346
lines changed

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Suggests:
6060
rpart,
6161
sparklyr (>= 1.0.0),
6262
survival,
63-
testthat,
63+
testthat (>= 3.0.0),
6464
xgboost (>= 1.5.0.1)
6565
VignetteBuilder:
6666
knitr
@@ -89,4 +89,5 @@ Config/rcmdcheck/ignore-inconsequential-notes: true
8989
Encoding: UTF-8
9090
LazyData: true
9191
Roxygen: list(markdown = TRUE)
92+
Config/testthat/edition: 3
9293
RoxygenNote: 7.1.2.9000

tests/testthat/_snaps/boost_tree.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# updating
2+
3+
Code
4+
expr1 %>% update(trees = 10)
5+
Output
6+
Boosted Tree Model Specification (unknown)
7+
8+
Main Arguments:
9+
trees = 10
10+
11+
Engine-Specific Arguments:
12+
verbose = 0
13+
14+
Computational engine: xgboost
15+
16+
17+
---
18+
19+
Code
20+
expr1 %>% update(param_tibb)
21+
Output
22+
Boosted Tree Model Specification (unknown)
23+
24+
Main Arguments:
25+
mtry = 1
26+
trees = 7
27+
28+
Engine-Specific Arguments:
29+
verbose = 0
30+
31+
Computational engine: xgboost
32+
33+
34+
---
35+
36+
Code
37+
expr1 %>% update(param_list)
38+
Output
39+
Boosted Tree Model Specification (unknown)
40+
41+
Main Arguments:
42+
mtry = 1
43+
trees = 7
44+
45+
Engine-Specific Arguments:
46+
verbose = 0
47+
48+
Computational engine: xgboost
49+
50+
51+
---
52+
53+
Code
54+
expr2 %>% update(bands = 10)
55+
Output
56+
Boosted Tree Model Specification (unknown)
57+
58+
Main Arguments:
59+
trees = tune()
60+
61+
Engine-Specific Arguments:
62+
bands = 10
63+
64+
Computational engine: C5.0
65+
66+
67+
---
68+
69+
Code
70+
expr3 %>% update(trees = 1, fresh = TRUE)
71+
Output
72+
Boosted Tree Model Specification (unknown)
73+
74+
Main Arguments:
75+
trees = 1
76+
77+
Computational engine: xgboost
78+
79+
80+
---
81+
82+
Code
83+
expr4 %>% update(noGlobalPruning = TRUE)
84+
Output
85+
Boosted Tree Model Specification (unknown)
86+
87+
Engine-Specific Arguments:
88+
noGlobalPruning = TRUE
89+
90+
Computational engine: C5.0
91+
92+
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# updating
2+
3+
Code
4+
expr1 %>% update(cost_complexity = 0.1)
5+
Output
6+
Decision Tree Model Specification (unknown)
7+
8+
Main Arguments:
9+
cost_complexity = 0.1
10+
11+
Engine-Specific Arguments:
12+
model = FALSE
13+
14+
Computational engine: rpart
15+
16+
17+
---
18+
19+
Code
20+
expr1 %>% update(param_tibb)
21+
Output
22+
Decision Tree Model Specification (unknown)
23+
24+
Main Arguments:
25+
cost_complexity = 0.1
26+
min_n = 1
27+
28+
Engine-Specific Arguments:
29+
model = FALSE
30+
31+
Computational engine: rpart
32+
33+
34+
---
35+
36+
Code
37+
expr1 %>% update(param_list)
38+
Output
39+
Decision Tree Model Specification (unknown)
40+
41+
Main Arguments:
42+
cost_complexity = 0.1
43+
min_n = 1
44+
45+
Engine-Specific Arguments:
46+
model = FALSE
47+
48+
Computational engine: rpart
49+
50+
51+
---
52+
53+
Code
54+
expr2 %>% update(model = FALSE)
55+
Output
56+
Decision Tree Model Specification (unknown)
57+
58+
Main Arguments:
59+
cost_complexity = tune()
60+
61+
Engine-Specific Arguments:
62+
model = FALSE
63+
64+
Computational engine: rpart
65+
66+
67+
---
68+
69+
Code
70+
expr3 %>% update(cost_complexity = 1, fresh = TRUE)
71+
Output
72+
Decision Tree Model Specification (unknown)
73+
74+
Main Arguments:
75+
cost_complexity = 1
76+
77+
Computational engine: rpart
78+
79+

tests/testthat/_snaps/linear_reg.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# updating
2+
3+
Code
4+
expr1 %>% update(mixture = 0)
5+
Output
6+
Linear Regression Model Specification (regression)
7+
8+
Main Arguments:
9+
mixture = 0
10+
11+
Engine-Specific Arguments:
12+
model = FALSE
13+
14+
Computational engine: lm
15+
16+
17+
---
18+
19+
Code
20+
expr2 %>% update(nlambda = 10)
21+
Output
22+
Linear Regression Model Specification (regression)
23+
24+
Engine-Specific Arguments:
25+
nlambda = 10
26+
27+
Computational engine: glmnet
28+
29+
30+
---
31+
32+
Code
33+
expr3 %>% update(mixture = 1, fresh = TRUE, nlambda = 10)
34+
Output
35+
Linear Regression Model Specification (regression)
36+
37+
Main Arguments:
38+
mixture = 1
39+
40+
Engine-Specific Arguments:
41+
nlambda = 10
42+
43+
Computational engine: glmnet
44+
45+
46+
---
47+
48+
Code
49+
expr3 %>% update(nlambda = 10)
50+
Output
51+
Linear Regression Model Specification (regression)
52+
53+
Main Arguments:
54+
penalty = tune()
55+
mixture = 0
56+
57+
Engine-Specific Arguments:
58+
nlambda = 10
59+
60+
Computational engine: glmnet
61+
62+
63+
---
64+
65+
Code
66+
expr4 %>% update(param_tibb)
67+
Output
68+
Linear Regression Model Specification (regression)
69+
70+
Main Arguments:
71+
penalty = 1
72+
mixture = 0.333333333333333
73+
74+
Engine-Specific Arguments:
75+
nlambda = 10
76+
77+
Computational engine: glmnet
78+
79+
80+
---
81+
82+
Code
83+
expr4 %>% update(param_list)
84+
Output
85+
Linear Regression Model Specification (regression)
86+
87+
Main Arguments:
88+
penalty = 1
89+
mixture = 0.333333333333333
90+
91+
Engine-Specific Arguments:
92+
nlambda = 10
93+
94+
Computational engine: glmnet
95+
96+
97+
---
98+
99+
Code
100+
expr5 %>% update(family = "poisson")
101+
Output
102+
Linear Regression Model Specification (regression)
103+
104+
Engine-Specific Arguments:
105+
family = poisson
106+
107+
Computational engine: glm
108+
109+

tests/testthat/_snaps/logistic_reg.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# updating
2+
3+
Code
4+
expr1 %>% update(mixture = 0)
5+
Output
6+
Logistic Regression Model Specification (classification)
7+
8+
Main Arguments:
9+
mixture = 0
10+
11+
Engine-Specific Arguments:
12+
family = expr(binomial(link = "probit"))
13+
14+
Computational engine: glm
15+
16+
17+
---
18+
19+
Code
20+
expr2 %>% update(nlambda = 10)
21+
Output
22+
Logistic Regression Model Specification (classification)
23+
24+
Main Arguments:
25+
mixture = tune()
26+
27+
Engine-Specific Arguments:
28+
nlambda = 10
29+
30+
Computational engine: glmnet
31+
32+
33+
---
34+
35+
Code
36+
expr3 %>% update(mixture = 1, fresh = TRUE, nlambda = 10)
37+
Output
38+
Logistic Regression Model Specification (classification)
39+
40+
Main Arguments:
41+
mixture = 1
42+
43+
Engine-Specific Arguments:
44+
nlambda = 10
45+
46+
Computational engine: glmnet
47+
48+
49+
---
50+
51+
Code
52+
expr4 %>% update(param_tibb)
53+
Output
54+
Logistic Regression Model Specification (classification)
55+
56+
Main Arguments:
57+
penalty = 1
58+
mixture = 0.333333333333333
59+
60+
Engine-Specific Arguments:
61+
nlambda = 10
62+
63+
Computational engine: glmnet
64+
65+
66+
---
67+
68+
Code
69+
expr4 %>% update(param_list)
70+
Output
71+
Logistic Regression Model Specification (classification)
72+
73+
Main Arguments:
74+
penalty = 1
75+
mixture = 0.333333333333333
76+
77+
Engine-Specific Arguments:
78+
nlambda = 10
79+
80+
Computational engine: glmnet
81+
82+

0 commit comments

Comments
 (0)