Skip to content

Commit

Permalink
Update usage of verify_output() to expect_snapshot() (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavisVaughan committed Oct 12, 2021
1 parent f872528 commit 58377f4
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 157 deletions.
154 changes: 154 additions & 0 deletions tests/testthat/_snaps/printing.md
@@ -0,0 +1,154 @@
# can print empty workflow

Code
workflow()
Output
== Workflow ====================================================================
Preprocessor: None
Model: None

# can print workflow with recipe

Code
add_recipe(workflow(), rec)
Output
== Workflow ====================================================================
Preprocessor: Recipe
Model: None
-- Preprocessor ----------------------------------------------------------------
0 Recipe Steps

# can print workflow with formula

Code
add_formula(workflow(), y ~ x)
Output
== Workflow ====================================================================
Preprocessor: Formula
Model: None
-- Preprocessor ----------------------------------------------------------------
y ~ x

# can print workflow with variables

Code
add_variables(workflow(), y, c(x1, x2))
Output
== Workflow ====================================================================
Preprocessor: Variables
Model: None
-- Preprocessor ----------------------------------------------------------------
Outcomes: y
Predictors: c(x1, x2)

# can print workflow with model

Code
add_model(workflow(), model)
Output
== Workflow ====================================================================
Preprocessor: None
Model: linear_reg()
-- Model -----------------------------------------------------------------------
Linear Regression Model Specification (regression)
Computational engine: lm

# can print workflow with model with engine specific args

Code
add_model(workflow(), model)
Output
== Workflow ====================================================================
Preprocessor: None
Model: linear_reg()
-- Model -----------------------------------------------------------------------
Linear Regression Model Specification (regression)
Main Arguments:
penalty = 0.01
Engine-Specific Arguments:
dfmax = 5
Computational engine: glmnet

# can print workflow with fit model

Code
fit(workflow, mtcars)
Output
== Workflow [trained] ==========================================================
Preprocessor: Formula
Model: linear_reg()
-- Preprocessor ----------------------------------------------------------------
mpg ~ cyl
-- Model -----------------------------------------------------------------------
Call:
stats::lm(formula = ..y ~ ., data = data)
Coefficients:
(Intercept) cyl
37.885 -2.876

# can print workflow with >10 recipe steps

Code
add_recipe(workflow(), rec)
Output
== Workflow ====================================================================
Preprocessor: Recipe
Model: None
-- Preprocessor ----------------------------------------------------------------
11 Recipe Steps
* step_log()
* step_log()
* step_log()
* step_log()
* step_log()
* step_log()
* step_log()
* step_log()
* step_log()
* step_log()
* ...
* and 1 more step.

---

Code
add_recipe(workflow(), rec)
Output
== Workflow ====================================================================
Preprocessor: Recipe
Model: None
-- Preprocessor ----------------------------------------------------------------
12 Recipe Steps
* step_log()
* step_log()
* step_log()
* step_log()
* step_log()
* step_log()
* step_log()
* step_log()
* step_log()
* step_log()
* ...
* and 2 more steps.

5 changes: 0 additions & 5 deletions tests/testthat/out/test-print-workflow-empty.txt

This file was deleted.

18 changes: 0 additions & 18 deletions tests/testthat/out/test-print-workflow-fit.txt

This file was deleted.

8 changes: 0 additions & 8 deletions tests/testthat/out/test-print-workflow-formula.txt

This file was deleted.

17 changes: 0 additions & 17 deletions tests/testthat/out/test-print-workflow-model-args.txt

This file was deleted.

11 changes: 0 additions & 11 deletions tests/testthat/out/test-print-workflow-model.txt

This file was deleted.

21 changes: 0 additions & 21 deletions tests/testthat/out/test-print-workflow-recipe-11-steps.txt

This file was deleted.

21 changes: 0 additions & 21 deletions tests/testthat/out/test-print-workflow-recipe-12-steps.txt

This file was deleted.

8 changes: 0 additions & 8 deletions tests/testthat/out/test-print-workflow-recipe.txt

This file was deleted.

9 changes: 0 additions & 9 deletions tests/testthat/out/test-print-workflow-variables.txt

This file was deleted.

48 changes: 9 additions & 39 deletions tests/testthat/test-printing.R
@@ -1,51 +1,32 @@
test_that("can print empty workflow", {
verify_output(
test_path("out/test-print-workflow-empty.txt"),
workflow()
)
expect_snapshot(workflow())
})

test_that("can print workflow with recipe", {
rec <- recipes::recipe(mtcars)

verify_output(
test_path("out/test-print-workflow-recipe.txt"),
add_recipe(workflow(), rec)
)
expect_snapshot(add_recipe(workflow(), rec))
})

test_that("can print workflow with formula", {
verify_output(
test_path("out/test-print-workflow-formula.txt"),
add_formula(workflow(), y ~ x)
)
expect_snapshot(add_formula(workflow(), y ~ x))
})

test_that("can print workflow with variables", {
verify_output(
test_path("out/test-print-workflow-variables.txt"),
add_variables(workflow(), y, c(x1, x2))
)
expect_snapshot(add_variables(workflow(), y, c(x1, x2)))
})

test_that("can print workflow with model", {
model <- parsnip::linear_reg()
model <- parsnip::set_engine(model, "lm")

verify_output(
test_path("out/test-print-workflow-model.txt"),
add_model(workflow(), model)
)
expect_snapshot(add_model(workflow(), model))
})

test_that("can print workflow with model with engine specific args", {
model <- parsnip::linear_reg(penalty = 0.01)
model <- parsnip::set_engine(model, "glmnet", dfmax = 5)

verify_output(
test_path("out/test-print-workflow-model-args.txt"),
add_model(workflow(), model)
)
expect_snapshot(add_model(workflow(), model))
})

test_that("can print workflow with fit model", {
Expand All @@ -56,10 +37,7 @@ test_that("can print workflow with fit model", {
workflow <- add_formula(workflow, mpg ~ cyl)
workflow <- add_model(workflow, model)

verify_output(
test_path("out/test-print-workflow-fit.txt"),
fit(workflow, mtcars)
)
expect_snapshot(fit(workflow, mtcars))
})

test_that("can print workflow with >10 recipe steps", {
Expand All @@ -76,17 +54,9 @@ test_that("can print workflow with >10 recipe steps", {
rec <- recipes::step_log(rec, cyl)
rec <- recipes::step_log(rec, cyl)

add_recipe(workflow(), rec)

verify_output(
test_path("out/test-print-workflow-recipe-11-steps.txt"),
add_recipe(workflow(), rec)
)
expect_snapshot(add_recipe(workflow(), rec))

rec <- recipes::step_log(rec, cyl)

verify_output(
test_path("out/test-print-workflow-recipe-12-steps.txt"),
add_recipe(workflow(), rec)
)
expect_snapshot(add_recipe(workflow(), rec))
})

0 comments on commit 58377f4

Please sign in to comment.