Skip to content

Commit

Permalink
-Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tylermorganwall committed Dec 2, 2023
1 parent db716cc commit 706174d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
24 changes: 24 additions & 0 deletions tests/testthat/_snaps/plot_image.md
@@ -0,0 +1,24 @@
# Checking plot_image_grid

`input_list` of length 4, but grid only has 1x1=1 slots: truncating list of images

---

`input_list` of length 4, but grid only has 1x2=2 slots: truncating list of images

---

`input_list` of length 4, but grid only has 2x1=2 slots: truncating list of images

---

`input_list` of length 4, but grid only has 1x1=1 slots: truncating list of images

---

`input_list` of length 4, but grid only has 1x2=2 slots: truncating list of images

---

`input_list` of length 4, but grid only has 2x1=2 slots: truncating list of images

30 changes: 23 additions & 7 deletions tests/testthat/test-plot_image.R
Expand Up @@ -11,7 +11,9 @@ compare_image = function(path1, path2) {
return(identical(image1, image2))
}

run_tests = function(func, argument_grid, plot_prefix="", ...) {


run_tests = function(func, argument_grid, plot_prefix="", warning_rows = NULL, error_rows = NULL, ...) {
stopifnot(inherits(argument_grid,"data.frame"))
for(i in seq_len(nrow(argument_grid))){
args = unlist(argument_grid[i,], recursive = FALSE)
Expand All @@ -22,10 +24,19 @@ run_tests = function(func, argument_grid, plot_prefix="", ...) {
args = append(args, ...)
# args = append(args, list(filename = path))
# browser()
save_test_png(do.call(func, args = args), path) |>
suppressMessages() |>
suppressWarnings() |>
expect_snapshot_file(name = test_filename, compare = compare_image)
if(i %in% warning_rows) {
expect_snapshot_warning(do.call(func, args = args))
} else if(i %in% error_rows) {
expect_snapshot_error(do.call(func, args = args))
}
if(interactive()) {
do.call(func, args = args)
} else {
save_test_png(do.call(func, args = args), path) |>
suppressMessages() |>
suppressWarnings() |>
expect_snapshot_file(name = test_filename, compare = compare_image)
}
}
}

Expand All @@ -37,6 +48,7 @@ test_that("Checking plot_image", {
new_page = list(TRUE, FALSE))

run_tests("plot_image", plt_img_args, plot_prefix = "plt_img",
warning_rows = NULL, error_rows = NULL,
list(input = dragon))
})

Expand All @@ -49,7 +61,11 @@ test_that("Checking plot_image_grid", {
c(2,1)),
draw_grid = list(FALSE, TRUE),
asp = list(c(0.5,1,2,3)))
plt_img_args = plt_img_args[-6,] #False positive
# plt_img_args = plt_img_args[-6,] #False positive

warning_rows = c(1,3,4,5,7,8)

run_tests("plot_image_grid", plt_img_args, plot_prefix = "plt_img_grid", list())
run_tests("plot_image_grid", plt_img_args, plot_prefix = "plt_img_grid",
warning_rows = warning_rows, error_rows = NULL,
list())
})

0 comments on commit 706174d

Please sign in to comment.