Skip to content

Commit 7a4979f

Browse files
committed
adjust to different covr version
1 parent 036934c commit 7a4979f

File tree

6 files changed

+92
-31
lines changed

6 files changed

+92
-31
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ inst/*.pdf
3434
po/*~
3535
inst/doc
3636
.Rproj.user
37-
37+
.DS_Store

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ print(gridify_object_fill)
100100

101101
<img src="man/figures/README-example-1.png" width="100%" />
102102

103-
Note: Get the image using `export_to(gridify_object, to = "mypng.png", res = 300, width = 2300, height = 1900)`
103+
Note: Get the image using
104+
`export_to(gridify_object_fill, to = "mypng.png", res = 300, width = 2300, height = 1900)`
104105

105106
## Documentation Guide
106107

tests/testthat/test_print.R

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,38 @@ test_that("print on gridifyClass returns invisibly grob object", {
1111
expect_type(print(test_gridify), "language")
1212
})
1313

14+
test_that("print on gridifyClass returns invisibly grob object", {
15+
expect_silent(
16+
test_gridify <- gridify(
17+
object = ggplot2::ggplot(mtcars, ggplot2::aes(mpg, wt)) +
18+
ggplot2::geom_point(),
19+
layout = gridifyLayout(
20+
nrow = 3L,
21+
ncol = 1L,
22+
heights = grid::unit(c(0, 10, 0), c("lines", "lines", "lines")),
23+
widths = grid::unit(1, "npc"),
24+
margin = grid::unit(c(t = 0.1, r = 0.1, b = 0.1, l = 0.1), units = "npc"),
25+
global_gpar = grid::gpar(),
26+
object = gridifyObject(row = 2, col = 1),
27+
cells = gridifyCells(
28+
title = gridifyCell(
29+
row = 1, col = 1, text = "Longer Default Title", mch = 10,
30+
gpar = grid::gpar(col = "black", fontsize = 12)
31+
),
32+
footer = gridifyCell(row = 3, col = 1)
33+
),
34+
adjust_height = TRUE
35+
)
36+
)
37+
)
38+
expect_silent(
39+
test_gridify <- set_cell(test_gridify, "footer", "Footer", gpar = grid::gpar(col = "black"))
40+
)
41+
expect_s4_class(test_gridify, "gridifyClass")
42+
expect_invisible(print(test_gridify))
43+
expect_type(print(test_gridify), "language")
44+
})
45+
1446
test_that("print on gridifyClass creates image", {
1547
skip_if(!getOption("RUNSNAPSHOTTESTS", FALSE))
1648
expect_silent(

tests/testthat/test_set_cell.R

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ test_that("set_cell works on gridify object", {
5555
test_that("set_cell works with multiple arguments filled", {
5656
expect_s4_class(test_gridify, "gridifyClass")
5757

58-
output <- set_cell(test_gridify, "title", "TITLE", mch = NULL, x = 0.7, hjust = 1, rot = 45)
58+
output <- set_cell(test_gridify, "title", "TITLE", mch = 120, x = 0.7, hjust = 1, rot = 45)
5959
output <- set_cell(
6060
output, "footer", "FOOTER",
6161
mch = NULL, y = 0.2, hjust = 0, gpar = grid::gpar(fontsize = 22, col = "red")
@@ -64,7 +64,7 @@ test_that("set_cell works with multiple arguments filled", {
6464
expect_equal(output@elements, list(
6565
title = list(
6666
text = "TITLE",
67-
mch = NULL,
67+
mch = 120,
6868
x = 0.7,
6969
y = NULL,
7070
hjust = 1,
@@ -171,6 +171,19 @@ test_that("set_cell errors when cell gpar is wrong", {
171171
)
172172
})
173173

174+
test_that("set_cell errors when cell mch is wrong", {
175+
expect_error(
176+
set_cell(
177+
test_gridify,
178+
"title",
179+
"something",
180+
mch = "a"
181+
),
182+
"The mch argument is not a positive numeric value",
183+
fixed = TRUE
184+
)
185+
})
186+
174187
test_that("Image testing for set_cell", {
175188
skip_if(!getOption("RUNSNAPSHOTTESTS", FALSE))
176189

tests/testthat/test_show.R

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,17 @@ test_that("show on complex gridifyLayout returns information to the console", {
192192

193193
test_that("test span row for output height row = c(x:y)", {
194194
test_layout <- gridifyLayout(
195-
nrow = 6L,
195+
nrow = 3L,
196196
ncol = 1L,
197-
heights = grid::unit(c(0.05, 0.05, 0.05, 0.7, 0.05, 0.1), "npc"),
197+
heights = grid::unit(c(0.15, 0.7, 0.15), "npc"),
198198
widths = grid::unit(1, "npc"),
199199
margin = grid::unit(c(t = 0.1, r = 0.1, b = 0.1, l = 0.1), units = "npc"),
200200
global_gpar = grid::gpar(),
201-
object = gridifyObject(row = c(1:3), col = 1),
202-
cells = gridifyCells(title = gridifyCell(row = 1, col = 1), footer = gridifyCell(row = 3, col = 1))
201+
object = gridifyObject(row = 2, col = 1),
202+
cells = gridifyCells(
203+
title = gridifyCell(row = 1, col = 1),
204+
footer = gridifyCell(row = 3, col = 1)
205+
)
203206
)
204207
expect_s4_class(test_layout, "gridifyLayout")
205208

@@ -209,31 +212,34 @@ test_that("test span row for output height row = c(x:y)", {
209212

210213
expect_equal(output, c(
211214
"gridifyLayout object", "---------------------", "Layout dimensions:",
212-
" Number of rows: 6", " Number of columns: 1", "", "Heights of rows:",
213-
" Row 1: 0.05 npc", " Row 2: 0.05 npc", " Row 3: 0.05 npc",
214-
" Row 4: 0.7 npc", " Row 5: 0.05 npc", " Row 6: 0.1 npc",
215+
" Number of rows: 3", " Number of columns: 1", "", "Heights of rows:",
216+
" Row 1: 0.15 npc", " Row 2: 0.7 npc", " Row 3: 0.15 npc",
215217
"", "Widths of columns:", " Column 1: 1 npc", "", "Object Position:",
216-
" Row: 1-3", " Col: 1", " Width: 1", " Height: 1", "", "Object Row Heights:",
217-
" Row 1: 0.05 npc", " Row 2: 0.05 npc", " Row 3: 0.05 npc",
218-
"", "Margin:", " Top: 0.1 npc", " Right: 0.1 npc", " Bottom: 0.1 npc",
219-
" Left: 0.1 npc", "", "Global graphical parameters:", " Are not set", "",
220-
"Default Cell Info:", " title:",
218+
" Row: 2", " Col: 1", " Width: 1", " Height: 1", "", "Object Row Heights:",
219+
" Row 2: 0.7 npc", "", "Margin:", " Top: 0.1 npc", " Right: 0.1 npc",
220+
" Bottom: 0.1 npc", " Left: 0.1 npc", "", "Global graphical parameters:",
221+
" Are not set", "", "Default Cell Info:", " title:",
221222
" row:1, col:1, text:NULL, mch:Inf, x:0.5, y:0.5, hjust:0.5, vjust:0.5, rot:0, ",
222-
" footer:",
223-
" row:3, col:1, text:NULL, mch:Inf, x:0.5, y:0.5, hjust:0.5, vjust:0.5, rot:0, ", ""
223+
" footer:", " row:3, col:1, text:NULL, mch:Inf, x:0.5, y:0.5, hjust:0.5, vjust:0.5, rot:0, ",
224+
""
224225
))
225226
})
226227

227228
test_that("test span row for output height row = c(x, y)", {
228229
test_layout <- gridifyLayout(
229-
nrow = 6L,
230+
nrow = 3L,
230231
ncol = 1L,
231-
heights = grid::unit(c(0.05, 0.05, 0.05, 0.7, 0.05, 0.1), "npc"),
232+
heights = grid::unit(c(0.15, 0.7, 0.15), "npc"),
232233
widths = grid::unit(1, "npc"),
233234
margin = grid::unit(c(t = 0.1, r = 0.1, b = 0.1, l = 0.1), units = "npc"),
234235
global_gpar = grid::gpar(),
235-
object = gridifyObject(row = c(1, 4), col = 1),
236-
cells = gridifyCells(title = gridifyCell(row = 1, col = 1), footer = gridifyCell(row = 3, col = 1))
236+
object = gridifyObject(row = 2, col = 1),
237+
cells = gridifyCells(
238+
title = gridifyCell(
239+
row = 1, col = 1, text = "Longer Default Title", gpar = grid::gpar(col = "black")
240+
),
241+
footer = gridifyCell(row = 3, col = 1)
242+
)
237243
)
238244
expect_s4_class(test_layout, "gridifyLayout")
239245

@@ -243,17 +249,16 @@ test_that("test span row for output height row = c(x, y)", {
243249

244250
expect_equal(output, c(
245251
"gridifyLayout object", "---------------------", "Layout dimensions:",
246-
" Number of rows: 6", " Number of columns: 1", "", "Heights of rows:",
247-
" Row 1: 0.05 npc", " Row 2: 0.05 npc", " Row 3: 0.05 npc",
248-
" Row 4: 0.7 npc", " Row 5: 0.05 npc", " Row 6: 0.1 npc",
252+
" Number of rows: 3", " Number of columns: 1", "", "Heights of rows:",
253+
" Row 1: 0.15 npc", " Row 2: 0.7 npc", " Row 3: 0.15 npc",
249254
"", "Widths of columns:", " Column 1: 1 npc", "", "Object Position:",
250-
" Row: 1-4", " Col: 1", " Width: 1", " Height: 1", "", "Object Row Heights:",
251-
" Row 1: 0.05 npc", " Row 2: 0.05 npc", " Row 3: 0.05 npc",
252-
" Row 4: 0.7 npc", "", "Margin:", " Top: 0.1 npc", " Right: 0.1 npc",
255+
" Row: 2", " Col: 1", " Width: 1", " Height: 1", "", "Object Row Heights:",
256+
" Row 2: 0.7 npc", "", "Margin:", " Top: 0.1 npc", " Right: 0.1 npc",
253257
" Bottom: 0.1 npc", " Left: 0.1 npc", "", "Global graphical parameters:",
254258
" Are not set", "", "Default Cell Info:", " title:",
255-
" row:1, col:1, text:NULL, mch:Inf, x:0.5, y:0.5, hjust:0.5, vjust:0.5, rot:0, ",
256-
" footer:",
257-
" row:3, col:1, text:NULL, mch:Inf, x:0.5, y:0.5, hjust:0.5, vjust:0.5, rot:0, ", ""
259+
" row:1, col:1, text:Longer Def..., mch:Inf, x:0.5, y:0.5, hjust:0.5, vjust:0.5, rot:0, ",
260+
" gpar - col:black, ", " footer:",
261+
" row:3, col:1, text:NULL, mch:Inf, x:0.5, y:0.5, hjust:0.5, vjust:0.5, rot:0, ",
262+
""
258263
))
259264
})

tests/testthat/test_show_cells.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
mock_gridify <- function() {
2+
grb <- grid::rectGrob()
3+
gridify(grb, simple_layout())
4+
}
5+
6+
test_that("show_cells function works with layout or gridify object", {
7+
expect_true(is.function(show_cells))
8+
expect_output(show_cells(mock_gridify()), "title")
9+
expect_output(show_cells(simple_layout()), "title")
10+
})

0 commit comments

Comments
 (0)