Skip to content

Commit 5c7867d

Browse files
authored
Silence tests (tidyverse#5507)
* set dotplot binwidth * set number of bins * fill in smooth defaults * silence coord replacements * stat_summary2d has been replace by stat_summary_2d * fill quantile formula * suppress scale type messages * suppress sp-related messages * use explicit tempfiles * Include snapshot renaming from tidyverse#5504
1 parent 41587fc commit 5c7867d

11 files changed

+46
-32
lines changed

tests/testthat/_snaps/scale_date/scale-x-date-labels-date-format-m-d.svg renamed to tests/testthat/_snaps/scale_date/scale-x-date-labels-label-date-m-d.svg

Lines changed: 1 addition & 1 deletion
Loading

tests/testthat/_snaps/scale_date/scale-x-date-labels-date-format-w-week.svg renamed to tests/testthat/_snaps/scale_date/scale-x-date-labels-label-date-w-week.svg

Lines changed: 1 addition & 1 deletion
Loading

tests/testthat/test-fortify.R

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
test_that("spatial polygons have correct ordering", {
2-
skip_if_not_installed("sp")
2+
suppressPackageStartupMessages({
3+
skip_if_not_installed("sp")
4+
})
5+
36

47
make_square <- function(x = 0, y = 0, height = 1, width = 1){
58
delx <- width/2
@@ -30,12 +33,14 @@ test_that("spatial polygons have correct ordering", {
3033
polys2_sp <- sp::SpatialPolygons(polys2)
3134
fake_sp2 <- sp::SpatialPolygonsDataFrame(polys2_sp, fake_data)
3235
lifecycle::expect_deprecated(
33-
expected <- fortify(fake_sp2)
36+
# supressing: Regions defined for each Polygons
37+
expected <- suppressMessages(fortify(fake_sp2))
3438
)
3539
expected <- expected[order(expected$id, expected$order), ]
3640

3741
lifecycle::expect_deprecated(
38-
actual <- fortify(fake_sp)
42+
# supressing: Regions defined for each Polygons
43+
actual <- suppressMessages(fortify(fake_sp))
3944
)
4045

4146
# the levels are different, so these columns need to be converted to character to compare

tests/testthat/test-function-args.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ test_that("stat_xxx and StatXxx$compute_panel arg defaults match", {
5050
stat_fun_names,
5151
c("stat_function", "stat_sf")
5252
)
53-
# Remove stat_spoke as it has been deprecated
54-
stat_fun_names <- setdiff(stat_fun_names, "stat_spoke")
53+
# Remove deprecated stats
54+
stat_fun_names <- setdiff(stat_fun_names, c("stat_spoke", "stat_summary2d"))
5555

5656
# For each stat_xxx function and the corresponding StatXxx$compute_panel and
5757
# StatXxx$compute_group functions, make sure that if they have same args, that

tests/testthat/test-geom-dotplot.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ test_that("NA's result in warning from stat_bindot", {
6363

6464
test_that("when binning on y-axis, limits depend on the panel", {
6565
p <- ggplot(mtcars, aes(factor(cyl), mpg)) +
66-
geom_dotplot(binaxis='y')
66+
geom_dotplot(binaxis='y', binwidth = 1/30 * diff(range(mtcars$mpg)))
6767

6868
b1 <- ggplot_build(p + facet_wrap(~am))
6969
b2 <- ggplot_build(p + facet_wrap(~am, scales = "free_y"))
@@ -77,10 +77,10 @@ test_that("when binning on y-axis, limits depend on the panel", {
7777

7878
test_that("weight aesthetic is checked", {
7979
p <- ggplot(mtcars, aes(x = mpg, weight = gear/3)) +
80-
geom_dotplot()
80+
geom_dotplot(binwidth = 1/30 * diff(range(mtcars$mpg)))
8181
expect_snapshot_warning(ggplot_build(p))
8282
p <- ggplot(mtcars, aes(x = mpg, weight = -gear)) +
83-
geom_dotplot()
83+
geom_dotplot(binwidth = 1/30 * diff(range(mtcars$mpg)))
8484
expect_snapshot_warning(ggplot_build(p))
8585
})
8686

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ test_that("check h/v/abline transformed on basic projections", {
99
geom_vline(xintercept = 3, colour = "red") +
1010
geom_hline(yintercept = 3, colour = "blue") +
1111
geom_abline(intercept = 0, slope = 1, colour = "purple") +
12-
labs(x = NULL, y = NULL) +
13-
coord_cartesian(expand = FALSE)
12+
labs(x = NULL, y = NULL)
1413

1514
expect_doppelganger(
1615
"cartesian lines intersect mid-bars",
17-
plot
16+
plot + coord_cartesian(expand = FALSE)
1817
)
1918
expect_doppelganger(
2019
"flipped lines intersect mid-bars",
@@ -34,11 +33,10 @@ test_that("curved lines in map projections", {
3433
nzmap <- ggplot(nz, aes(long, lat, group = group)) +
3534
geom_path() +
3635
geom_hline(yintercept = -38.6) + # roughly Taupo
37-
geom_vline(xintercept = 176) +
38-
coord_map()
36+
geom_vline(xintercept = 176)
3937

4038
expect_doppelganger("straight lines in mercator",
41-
nzmap
39+
nzmap + coord_map()
4240
)
4341
expect_doppelganger("lines curved in azequalarea",
4442
nzmap + coord_map(projection = 'azequalarea', orientation = c(-36.92, 174.6, 0))

tests/testthat/test-geom-quantile.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test_that("geom_quantile matches quantile regression", {
1313
y = x^2 + 0.5 * rnorm(10)
1414
)
1515

16-
ps <- ggplot(df, aes(x, y)) + geom_quantile()
16+
ps <- ggplot(df, aes(x, y)) + geom_quantile(formula = y ~ x)
1717

1818
quants <- c(0.25, 0.5, 0.75)
1919

tests/testthat/test-geom-smooth.R

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ test_that("data is ordered by x", {
88
})
99

1010
test_that("geom_smooth works in both directions", {
11-
p <- ggplot(mpg, aes(displ, hwy)) + geom_smooth()
11+
p <- ggplot(mpg, aes(displ, hwy)) +
12+
geom_smooth(method = 'loess', formula = y ~ x)
1213
x <- layer_data(p)
1314
expect_false(x$flipped_aes[1])
1415

15-
p <- ggplot(mpg, aes(hwy, displ)) + geom_smooth(orientation = "y")
16+
p <- ggplot(mpg, aes(hwy, displ)) +
17+
geom_smooth(orientation = "y", method = 'loess', formula = y ~ x)
1618
y <- layer_data(p)
1719
expect_true(y$flipped_aes[1])
1820

@@ -103,11 +105,11 @@ test_that("geom_smooth() works with alternative stats", {
103105

104106
expect_doppelganger("ribbon turned on in geom_smooth", {
105107
ggplot(df, aes(x, y, color = fill, fill = fill)) +
106-
geom_smooth(stat = "summary") # ribbon on by default
108+
geom_smooth(stat = "summary", fun.data = mean_se) # ribbon on by default
107109
})
108110

109111
expect_doppelganger("ribbon turned off in geom_smooth", {
110112
ggplot(df, aes(x, y, color = fill, fill = fill)) +
111-
geom_smooth(stat = "summary", se = FALSE) # ribbon is turned off via `se = FALSE`
113+
geom_smooth(stat = "summary", se = FALSE, fun.data = mean_se) # ribbon is turned off via `se = FALSE`
112114
})
113115
})

tests/testthat/test-layer.R

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@ test_that("unknown aesthetics create warning", {
2626
})
2727

2828
test_that("invalid aesthetics throws errors", {
29-
p <- ggplot(mtcars) + geom_point(aes(disp, mpg, fill = data))
30-
expect_snapshot_error(ggplot_build(p))
31-
p <- ggplot(mtcars) + geom_point(aes(disp, mpg, fill = after_stat(data)))
32-
expect_snapshot_error(ggplot_build(p))
29+
# We want to test error and ignore the scale search message
30+
suppressMessages({
31+
p <- ggplot(mtcars) + geom_point(aes(disp, mpg, fill = data))
32+
expect_snapshot_error(ggplot_build(p))
33+
p <- ggplot(mtcars) + geom_point(aes(disp, mpg, fill = after_stat(data)))
34+
expect_snapshot_error(ggplot_build(p))
35+
})
3336
})
3437

3538
test_that("unknown NULL aesthetic doesn't create warning (#1909)", {
@@ -57,8 +60,12 @@ test_that("missing aesthetics trigger informative error", {
5760

5861
test_that("function aesthetics are wrapped with after_stat()", {
5962
df <- data_frame(x = 1:10)
60-
expect_snapshot_error(
61-
ggplot_build(ggplot(df, aes(colour = density, fill = density)) + geom_point())
63+
suppressMessages(
64+
expect_snapshot_error(
65+
ggplot_build(
66+
ggplot(df, aes(colour = density, fill = density)) + geom_point()
67+
)
68+
)
6269
)
6370
})
6471

tests/testthat/test-stat-bin.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ test_that("stat_bin throws error when wrong combination of aesthetic is present"
99
})
1010

1111
test_that("stat_bin works in both directions", {
12-
p <- ggplot(mpg, aes(hwy)) + stat_bin()
12+
p <- ggplot(mpg, aes(hwy)) + stat_bin(bins = 30)
1313
x <- layer_data(p)
1414
expect_false(x$flipped_aes[1])
1515

16-
p <- ggplot(mpg, aes(y = hwy)) + stat_bin()
16+
p <- ggplot(mpg, aes(y = hwy)) + stat_bin(bins = 30)
1717
y <- layer_data(p)
1818
expect_true(y$flipped_aes[1])
1919

@@ -81,7 +81,7 @@ test_that("breaks are transformed by the scale", {
8181

8282
test_that("geom_histogram() can be drawn over a 0-width range (#3043)", {
8383
df <- data_frame(x = rep(1, 100))
84-
out <- layer_data(ggplot(df, aes(x)) + geom_histogram())
84+
out <- layer_data(ggplot(df, aes(x)) + geom_histogram(bins = 30))
8585

8686
expect_equal(nrow(out), 1)
8787
expect_equal(out$xmin, 0.95)

tests/testthat/test-utilities-checks.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
test_that("check_device checks R versions correctly", {
33

44
# Most widely supported device
5-
withr::local_pdf()
5+
file <- withr::local_tempfile(fileext = ".pdf")
6+
withr::local_pdf(file)
67

78
# R 4.0.0 doesn't support any new features
89
with_mocked_bindings(
@@ -45,7 +46,8 @@ test_that("check_device finds device capabilities", {
4546
getRversion() < "4.2.0",
4647
"R version < 4.2.0 does doesn't have proper `dev.capabilities()`."
4748
)
48-
withr::local_pdf()
49+
file <- withr::local_tempfile(fileext = ".pdf")
50+
withr::local_pdf(file)
4951
with_mocked_bindings(
5052
dev.capabilities = function() list(clippingPaths = TRUE),
5153
expect_true(check_device("clippingPaths")),

0 commit comments

Comments
 (0)