From dda87e51d9090ee425763c59bc35fe2d3a4d730e Mon Sep 17 00:00:00 2001 From: simonpcouch Date: Mon, 29 Jan 2024 16:00:35 -0600 Subject: [PATCH] don't test for error contexts we don't own transitions from `expect_snapshot()` to `expect_snapshot_error()` so that we don't test for error headers from errors that aren't thrown by the package. ultimately, we likely want to just throw more informative errors ourselves and then we can transition back to testing with `expect_snapshot()` --- tests/testthat/_snaps/first_level.md | 6 +-- .../testthat/_snaps/first_level_prob_name.md | 6 +-- tests/testthat/_snaps/multiclass_plots.md | 40 +++------------- tests/testthat/_snaps/reg_plots.md | 24 ++-------- tests/testthat/_snaps/twoclass_plots.md | 46 +++---------------- tests/testthat/test-first_level.R | 3 +- tests/testthat/test-first_level_prob_name.R | 3 +- tests/testthat/test-multiclass_plots.R | 26 +++++------ tests/testthat/test-reg_plots.R | 21 +++++---- tests/testthat/test-twoclass_plots.R | 29 ++++++------ 10 files changed, 57 insertions(+), 147 deletions(-) diff --git a/tests/testthat/_snaps/first_level.md b/tests/testthat/_snaps/first_level.md index 1ca2798..4fd0fc6 100644 --- a/tests/testthat/_snaps/first_level.md +++ b/tests/testthat/_snaps/first_level.md @@ -40,11 +40,7 @@ --- - Code - first_level(preds, "first", Class) - Condition - Error: - ! object 'Class' not found + object 'Class' not found --- diff --git a/tests/testthat/_snaps/first_level_prob_name.md b/tests/testthat/_snaps/first_level_prob_name.md index c6ac65d..ceb4e1b 100644 --- a/tests/testthat/_snaps/first_level_prob_name.md +++ b/tests/testthat/_snaps/first_level_prob_name.md @@ -24,9 +24,5 @@ --- - Code - first_class_prob_name(preds, "first", Class) - Condition - Error: - ! object 'Class' not found + object 'Class' not found diff --git a/tests/testthat/_snaps/multiclass_plots.md b/tests/testthat/_snaps/multiclass_plots.md index daad882..3c984d8 100644 --- a/tests/testthat/_snaps/multiclass_plots.md +++ b/tests/testthat/_snaps/multiclass_plots.md @@ -24,21 +24,11 @@ --- - Code - plot_multiclass_pred_numcol(org$predictions, y_name) - Condition - Error: - ! argument "numcol" is missing, with no default + argument "numcol" is missing, with no default --- - Code - plot_multiclass_pred_numcol(org$predictions, org$y_name, "AXL") - Condition - Warning in `ggplot2::geom_point()`: - Ignoring unknown aesthetics: customdata and text - Error: - ! object 'AXL' not found + object 'AXL' not found # can accurately plot predicted probabilities vs. a factor column plot @@ -50,21 +40,11 @@ --- - Code - plot_multiclass_pred_factorcol(org$predictions, y_name) - Condition - Error: - ! argument "factorcol" is missing, with no default + argument "factorcol" is missing, with no default --- - Code - plot_multiclass_pred_factorcol(org$predictions, org$y_name, "Genotype") - Condition - Warning in `ggplot2::geom_point()`: - Ignoring unknown aesthetics: customdata and text - Error: - ! object 'Genotype' not found + object 'Genotype' not found # can accurately plot the ROC curve @@ -76,11 +56,7 @@ --- - Code - plot_multiclass_roc() - Condition - Error in `plot_multiclass_roc()`: - ! argument "dat" is missing, with no default + argument "dat" is missing, with no default # can accurately plot the PR curve @@ -92,9 +68,5 @@ --- - Code - plot_multiclass_pr() - Condition - Error in `plot_multiclass_pr()`: - ! argument "dat" is missing, with no default + argument "dat" is missing, with no default diff --git a/tests/testthat/_snaps/reg_plots.md b/tests/testthat/_snaps/reg_plots.md index 7a85313..5620bac 100644 --- a/tests/testthat/_snaps/reg_plots.md +++ b/tests/testthat/_snaps/reg_plots.md @@ -8,13 +8,7 @@ --- - Code - plot_numeric_obs_pred(org$predictions, y_name) - Condition - Warning in `ggplot2::geom_point()`: - Ignoring unknown aesthetics: customdata and text - Error: - ! object 'y_name' not found + object 'y_name' not found # can accurately plot numeric residuals vs. predicted plot @@ -34,13 +28,7 @@ --- - Code - plot_numeric_res_numcol(org$predictions, "Sale_Price", "Class") - Condition - Warning in `ggplot2::geom_point()`: - Ignoring unknown aesthetics: customdata and text - Error: - ! object 'Class' not found + object 'Class' not found # can accurately plot numeric residuals vs. a factor column plot @@ -52,11 +40,5 @@ --- - Code - plot_numeric_res_factorcol(org$predictions, org$y_name, "St") - Condition - Warning in `ggplot2::geom_point()`: - Ignoring unknown aesthetics: customdata and text - Error: - ! object 'St' not found + object 'St' not found diff --git a/tests/testthat/_snaps/twoclass_plots.md b/tests/testthat/_snaps/twoclass_plots.md index 5ab1787..094a420 100644 --- a/tests/testthat/_snaps/twoclass_plots.md +++ b/tests/testthat/_snaps/twoclass_plots.md @@ -8,11 +8,7 @@ --- - Code - plot_twoclass_obs_pred(org$predictions, y_name) - Condition - Error: - ! object 'y_name' not found + object 'y_name' not found # can accurately plot confusion matrix plot @@ -32,21 +28,11 @@ --- - Code - plot_twoclass_pred_numcol(org$predictions, y_name, "AXL") - Condition - Error: - ! object 'y_name' not found + object 'y_name' not found --- - Code - plot_twoclass_pred_numcol(org$predictions, org$y_name, "potato") - Condition - Warning in `ggplot2::geom_point()`: - Ignoring unknown aesthetics: customdata and text - Error: - ! object 'potato' not found + object 'potato' not found # can accurately plot predicted probabilities vs. a factor column plot @@ -58,21 +44,11 @@ --- - Code - plot_twoclass_pred_factorcol(org$predictions, y_name, "fact_col") - Condition - Error: - ! object 'y_name' not found + object 'y_name' not found --- - Code - plot_twoclass_pred_factorcol(org$predictions, org$y_name, "potato") - Condition - Warning in `ggplot2::geom_point()`: - Ignoring unknown aesthetics: customdata and text - Error: - ! object 'potato' not found + object 'potato' not found # can accurately plot the ROC curve @@ -84,11 +60,7 @@ --- - Code - plot_twoclass_roc(org$predictions, y_name) - Condition - Error: - ! object 'y_name' not found + object 'y_name' not found # can accurately plot the PR curve @@ -100,11 +72,7 @@ --- - Code - plot_twoclass_pr(org$predictions, y_name) - Condition - Error: - ! object 'y_name' not found + object 'y_name' not found --- diff --git a/tests/testthat/test-first_level.R b/tests/testthat/test-first_level.R index db14cfe..7924355 100644 --- a/tests/testthat/test-first_level.R +++ b/tests/testthat/test-first_level.R @@ -38,8 +38,7 @@ test_that("can find first level", { error = TRUE, first_level(preds, 1, "Class") ) - expect_snapshot( - error = TRUE, + expect_snapshot_error( first_level(preds, "first", Class) ) expect_snapshot( diff --git a/tests/testthat/test-first_level_prob_name.R b/tests/testthat/test-first_level_prob_name.R index 28cf008..86501b4 100644 --- a/tests/testthat/test-first_level_prob_name.R +++ b/tests/testthat/test-first_level_prob_name.R @@ -24,8 +24,7 @@ test_that("can find the correct first level .pred name", { error = TRUE, first_class_prob_name(preds, first, "Class") ) - expect_snapshot( - error = TRUE, + expect_snapshot_error( first_class_prob_name(preds, "first", Class) ) }) diff --git a/tests/testthat/test-multiclass_plots.R b/tests/testthat/test-multiclass_plots.R index 6832f07..8c9400e 100644 --- a/tests/testthat/test-multiclass_plots.R +++ b/tests/testthat/test-multiclass_plots.R @@ -44,13 +44,13 @@ test_that("can accurately plot predicted probabilities vs. a numeric column plot error = TRUE, plot_multiclass_pred_numcol(org, org$y_name, "Diameter") ) - expect_snapshot( - error = TRUE, + expect_snapshot_error( plot_multiclass_pred_numcol(org$predictions, y_name) ) - expect_snapshot( - error = TRUE, - plot_multiclass_pred_numcol(org$predictions, org$y_name, "AXL"), + suppressWarnings( + expect_snapshot_error( + plot_multiclass_pred_numcol(org$predictions, org$y_name, "AXL") + ) ) expect_warning( c <- plot_multiclass_pred_numcol(org$predictions, org$y_name, "Diameter"), @@ -70,13 +70,13 @@ test_that("can accurately plot predicted probabilities vs. a factor column plot" error = TRUE, plot_multiclass_pred_factorcol(org, org$y_name, "tectonic_settings") ) - expect_snapshot( - error = TRUE, + expect_snapshot_error( plot_multiclass_pred_factorcol(org$predictions, y_name) ) - expect_snapshot( - error = TRUE, - plot_multiclass_pred_factorcol(org$predictions, org$y_name, "Genotype"), + suppressWarnings( + expect_snapshot_error( + plot_multiclass_pred_factorcol(org$predictions, org$y_name, "Genotype"), + ) ) expect_warning( d <- plot_multiclass_pred_factorcol(org$predictions, org$y_name, "Month"), @@ -99,8 +99,7 @@ test_that("can accurately plot the ROC curve", { error = TRUE, plot_multiclass_roc(org, org$y_name) ) - expect_snapshot( - error = TRUE, + expect_snapshot_error( plot_multiclass_roc() ) @@ -122,8 +121,7 @@ test_that("can accurately plot the PR curve", { error = TRUE, plot_multiclass_pr(org, org$y_name) ) - expect_snapshot( - error = TRUE, + expect_snapshot_error( plot_multiclass_pr() ) f <- plot_multiclass_pr(org$predictions, org$y_name) diff --git a/tests/testthat/test-reg_plots.R b/tests/testthat/test-reg_plots.R index 423dae9..d4c26c0 100644 --- a/tests/testthat/test-reg_plots.R +++ b/tests/testthat/test-reg_plots.R @@ -14,9 +14,10 @@ test_that("can accurately plot numeric observed vs. predicted plot", { error = TRUE, plot_numeric_obs_pred(org, org$y_name) ) - expect_snapshot( - error = TRUE, - plot_numeric_obs_pred(org$predictions, y_name) + suppressWarnings( + expect_snapshot_error( + plot_numeric_obs_pred(org$predictions, y_name) + ) ) expect_warning( a <- plot_numeric_obs_pred(org$predictions, org$y_name), @@ -56,9 +57,10 @@ test_that("can accurately plot numeric residuals vs. a numeric column plot", { error = TRUE, plot_numeric_obs_pred(org, org$y_name) ) - expect_snapshot( - error = TRUE, - plot_numeric_res_numcol(org$predictions, "Sale_Price", "Class") + suppressWarnings( + expect_snapshot_error( + plot_numeric_res_numcol(org$predictions, "Sale_Price", "Class") + ) ) expect_warning( c <- plot_numeric_res_numcol(org$predictions, org$y_name, "Longitude"), @@ -79,9 +81,10 @@ test_that("can accurately plot numeric residuals vs. a factor column plot", { error = TRUE, plot_numeric_obs_pred(org, org$y_name) ) - expect_snapshot( - error = TRUE, - plot_numeric_res_factorcol(org$predictions, org$y_name, "St") + suppressWarnings( + expect_snapshot_error( + plot_numeric_res_factorcol(org$predictions, org$y_name, "St") + ) ) expect_warning( d <- plot_numeric_res_factorcol(org$predictions, org$y_name, "Neighborhood"), diff --git a/tests/testthat/test-twoclass_plots.R b/tests/testthat/test-twoclass_plots.R index f193408..dc1dd5e 100644 --- a/tests/testthat/test-twoclass_plots.R +++ b/tests/testthat/test-twoclass_plots.R @@ -13,8 +13,7 @@ test_that("can accurately plot predicted probabilities vs true class plot", { error = TRUE, plot_twoclass_obs_pred(org, org$y_name) ) - expect_snapshot( - error = TRUE, + expect_snapshot_error( plot_twoclass_obs_pred(org$predictions, y_name) ) a <- plot_twoclass_obs_pred(org$predictions, org$y_name) @@ -47,13 +46,13 @@ test_that("can accurately plot predicted probabilities vs. a numeric column plot error = TRUE, plot_twoclass_pred_numcol(org, org$y_name, "AXL") ) - expect_snapshot( - error = TRUE, + expect_snapshot_error( plot_twoclass_pred_numcol(org$predictions, y_name, "AXL") ) - expect_snapshot( - error = TRUE, - plot_twoclass_pred_numcol(org$predictions, org$y_name, "potato") + suppressWarnings( + expect_snapshot_error( + plot_twoclass_pred_numcol(org$predictions, org$y_name, "potato") + ) ) expect_warning( c <- plot_twoclass_pred_numcol(org$predictions, org$y_name, "angle_ch_1"), @@ -81,13 +80,13 @@ test_that("can accurately plot predicted probabilities vs. a factor column plot" error = TRUE, plot_twoclass_pred_factorcol(org, org$y_name, "fact_col") ) - expect_snapshot( - error = TRUE, + expect_snapshot_error( plot_twoclass_pred_factorcol(org$predictions, y_name, "fact_col") ) - expect_snapshot( - error = TRUE, - plot_twoclass_pred_factorcol(org$predictions, org$y_name, "potato") + expect_warning( + expect_snapshot_error( + plot_twoclass_pred_factorcol(org$predictions, org$y_name, "potato") + ) ) expect_warning( d <- plot_twoclass_pred_factorcol(org$predictions, org$y_name, "fact_col"), @@ -110,8 +109,7 @@ test_that("can accurately plot the ROC curve", { error = TRUE, plot_twoclass_roc(org, org$y_name) ) - expect_snapshot( - error = TRUE, + expect_snapshot_error( plot_twoclass_roc(org$predictions, y_name) ) e <- plot_twoclass_roc(org$predictions, org$y_name) @@ -132,8 +130,7 @@ test_that("can accurately plot the PR curve", { error = TRUE, plot_twoclass_pr(org, org$y_name) ) - expect_snapshot( - error = TRUE, + expect_snapshot_error( plot_twoclass_pr(org$predictions, y_name) ) expect_snapshot(