Skip to content

Commit ad3dbfc

Browse files
Use testthat 3e (#4522)
1 parent 4c1c8df commit ad3dbfc

File tree

95 files changed

+123
-258
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+123
-258
lines changed

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Suggests:
6464
rpart,
6565
sf (>= 0.7-3),
6666
svglite (>= 1.2.0.9001),
67-
testthat (>= 2.1.0),
67+
testthat (>= 3.0.0),
6868
vdiffr (>= 1.0.0),
6969
xml2
7070
Enhances: sp
@@ -274,3 +274,4 @@ Config/Needs/website:
274274
tidyr,
275275
forcats,
276276
tidyverse/tidytemplate
277+
Config/testthat/edition: 3

tests/testthat/test-add.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("Adding plot elements")
2-
31
test_that("mapping class is preserved when adding uneval objects", {
42
p <- ggplot(mtcars) + aes(wt, mpg)
53
expect_identical(class(p$mapping), "uneval")

tests/testthat/test-aes-calculated.r

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("test-aes-calculated.r")
2-
31
test_that("constants aren't calculated", {
42
expect_equal(is_calculated_aes(aes(1, "a", TRUE)), c(FALSE, FALSE, FALSE))
53
})

tests/testthat/test-aes-grouping.r

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("Aesthetics (grouping)")
2-
31
df <- data_frame(
42
x = 1:4,
53
a = c("a", "a", "b", "b"),

tests/testthat/test-aes-setting.r

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("Aes - setting values")
2-
31
test_that("aesthetic parameters match length of data", {
42
df <- data_frame(x = 1:5, y = 1:5)
53
p <- ggplot(df, aes(x, y))

tests/testthat/test-aes.r

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("Creating aesthetic mappings")
2-
31
test_that("aes() captures input expressions", {
42
out <- aes(mpg, wt + 1)
53
expect_identical(out$x, quo(mpg))
@@ -36,7 +34,9 @@ test_that("aes_q() & aes_string() preserve explicit NULLs", {
3634
test_that("aes_all() converts strings into mappings", {
3735
expect_equal(
3836
aes_all(c("x", "y", "col", "pch")),
39-
aes(x, y, colour = col, shape = pch)
37+
aes(x, y, colour = col, shape = pch),
38+
# ignore the environments of quosures
39+
ignore_attr = TRUE
4040
)
4141
})
4242

tests/testthat/test-annotate.r

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("annotate")
2-
31
test_that("dates in segment annotation work", {
42
dt <- structure(list(month = structure(c(1364774400, 1377993600),
53
class = c("POSIXct", "POSIXt"), tzone = "UTC"), total = c(-10.3,

tests/testthat/test-build.r

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
# Test the complete path from plot specification to rendered data
2-
context("Plot building")
3-
42
df <- data_frame(x = 1:3, y = 3:1, z = letters[1:3])
53

64
test_that("there is one data frame for each layer", {
@@ -19,8 +17,8 @@ test_that("position aesthetics are coerced to correct type", {
1917
l1 <- ggplot(df, aes(x, y)) + geom_point()
2018
d1 <- layer_data(l1, 1)
2119

22-
expect_is(d1$x, "numeric")
23-
expect_is(d1$y, "numeric")
20+
expect_type(d1$x, "double")
21+
expect_type(d1$y, "double")
2422

2523
l2 <- ggplot(df, aes(x, z)) + geom_point() + scale_x_discrete()
2624
d2 <- layer_data(l2, 1)
@@ -52,5 +50,5 @@ test_that("strings are not converted to factors", {
5250
p <- ggplot(df, aes(x, y)) +
5351
geom_text(aes(label = label), parse = TRUE)
5452

55-
expect_is(layer_data(p)$label, "character")
53+
expect_type(layer_data(p)$label, "character")
5654
})

tests/testthat/test-coord-.r

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("test-coord-.r")
2-
31
test_that("clipping is on by default", {
42
p <- ggplot()
53
coord <- ggplot_build(p)$layout$coord

tests/testthat/test-coord-cartesian.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("coord_cartesian")
2-
31
test_that("clipping can be turned off and on", {
42
# clip on by default
53
p <- ggplot() + coord_cartesian()

tests/testthat/test-coord-flip.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("test-coord-flip.r")
2-
31
test_that("secondary labels are correctly turned off", {
42
# Using a visual test because the labels are only generated during rendering
53
expect_doppelganger("turning off secondary title with coord_flip",

tests/testthat/test-coord-map.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("coord_map")
2-
31
test_that("USA state map drawn", {
42
skip_if(packageVersion("base") < "3.5.0")
53
us_map <- map_data("usa")

tests/testthat/test-coord-polar.r

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("coord_polar")
2-
31
test_that("polar distance is calculated correctly", {
42
dat <- data_frame(
53
theta = c(0, 2*pi, 2, 6, 6, 1, 1, 0),

tests/testthat/test-coord-train.r

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("coord_train")
2-
31
test_that("NA's don't appear in breaks", {
42

53
# Returns true if any major/minor breaks have an NA

tests/testthat/test-coord-transform.R

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("coord_trans")
2-
31
test_that("warnings are generated when cord_trans() results in new infinite values", {
42
p <- ggplot(head(diamonds, 20)) +
53
geom_bar(aes(x = cut)) +
@@ -9,8 +7,12 @@ test_that("warnings are generated when cord_trans() results in new infinite valu
97
geom_point() +
108
coord_trans(x = "log")
119

12-
expect_warning(ggplot_gtable(ggplot_build(p)), "Transformation introduced infinite values in y-axis")
13-
expect_warning(ggplot_gtable(ggplot_build(p2)), "Transformation introduced infinite values in x-axis")
10+
# TODO: These multiple warnings should be summarized nicely. Until this gets
11+
# fixed, this test ignores all the following errors than the first one.
12+
suppressWarnings({
13+
expect_warning(ggplot_gtable(ggplot_build(p)), "Transformation introduced infinite values in y-axis")
14+
expect_warning(ggplot_gtable(ggplot_build(p2)), "Transformation introduced infinite values in x-axis")
15+
})
1416
})
1517

1618
test_that("no warnings are generated when original data has Inf values, but no new Inf values created from the transformation", {

tests/testthat/test-coord_sf.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("coord_sf")
2-
31
test_that("basic plot builds without error", {
42
skip_if_not_installed("sf")
53

tests/testthat/test-data.r

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
context("Data")
2-
31
test_that("stringsAsFactors doesn't affect results", {
4-
old <- getOption("stringsAsFactors")
5-
on.exit(options(stringsAsFactors = old), add = TRUE)
2+
skip_if(as.integer(R.Version()$major) >= 4L, "stringsAsFactors only affects R <4.0")
3+
4+
old <- getOption("stringsAsFactors")
5+
on.exit(options(stringsAsFactors = old), add = TRUE)
66

7-
dat.character <- data_frame(x = letters[5:1], y = 1:5)
8-
dat.factor <- data_frame(x = letters[5:1], y = 1:5)
7+
dat.character <- data_frame(x = letters[5:1], y = 1:5)
8+
dat.factor <- data_frame(x = letters[5:1], y = 1:5)
99

10-
base <- ggplot(mapping = aes(x, y)) + geom_point()
11-
xlabels <- function(x) x$layout$panel_params[[1]]$x$get_labels()
10+
base <- ggplot(mapping = aes(x, y)) + geom_point()
11+
xlabels <- function(x) x$layout$panel_params[[1]]$x$get_labels()
1212

13-
options(stringsAsFactors = TRUE)
14-
char_true <- ggplot_build(base %+% dat.character)
15-
factor_true <- ggplot_build(base %+% dat.factor)
13+
options(stringsAsFactors = TRUE)
14+
char_true <- ggplot_build(base %+% dat.character)
15+
factor_true <- ggplot_build(base %+% dat.factor)
1616

17-
options(stringsAsFactors = FALSE)
18-
char_false <- ggplot_build(base %+% dat.character)
19-
factor_false <- ggplot_build(base %+% dat.factor)
17+
options(stringsAsFactors = FALSE)
18+
char_false <- ggplot_build(base %+% dat.character)
19+
factor_false <- ggplot_build(base %+% dat.factor)
2020

21-
expect_equal(xlabels(char_true), letters[1:5])
22-
expect_equal(xlabels(char_false), letters[1:5])
23-
expect_equal(xlabels(factor_true), letters[1:5])
24-
expect_equal(xlabels(factor_false), letters[1:5])
21+
expect_equal(xlabels(char_true), letters[1:5])
22+
expect_equal(xlabels(char_false), letters[1:5])
23+
expect_equal(xlabels(factor_true), letters[1:5])
24+
expect_equal(xlabels(factor_false), letters[1:5])
2525
})

tests/testthat/test-draw-key.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
# Setting of legend key glyphs has to be tested visually
2-
context("Legend key glyphs")
3-
42

53
test_that("alternative key glyphs work", {
64
df <- data_frame(x = 1:3, y = 3:1, z = letters[1:3])

tests/testthat/test-empty-data.r

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context('Empty data')
2-
31
df0 <- data_frame(mpg = numeric(0), wt = numeric(0), am = numeric(0), cyl = numeric(0))
42

53
test_that("layers with empty data are silently omitted", {

tests/testthat/test-error.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("error")
2-
31
test_that("various misuses of +.gg (#2638)", {
42
expect_error(
53
{

tests/testthat/test-facet-.r

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("Facetting")
2-
31
test_that("as_facets_list() coerces formulas", {
42
expect_identical(as_facets_list(~foo), list(quos(), quos(foo = foo)))
53
expect_identical(as_facets_list(~foo + bar), list(quos(), quos(foo = foo, bar = bar)))
@@ -277,15 +275,16 @@ test_that("combine_vars() generates the correct combinations", {
277275
factor = factor(c("level1", "level2")),
278276
stringsAsFactors = FALSE
279277
)
278+
attr(df_all, "out.attrs") <- NULL
280279

281280
vars_all <- vars(letter = letter, number = number, boolean = boolean, factor = factor)
282281

283-
expect_equivalent(
282+
expect_equal(
284283
combine_vars(list(df_one), vars = vars_all),
285284
df_one
286285
)
287286

288-
expect_equivalent(
287+
expect_equal(
289288
combine_vars(list(df_all), vars = vars_all),
290289
df_all
291290
)
@@ -295,21 +294,22 @@ test_that("combine_vars() generates the correct combinations", {
295294
# NAs are kept with with drop = TRUE
296295
# drop keeps all combinations of data, regardless of the combinations in which
297296
# they appear in the data (in addition to keeping unused factor levels)
298-
expect_equivalent(
297+
expect_equal(
299298
combine_vars(list(df_one), vars = vars_all, drop = FALSE),
300-
df_all[order(df_all$letter, df_all$number, df_all$boolean, df_all$factor), ]
299+
df_all[order(df_all$letter, df_all$number, df_all$boolean, df_all$factor), ],
300+
ignore_attr = TRUE # do not compare `row.names`
301301
)
302302
})
303303

304304
test_that("drop = FALSE in combine_vars() keeps unused factor levels", {
305305
df <- data_frame(x = factor("a", levels = c("a", "b")))
306-
expect_equivalent(
306+
expect_equal(
307307
combine_vars(list(df), vars = vars(x = x), drop = TRUE),
308-
data_frame(x = factor("a"))
308+
data_frame(x = factor("a", levels = c("a", "b")))
309309
)
310-
expect_equivalent(
310+
expect_equal(
311311
combine_vars(list(df), vars = vars(x = x), drop = FALSE),
312-
data_frame(x = factor(c("a", "b")))
312+
data_frame(x = factor(c("a", "b"), levels = c("a", "b")))
313313
)
314314
})
315315

tests/testthat/test-facet-labels.r

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("Facet Labels")
2-
31
get_labels_matrix <- function(plot, ...) {
42
data <- ggplot_build(plot)
53
layout <- data$layout

tests/testthat/test-facet-layout.r

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("Facetting (layout)")
2-
31
a <- data_frame(a = c(1, 1, 2, 2), b = c(1, 2, 1, 1))
42
b <- data_frame(a = 3)
53
c <- data_frame(b = 3)

tests/testthat/test-facet-map.r

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("Facetting (mapping)")
2-
31
df <- expand.grid(a = 1:2, b = 1:2)
42
df_a <- unique(df["a"])
53
df_b <- unique(df["b"])

tests/testthat/test-facet-strips.r

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("Facet Strips")
2-
31
strip_layout <- function(p) {
42
data <- ggplot_build(p)
53
plot <- data$plot

tests/testthat/test-fortify.r

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("Fortify")
2-
31
test_that("spatial polygons have correct ordering", {
42
skip_if_not_installed("sp")
53

@@ -31,9 +29,17 @@ test_that("spatial polygons have correct ordering", {
3129
polys2 <- rev(polys)
3230
polys2_sp <- sp::SpatialPolygons(polys2)
3331
fake_sp2 <- sp::SpatialPolygonsDataFrame(polys2_sp, fake_data)
34-
fake_sp2_fortified <- fortify(fake_sp2)
32+
expected <- fortify(fake_sp2)
33+
expected <- expected[order(expected$id, expected$order), ]
34+
35+
actual <- fortify(fake_sp)
36+
37+
# the levels are different, so these columns need to be converted to character to compare
38+
expected$group <- as.character(expected$group)
39+
actual$group <- as.character(actual$group)
3540

36-
expect_equivalent(fortify(fake_sp), fake_sp2_fortified[order(fake_sp2_fortified$id, fake_sp2_fortified$order), ])
41+
# Use expect_equal(ignore_attr = TRUE) to ignore rownames
42+
expect_equal(actual, expected, ignore_attr = TRUE)
3743
})
3844

3945
test_that("fortify.default proves a helpful error with class uneval", {

tests/testthat/test-function-args.r

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("function-args")
2-
31
filter_args <- function(x) {
42
all_names <- names(x)
53
all_names <- setdiff(all_names, c("self", "data", "scales", "coordinates", "..."))

tests/testthat/test-geom-bar.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("geom_bar")
2-
31
test_that("geom_bar removes bars with parts outside the plot limits", {
42
dat <- data_frame(x = c("a", "b", "b", "c", "c", "c"))
53

tests/testthat/test-geom-boxplot.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("geom_boxplot")
2-
31
# thanks wch for providing the test code
42
test_that("geom_boxplot range includes all outliers", {
53
dat <- data_frame(x = 1, y = c(-(1:20) ^ 3, (1:20) ^ 3) )

tests/testthat/test-geom-col.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("geom_col")
2-
31
test_that("geom_col removes columns with parts outside the plot limits", {
42
dat <- data_frame(x = c(1, 2, 3))
53

tests/testthat/test-geom-dotplot.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("geom_dotplot")
2-
31
skip_on_cran() # This test suite is long-running (on cran) and is skipped
42

53
set.seed(111)

tests/testthat/test-geom-freqpoly.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("geom_freqpoly")
2-
31
test_that("can do frequency polygon with categorical x", {
42
df <- data_frame(x = rep(letters[1:3], 3:1))
53

tests/testthat/test-geom-hex.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("geom_hex")
2-
31
test_that("density and value summaries are available", {
42
df <- data_frame(x = c(1, 1, 1, 2), y = c(1, 1, 1, 2))
53
base <- ggplot(df, aes(x, y)) +

tests/testthat/test-geom-hline-vline-abline.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("geom-hline-vline-abline")
2-
31

42
# Visual tests ------------------------------------------------------------
53

tests/testthat/test-geom-path.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("geom-path")
2-
31
test_that("keep_mid_true drops leading/trailing FALSE", {
42
expect_equal(keep_mid_true(c(F, F)), c(F, F))
53
expect_equal(keep_mid_true(c(F, T, F, T, F)), c(F, T, T, T, F))

tests/testthat/test-geom-point.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("geom-point")
2-
31
test_that("single strings translate to their corresponding integers", {
42
expect_equal(translate_shape_string("square open"), 0)
53
})

tests/testthat/test-geom-polygon.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("geom-polygon")
2-
31

42
# Visual tests ------------------------------------------------------------
53

0 commit comments

Comments
 (0)