Skip to content

Commit b46db93

Browse files
committed
skip mapbox tests if no token exists
1 parent 61b5095 commit b46db93

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

tests/testthat/test-plotly-sf.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ context("add_sf")
33
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
44
storms <- sf::st_read(system.file("shape/storms_xyz.shp", package = "sf"), quiet = TRUE)
55

6+
has_mapbox <- function() {
7+
!is.null(tryNULL(mapbox_token()))
8+
}
9+
610
test_that("add_sf() is optional", {
711
skip_if_not_installed("sf")
812

@@ -44,6 +48,7 @@ test_that("plot_geo() lat/lon range is set", {
4448

4549
test_that("plot_mapbox() fitbounds is set", {
4650
skip_if_not_installed("sf")
51+
skip_if_not(has_mapbox())
4752

4853
p <- plotly_build(plot_mapbox(nc))
4954
expect_equal(
@@ -56,6 +61,7 @@ test_that("plot_mapbox() fitbounds is set", {
5661

5762
test_that("sf defaults can be overriden", {
5863
skip_if_not_installed("sf")
64+
skip_if_not(has_mapbox())
5965

6066
# when applied to fillcolor, alpha defaults to 0.5
6167
p <- plotly_build(plot_mapbox(nc, color = I("red")))
@@ -115,6 +121,7 @@ test_that("plot_ly() defaults to blank axes", {
115121

116122
test_that("discrete color informs fillcolor", {
117123
skip_if_not_installed("sf")
124+
skip_if_not(has_mapbox())
118125

119126
res <- unique(res_mn$INDRESNAME)
120127
cols <- viridisLite::magma(length(res))
@@ -136,6 +143,7 @@ test_that("discrete color informs fillcolor", {
136143

137144
test_that("discrete color informs fillcolor", {
138145
skip_if_not_installed("sf")
146+
skip_if_not(has_mapbox())
139147

140148
res <- unique(res_mn$INDRESNAME)
141149
cols <- viridisLite::magma(length(res))
@@ -171,6 +179,7 @@ test_that("discrete color informs fillcolor", {
171179

172180
test_that("numeric color informs fillcolor", {
173181
skip_if_not_installed("sf")
182+
skip_if_not(has_mapbox())
174183

175184
p <- plot_mapbox(res_mn, color = ~AREA)
176185
expect_warning(plotly_build(p), "Only one fillcolor per trace allowed")
@@ -214,6 +223,7 @@ test_that("numeric color informs fillcolor", {
214223

215224
test_that("sizing constants", {
216225
skip_if_not_installed("sf")
226+
skip_if_not(has_mapbox())
217227

218228
# span controls 'stroke-size'
219229
p <- plot_mapbox(res_mn, span = I(5)) %>% plotly_build()
@@ -259,6 +269,7 @@ test_that("sizing constants", {
259269

260270
test_that("size mappings", {
261271
skip_if_not_installed("sf")
272+
skip_if_not(has_mapbox())
262273

263274
expect_warning(
264275
plotly_build(plot_mapbox(res_mn, span = ~PERIMETER)),
@@ -294,6 +305,7 @@ test_that("size mappings", {
294305

295306
test_that("altogether now", {
296307
skip_if_not_installed("sf")
308+
skip_if_not(has_mapbox())
297309

298310
s <- subplot(plot_ly(nc), plot_geo(nc), plot_mapbox(nc), nrows = 3) %>% plotly_build()
299311
d <- s$x$data
@@ -328,6 +340,7 @@ test_that("altogether now", {
328340

329341
test_that("color and stroke scales can be set independently", {
330342
skip_if_not_installed("sf")
343+
skip_if_not(has_mapbox())
331344

332345
n <- length(unique(res_mn$INDRESNAME))
333346
p <- plot_mapbox(res_mn, split = ~INDRESNAME, color = ~AREA, stroke = ~PERIMETER, span = I(2)) %>%

0 commit comments

Comments
 (0)