-
Notifications
You must be signed in to change notification settings - Fork 4
/
test-plot_image.R
53 lines (53 loc) · 1.88 KB
/
test-plot_image.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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)))
# plt_img_args = plt_img_args[-6,] #False positive
#
# run_tests("plot_image_grid", plt_img_args, plot_prefix = "plt_img_grid", list())
# })