Skip to content

Commit 7804095

Browse files
committed
fix: use skip_on_ci instead of checking graphics version
1 parent 14b411a commit 7804095

File tree

1 file changed

+31
-54
lines changed

1 file changed

+31
-54
lines changed

tests/testthat/test-gf_model-visual.R

Lines changed: 31 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,15 @@
1-
graphics_api_version_mismatch <- tryCatch(
2-
{
3-
vdiffr::write_svg(tempfile(fileext = ".svg"), function() NULL)
4-
FALSE
5-
},
6-
error = function(e) {
7-
grepl("Graphics API version mismatch", conditionMessage(e), fixed = TRUE)
8-
},
9-
finally = {
10-
# close the device if it opened successfully
11-
if (grDevices::dev.cur() > 1) grDevices::dev.off()
12-
}
13-
)
14-
15-
# Helper to skip if graphics API version mismatch
16-
skip_if_graphics_api_mismatch <- function() {
17-
testthat::skip_if(
18-
graphics_api_version_mismatch,
19-
"Graphics API version mismatch. Skipping tests that require vdiffr."
20-
)
21-
}
22-
23-
241
# No predictor -------------------------------------------------------------------------------
252

263
test_that("it plots the empty model as a horizontal line when outcome is on Y, two axis plots", {
27-
skip_if_graphics_api_mismatch()
4+
testthat::skip_on_ci()
285

296
gf_point(later_anxiety ~ base_anxiety, color = ~condition, data = er) %>%
307
gf_model(lm(later_anxiety ~ NULL, data = er)) %>%
318
expect_doppelganger("[gf_point] null mod., y on Y")
329
})
3310

3411
test_that("it plots the empty model as a vertical line when outcome is on Y, one axis plot", {
35-
skip_if_graphics_api_mismatch()
12+
testthat::skip_on_ci()
3613

3714
# I know that the plot has two axes, but I only specify one, that's why "one" axis plot
3815
snap_name <- function(plot_name, suffix = "") {
@@ -65,14 +42,14 @@ test_that("it plots the empty model as a vertical line when outcome is on Y, one
6542
})
6643

6744
test_that("it plots the empty model as a horizontal line when outcome is on X, two axis plot", {
68-
skip_if_graphics_api_mismatch()
45+
testthat::skip_on_ci()
6946
gf_point(base_anxiety ~ later_anxiety, color = ~condition, data = er) %>%
7047
gf_model(lm(later_anxiety ~ NULL, data = er)) %>%
7148
expect_doppelganger("[gf_point] null mod., y on X")
7249
})
7350

7451
test_that("it plots the empty model as a vertical line when outcome is on X, one axis plot", {
75-
skip_if_graphics_api_mismatch()
52+
testthat::skip_on_ci()
7653

7754
# I know that the plot has two axes, but I only specify one, that's why "one" axis plot
7855
snap_name <- function(plot_name, suffix = "") {
@@ -117,7 +94,7 @@ test_that("it plots the empty model as a vertical line when outcome is on X, one
11794
# Single predictor, on axis, categorical ------------------------------------------------------
11895

11996
test_that("it plots 1 predictor (on axis, categorical) models as lines at means, outcome on Y", {
120-
skip_if_graphics_api_mismatch()
97+
testthat::skip_on_ci()
12198
testthat::skip_on_ci()
12299

123100
snap_name <- function(plot_name, suffix = "") {
@@ -134,7 +111,7 @@ test_that("it plots 1 predictor (on axis, categorical) models as lines at means,
134111
})
135112

136113
test_that("it plots 1 predictor (on axis, categorical) models as lines at means, outcome on X", {
137-
skip_if_graphics_api_mismatch()
114+
testthat::skip_on_ci()
138115

139116
snap_name <- function(plot_name, suffix = "") {
140117
glue("[{plot_name}] cond. mod., y on X{suffix}")
@@ -153,7 +130,7 @@ test_that("it plots 1 predictor (on axis, categorical) models as lines at means,
153130
# Single predictor, on aesthetic, categorical -------------------------------------------------
154131

155132
test_that("it plots 1 predictor (on aesthetic, cat.) models as lines at means, outcome on Y", {
156-
skip_if_graphics_api_mismatch()
133+
testthat::skip_on_ci()
157134
testthat::skip_on_ci()
158135

159136
snap_name <- function(plot_name, suffix = "") {
@@ -180,7 +157,7 @@ test_that("it plots 1 predictor (on aesthetic, cat.) models as lines at means, o
180157
})
181158

182159
test_that("it plots 1 predictor (on aesthetic, cat.) models as lines at means, outcome on X", {
183-
skip_if_graphics_api_mismatch()
160+
testthat::skip_on_ci()
184161
testthat::skip_on_ci()
185162

186163
snap_name <- function(plot_name, suffix = "") {
@@ -210,7 +187,7 @@ test_that("it plots 1 predictor (on aesthetic, cat.) models as lines at means, o
210187
# Single predictor, on facet, categorical -----------------------------------------------------
211188

212189
test_that("it plots 1 predictor (on facet, compact cat.) models as lines at means, outcome on Y", {
213-
skip_if_graphics_api_mismatch()
190+
testthat::skip_on_ci()
214191
testthat::skip_on_ci()
215192

216193
snap_name <- function(plot_name, suffix = "") {
@@ -248,7 +225,7 @@ test_that("it plots 1 predictor (on facet, compact cat.) models as lines at mean
248225
})
249226

250227
test_that("it plots 1 predictor (on facet, compact cat.) models as lines at means, outcome on X", {
251-
skip_if_graphics_api_mismatch()
228+
testthat::skip_on_ci()
252229
testthat::skip_on_ci()
253230

254231
snap_name <- function(plot_name, suffix = "") {
@@ -279,7 +256,7 @@ test_that("it plots 1 predictor (on facet, compact cat.) models as lines at mean
279256
# Single predictor, on axis, continuous -------------------------------------------------------
280257

281258
test_that("it plots 1 predictor (on axis, cont.) models as a fit line", {
282-
skip_if_graphics_api_mismatch()
259+
testthat::skip_on_ci()
283260

284261
gf_point(later_anxiety ~ base_anxiety, color = ~condition, data = er) %>%
285262
gf_model(lm(later_anxiety ~ base_anxiety, data = er)) %>%
@@ -294,7 +271,7 @@ test_that("it plots 1 predictor (on axis, cont.) models as a fit line", {
294271
# Single predictor, on aesthetic, continuous --------------------------------------------------
295272

296273
test_that("it splits continuous aesthetic predictors at -+1 SD and mean", {
297-
skip_if_graphics_api_mismatch()
274+
testthat::skip_on_ci()
298275

299276
gf_point(later_anxiety ~ condition, color = ~base_anxiety, data = er) %>%
300277
gf_model(lm(later_anxiety ~ base_anxiety, data = er)) %>%
@@ -309,47 +286,47 @@ test_that("it splits continuous aesthetic predictors at -+1 SD and mean", {
309286
# Two predictors, on axis and aesthetic -------------------------------------------------------
310287

311288
test_that("it plots main effects models (cat. + cat.)", {
312-
skip_if_graphics_api_mismatch()
289+
testthat::skip_on_ci()
313290

314291
gf_point(later_anxiety ~ provider, color = ~condition, data = er) %>%
315292
gf_model(lm(later_anxiety ~ provider + condition, data = er)) %>%
316293
expect_doppelganger("[gf_point] floating 'parallel' hashes in two colors")
317294
})
318295

319296
test_that("it plots main effects models (quant. + cat.)", {
320-
skip_if_graphics_api_mismatch()
297+
testthat::skip_on_ci()
321298

322299
gf_point(later_anxiety ~ base_anxiety, color = ~condition, data = er) %>%
323300
gf_model(lm(later_anxiety ~ base_anxiety + condition, data = er)) %>%
324301
expect_doppelganger("[gf_point] parallel lines in 2 colors")
325302
})
326303

327304
test_that("it plots main effects models (cat. + quant.)", {
328-
skip_if_graphics_api_mismatch()
305+
testthat::skip_on_ci()
329306

330307
gf_point(later_anxiety ~ condition, color = ~base_anxiety, data = er) %>%
331308
gf_model(lm(later_anxiety ~ condition + base_anxiety, data = er)) %>%
332309
expect_doppelganger("[gf_point] parallel hashes in 3 colors (M, +-SD)")
333310
})
334311

335312
test_that("it plots main effect models (quant. + quant.)", {
336-
skip_if_graphics_api_mismatch()
313+
testthat::skip_on_ci()
337314

338315
gf_point(later_anxiety ~ base_anxiety, color = ~base_depression, data = er) %>%
339316
gf_model(lm(later_anxiety ~ base_anxiety + base_depression, data = er)) %>%
340317
expect_doppelganger("[gf_point] parallel lines in 3 colors (M, +-SD)")
341318
})
342319

343320
test_that("it plots interactive models (cat. * cat.)", {
344-
skip_if_graphics_api_mismatch()
321+
testthat::skip_on_ci()
345322

346323
gf_point(later_anxiety ~ provider, color = ~condition, data = er) %>%
347324
gf_model(lm(later_anxiety ~ provider * condition, data = er)) %>%
348325
expect_doppelganger("[gf_point] diverging hashes in 2 colors")
349326
})
350327

351328
test_that("it plots interactive models (quant. * cat.)", {
352-
skip_if_graphics_api_mismatch()
329+
testthat::skip_on_ci()
353330

354331
gf_point(later_anxiety ~ base_anxiety, color = ~condition, data = er) %>%
355332
gf_model(lm(later_anxiety ~ base_anxiety * condition, data = er)) %>%
@@ -361,15 +338,15 @@ test_that("it plots interactive models (quant. * cat.)", {
361338
})
362339

363340
test_that("it plots interactive models (cat. * quant.)", {
364-
skip_if_graphics_api_mismatch()
341+
testthat::skip_on_ci()
365342

366343
gf_point(later_anxiety ~ condition, color = ~base_anxiety, data = er) %>%
367344
gf_model(lm(later_anxiety ~ condition * base_anxiety, data = er)) %>%
368345
expect_doppelganger("[gf_point] non-parallel hashes in 3 colors (M, +-SD)")
369346
})
370347

371348
test_that("it plots interactive models (quant. * quant.)", {
372-
skip_if_graphics_api_mismatch()
349+
testthat::skip_on_ci()
373350

374351
gf_point(later_anxiety ~ base_anxiety, color = ~base_depression, data = er) %>%
375352
gf_model(lm(later_anxiety ~ base_anxiety * base_depression, data = er)) %>%
@@ -380,31 +357,31 @@ test_that("it plots interactive models (quant. * quant.)", {
380357
# Two predictors, on axis and facet -----------------------------------------------------------
381358

382359
test_that("it plots main effect models across facets (cat. + cat.)", {
383-
skip_if_graphics_api_mismatch()
360+
testthat::skip_on_ci()
384361

385362
gf_point(later_anxiety ~ provider | condition, data = er) %>%
386363
gf_model(lm(later_anxiety ~ provider + condition, data = er)) %>%
387364
expect_doppelganger("[gf_point] hashes at an offset across facets")
388365
})
389366

390367
test_that("it plots main effect models across facets (quant. + cat.)", {
391-
skip_if_graphics_api_mismatch()
368+
testthat::skip_on_ci()
392369

393370
gf_point(later_anxiety ~ base_anxiety | condition, data = er) %>%
394371
gf_model(lm(later_anxiety ~ base_anxiety + condition, data = er)) %>%
395372
expect_doppelganger("[gf_point] parallel lines in different facets")
396373
})
397374

398375
test_that("it plots interactive models across facets (cat. * cat.)", {
399-
skip_if_graphics_api_mismatch()
376+
testthat::skip_on_ci()
400377

401378
gf_point(later_anxiety ~ provider | condition, data = er) %>%
402379
gf_model(lm(later_anxiety ~ provider * condition, data = er)) %>%
403380
expect_doppelganger("[gf_point] hash patterns across facets")
404381
})
405382

406383
test_that("it plots interactive models across facets (quant. * cat.)", {
407-
skip_if_graphics_api_mismatch()
384+
testthat::skip_on_ci()
408385

409386
gf_point(later_anxiety ~ base_anxiety | condition, data = er) %>%
410387
gf_model(lm(later_anxiety ~ base_anxiety * condition, data = er)) %>%
@@ -425,39 +402,39 @@ test_that("it plots interactive models across facets (quant. * cat.)", {
425402
# Mappings ------------------------------------------------------------------------------------
426403

427404
test_that("it respects static aesthetic choices", {
428-
skip_if_graphics_api_mismatch()
405+
testthat::skip_on_ci()
429406

430407
gf_point(later_anxiety ~ base_anxiety, color = ~condition, data = er) %>%
431408
gf_model(lm(later_anxiety ~ base_anxiety, data = er), color = "blue") %>%
432409
expect_doppelganger("[gf_point] model line is blue")
433410
})
434411

435412
test_that("it un-maps dynamic aesthetics from underlying layers that are not in the model", {
436-
skip_if_graphics_api_mismatch()
413+
testthat::skip_on_ci()
437414

438415
gf_point(later_anxiety ~ base_anxiety, color = ~condition, shape = ~provider, data = er) %>%
439416
gf_model(lm(later_anxiety ~ base_anxiety, data = er)) %>%
440417
expect_doppelganger("[gf_point] anx. mod., y on Y, with color & shape")
441418
})
442419

443420
test_that("it will translate color arguments if applicable (e.g. fill to color)", {
444-
skip_if_graphics_api_mismatch()
421+
testthat::skip_on_ci()
445422

446423
gf_boxplot(later_anxiety ~ provider, fill = ~condition, data = er) %>%
447424
gf_model(lm(later_anxiety ~ condition, data = er)) %>%
448425
expect_doppelganger("[gf_point] cond. mod., y on Y, with color")
449426
})
450427

451428
test_that("it can use aesthetics other than color... just checking", {
452-
skip_if_graphics_api_mismatch()
429+
testthat::skip_on_ci()
453430

454431
gf_point(later_anxiety ~ base_anxiety, shape = ~condition, data = er) %>%
455432
gf_model(lm(later_anxiety ~ condition, data = er)) %>%
456433
expect_doppelganger("[gf_point] cond. mod., y on Y, pred. on shape")
457434
})
458435

459436
test_that("it allows mapping new aesthetics", {
460-
skip_if_graphics_api_mismatch()
437+
testthat::skip_on_ci()
461438

462439
gf_point(later_anxiety ~ base_anxiety, color = ~condition, data = er) %>%
463440
gf_model(lm(later_anxiety ~ condition, data = er), linetype = ~condition) %>%
@@ -469,7 +446,7 @@ test_that("it allows mapping new aesthetics", {
469446
# Alternate specification ---------------------------------------------------------------------
470447

471448
test_that("you can pass it a formula instead of an `lm()` object", {
472-
skip_if_graphics_api_mismatch()
449+
testthat::skip_on_ci()
473450

474451
gf_point(later_anxiety ~ base_anxiety, color = ~condition, data = er) %>%
475452
gf_model(later_anxiety ~ condition) %>%
@@ -480,7 +457,7 @@ test_that("you can pass it a formula instead of an `lm()` object", {
480457
# Other tests ---------------------------------------------------------------------------------
481458

482459
test_that("it treats boolean and character predictors like factors", {
483-
skip_if_graphics_api_mismatch()
460+
testthat::skip_on_ci()
484461

485462
new_er <- er %>%
486463
mutate(base_anxiety_high = base_anxiety > 5)

0 commit comments

Comments
 (0)