-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-Turn off golden tests (too inconsistent across systems)
-Improve docs
- Loading branch information
1 parent
bb067e6
commit 972b3ef
Showing
3 changed files
with
59 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,53 @@ | ||
save_test_png = function(code, path) { | ||
grDevices::png(filename=path, width=500, height=400) | ||
code | ||
dev.off() | ||
path | ||
} | ||
|
||
compare_image = function(path1, path2) { | ||
image1 = png::readPNG(path1) | ||
image2 = png::readPNG(path2) | ||
return(identical(image1, image2)) | ||
} | ||
|
||
run_tests = function(func, argument_grid, plot_prefix="", ...) { | ||
stopifnot(inherits(argument_grid,"data.frame")) | ||
for(i in seq_len(nrow(argument_grid))){ | ||
args = unlist(argument_grid[i,], recursive = FALSE) | ||
test_filename = sprintf("%s_test%i.png", | ||
plot_prefix , i) | ||
path = tempfile(fileext = ".png") | ||
|
||
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) | ||
} | ||
} | ||
|
||
test_that("Checking plot_image", { | ||
plt_img_args = expand.grid(rotate = list(0,90,180,270), | ||
draw_grid = list(FALSE, TRUE), | ||
asp = list(0.5,1,2), | ||
new_page = list(TRUE, FALSE)) | ||
|
||
run_tests("plot_image", plt_img_args, plot_prefix = "plt_img", | ||
list(input = dragon)) | ||
}) | ||
|
||
test_that("Checking plot_image_grid", { | ||
plt_img_args = expand.grid(input_list = list(list(dragon, NULL, NULL, dragon)), | ||
dim = list(c(1,1), | ||
c(2,2), | ||
c(1,2), | ||
c(2,1)), | ||
draw_grid = list(FALSE, TRUE), | ||
asp = list(c(0.5,1,2,3))) | ||
|
||
run_tests("plot_image_grid", plt_img_args, plot_prefix = "plt_img_grid", list()) | ||
}) | ||
# save_test_png = function(code, path) { | ||
# grDevices::png(filename=path, width=500, height=400) | ||
# code | ||
# dev.off() | ||
# path | ||
# } | ||
# | ||
# compare_image = function(path1, path2) { | ||
# image1 = png::readPNG(path1) | ||
# image2 = png::readPNG(path2) | ||
# return(identical(image1, image2)) | ||
# } | ||
# | ||
# run_tests = function(func, argument_grid, plot_prefix="", ...) { | ||
# stopifnot(inherits(argument_grid,"data.frame")) | ||
# for(i in seq_len(nrow(argument_grid))){ | ||
# args = unlist(argument_grid[i,], recursive = FALSE) | ||
# test_filename = sprintf("%s_test%i.png", | ||
# plot_prefix , i) | ||
# path = tempfile(fileext = ".png") | ||
# | ||
# 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) | ||
# } | ||
# } | ||
# | ||
# test_that("Checking plot_image", { | ||
# plt_img_args = expand.grid(rotate = list(0,90,180,270), | ||
# draw_grid = list(FALSE, TRUE), | ||
# asp = list(0.5,1,2), | ||
# new_page = list(TRUE, FALSE)) | ||
# | ||
# run_tests("plot_image", plt_img_args, plot_prefix = "plt_img", | ||
# list(input = dragon)) | ||
# }) | ||
# | ||
# test_that("Checking plot_image_grid", { | ||
# plt_img_args = expand.grid(input_list = list(list(dragon, NULL, NULL, dragon)), | ||
# dim = list(c(1,1), | ||
# c(2,2), | ||
# c(1,2), | ||
# 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 | ||
# | ||
# run_tests("plot_image_grid", plt_img_args, plot_prefix = "plt_img_grid", list()) | ||
# }) |