Skip to content

Commit e57f751

Browse files
testing r-universe failure
1 parent 4b8d8e5 commit e57f751

File tree

2 files changed

+57
-62
lines changed

2 files changed

+57
-62
lines changed

tests/testthat/setup.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ suppressPackageStartupMessages({
88
library(deSolve)
99
library(lubridate)
1010
library(oor)
11+
library(Rgraphviz)
1112
})
1213
options(macpan2_verbose = FALSE)
1314
system.file("utils", "test-cache.R", package = "macpan2") |> source()

tests/testthat/test-dot-layout.R

Lines changed: 56 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,56 @@
1-
test_that("dot layouts produce appropriate errors and output classes", {
2-
specs <- mp_tmb_entire_library()
3-
n_flows = (specs
4-
|> lapply(mp_flow_frame, topological_sort = FALSE)
5-
|> vapply(nrow, integer(1L))
6-
)
7-
no_mpflows <- which(n_flows == 0L) |> names()
8-
for (s in no_mpflows) {
9-
expect_error(
10-
mp_dot_layout(specs[[s]], action = "layout")
11-
, "was spec defined"
12-
)
13-
}
14-
plts = list()
15-
for (s in setdiff(names(specs), no_mpflows)) {
16-
plts[[s]] <- mp_dot_layout(specs[[s]], action = "layout")
17-
expect_s4_class(plts[[s]], "graphAM")
18-
}
19-
if (interactive()) for (plt in plts) Rgraphviz::renderGraph(plt)
20-
21-
## copied from https://testthat.r-lib.org/reference/expect_snapshot_file.html
22-
save_png <- function(code, width = 400, height = 400) {
23-
path <- tempfile(fileext = ".png")
24-
png(path, width = width, height = height)
25-
on.exit(dev.off())
26-
code
27-
28-
path
29-
}
30-
expect_snapshot_plot <- function(name, code) {
31-
# Other packages might affect results
32-
skip_if_not_installed("ggplot2", "2.0.0")
33-
# Or maybe the output is different on some operation systems
34-
skip_on_os("windows")
35-
# You'll need to carefully think about and experiment with these skips
36-
37-
name <- paste0(name, ".png")
38-
39-
# Announce the file before touching `code`. This way, if `code`
40-
# unexpectedly fails or skips, testthat will not auto-delete the
41-
# corresponding snapshot file.
42-
announce_snapshot_file(name = name)
43-
44-
path <- save_png(code)
45-
expect_snapshot_file(path, name)
46-
}
47-
48-
macpan_base <- mp_official_library("macpan_base")
49-
seir <- mp_official_library("seir")
50-
shiver <- mp_official_library("shiver")
51-
52-
graph3 = mp_dot_layout(macpan_base, action = "define")
53-
graph2 = mp_dot_layout(seir, action = "layout")
54-
expect_snapshot_plot("shiver1", {graph1 <- mp_dot_layout(shiver, action = "render")})
55-
expect_snapshot_plot("base", {graph3 |> Rgraphviz::layoutGraph() |> Rgraphviz::renderGraph()})
56-
expect_snapshot_plot("seir", {graph2 |> Rgraphviz::renderGraph()})
57-
expect_snapshot_plot("shiver2", {graph1 |> Rgraphviz::renderGraph()})
58-
59-
expect_s4_class(graph1, "graphAM")
60-
expect_s4_class(graph2, "graphAM")
61-
expect_s4_class(graph3, "graphAM")
62-
})
1+
# test_that("dot layouts produce appropriate errors and output classes", {
2+
# specs <- mp_tmb_entire_library()
3+
# n_flows = (specs
4+
# |> lapply(mp_flow_frame, topological_sort = FALSE)
5+
# |> vapply(nrow, integer(1L))
6+
# )
7+
# no_mpflows <- which(n_flows == 0L) |> names()
8+
# for (s in no_mpflows) {
9+
# expect_error(
10+
# mp_dot_layout(specs[[s]], action = "layout")
11+
# , "was spec defined"
12+
# )
13+
# }
14+
# plts = list()
15+
# for (s in setdiff(names(specs), no_mpflows)) {
16+
# plts[[s]] <- mp_dot_layout(specs[[s]], action = "layout")
17+
# expect_s4_class(plts[[s]], "graphAM")
18+
# }
19+
# if (interactive()) for (plt in plts) renderGraph(plt)
20+
#
21+
# ## copied from https://testthat.r-lib.org/reference/expect_snapshot_file.html
22+
# save_png <- function(code, width = 400, height = 400) {
23+
# path <- tempfile(fileext = ".png")
24+
# png(path, width = width, height = height)
25+
# on.exit(dev.off())
26+
# code
27+
#
28+
# path
29+
# }
30+
# expect_snapshot_plot <- function(name, code) {
31+
# name <- paste0(name, ".png")
32+
#
33+
# # Announce the file before touching `code`. This way, if `code`
34+
# # unexpectedly fails or skips, testthat will not auto-delete the
35+
# # corresponding snapshot file.
36+
# announce_snapshot_file(name = name)
37+
#
38+
# path <- save_png(code)
39+
# expect_snapshot_file(path, name)
40+
# }
41+
#
42+
# macpan_base <- mp_official_library("macpan_base")
43+
# seir <- mp_official_library("seir")
44+
# shiver <- mp_official_library("shiver")
45+
#
46+
# graph3 = mp_dot_layout(macpan_base, action = "define")
47+
# graph2 = mp_dot_layout(seir, action = "layout")
48+
# expect_snapshot_plot("shiver1", {graph1 <- mp_dot_layout(shiver, action = "render")})
49+
# expect_snapshot_plot("base", {graph3 |> layoutGraph() |> renderGraph()})
50+
# expect_snapshot_plot("seir", {graph2 |> renderGraph()})
51+
# expect_snapshot_plot("shiver2", {graph1 |> renderGraph()})
52+
#
53+
# expect_s4_class(graph1, "graphAM")
54+
# expect_s4_class(graph2, "graphAM")
55+
# expect_s4_class(graph3, "graphAM")
56+
# })

0 commit comments

Comments
 (0)