Skip to content

Commit

Permalink
don't test for error contexts we don't own
Browse files Browse the repository at this point in the history
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()`
  • Loading branch information
simonpcouch committed Jan 29, 2024
1 parent 78b8083 commit dda87e5
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 147 deletions.
6 changes: 1 addition & 5 deletions tests/testthat/_snaps/first_level.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@

---

Code
first_level(preds, "first", Class)
Condition
Error:
! object 'Class' not found
object 'Class' not found

---

Expand Down
6 changes: 1 addition & 5 deletions tests/testthat/_snaps/first_level_prob_name.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,5 @@

---

Code
first_class_prob_name(preds, "first", Class)
Condition
Error:
! object 'Class' not found
object 'Class' not found

40 changes: 6 additions & 34 deletions tests/testthat/_snaps/multiclass_plots.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

24 changes: 3 additions & 21 deletions tests/testthat/_snaps/reg_plots.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

46 changes: 7 additions & 39 deletions tests/testthat/_snaps/twoclass_plots.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -100,11 +72,7 @@

---

Code
plot_twoclass_pr(org$predictions, y_name)
Condition
Error:
! object 'y_name' not found
object 'y_name' not found

---

Expand Down
3 changes: 1 addition & 2 deletions tests/testthat/test-first_level.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions tests/testthat/test-first_level_prob_name.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
})
26 changes: 12 additions & 14 deletions tests/testthat/test-multiclass_plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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"),
Expand All @@ -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()
)

Expand All @@ -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)
Expand Down
21 changes: 12 additions & 9 deletions tests/testthat/test-reg_plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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"),
Expand All @@ -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"),
Expand Down
Loading

0 comments on commit dda87e5

Please sign in to comment.