Skip to content

Commit f6e2b5c

Browse files
committed
Skip plotly cloud API tests on everything but Windows r-release
1 parent d683852 commit f6e2b5c

File tree

4 files changed

+45
-35
lines changed

4 files changed

+45
-35
lines changed

.github/workflows/R-CMD-check.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ jobs:
9191
_R_CHECK_CRAN_INCOMING_: false
9292
run: |
9393
options(crayon.enabled = TRUE)
94-
Sys.setenv('plotly_username' = 'cpsievert')
9594
rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
9695
shell: Rscript {0}
9796

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ Suggests:
7474
processx,
7575
plotlyGeoAssets,
7676
forcats,
77-
palmerpenguins
77+
palmerpenguins,
78+
rversions
7879
LazyData: true
7980
RoxygenNote: 7.1.1
8081
Encoding: UTF-8

tests/testthat/test-api.R

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
1+
r_version <- paste(R.version$major, R.version$minor, sep = ".")
2+
r_release <- rversions::r_release()$version
3+
is_release <- isTRUE(r_release == r_version)
4+
is_win <- .Platform$OS.type == "windows"
15

2-
test_that("api() returns endpoints", {
6+
skip_cloud_tests <- function() {
37
skip_on_cran()
4-
skip_if_not_master()
8+
if (is.na(Sys.getenv("plotly_username", NA))) {
9+
skip("Cloud testing requires a plotly account (plotly_username)")
10+
}
11+
if (is.na(Sys.getenv("plotly_api_key", NA))) {
12+
skip("Cloud testing requires a plotly account (plotly_api_key)")
13+
}
14+
if (!is_release || !is_win) {
15+
skip("Cloud testing is only run on Windows with the current release of R")
16+
}
17+
}
18+
19+
20+
test_that("api() returns endpoints", {
21+
skip_cloud_tests()
522

623
res <- api()
724
expect_true(length(res) > 1)
825
expect_true(all(c("plots", "grids", "folders") %in% names(res)))
926
})
1027

1128
test_that("Can search with white-space", {
12-
skip_on_cran()
13-
skip_if_not_master()
29+
skip_cloud_tests()
1430

1531
res <- api("search?q=overdose drugs")
1632
expect_true(length(res) > 1)
@@ -27,8 +43,7 @@ test_that("Changing a filename works", {
2743

2844

2945
test_that("Downloading plots works", {
30-
skip_on_cran()
31-
skip_if_not_master()
46+
skip_cloud_tests()
3247

3348
# https://plot.ly/~cpsievert/200
3449
p <- api_download_plot(200, "cpsievert")
@@ -46,8 +61,7 @@ test_that("Downloading plots works", {
4661

4762

4863
test_that("Downloading grids works", {
49-
skip_on_cran()
50-
skip_if_not_master()
64+
skip_cloud_tests()
5165

5266
g <- api_download_grid(14681, "cpsievert")
5367
expect_is(g, "api_file")
@@ -63,8 +77,7 @@ test_that("Downloading grids works", {
6377

6478

6579
test_that("Creating produces a new file by default", {
66-
skip_on_cran()
67-
skip_if_not_master()
80+
skip_cloud_tests()
6881

6982
expect_new <- function(obj) {
7083
old <- api("folders/home?user=cpsievert")
@@ -87,8 +100,7 @@ test_that("Creating produces a new file by default", {
87100

88101

89102
test_that("Can overwrite a grid", {
90-
skip_on_cran()
91-
skip_if_not_master()
103+
skip_cloud_tests()
92104

93105
id <- new_id()
94106
m <- api_create(mtcars, id)
@@ -98,8 +110,7 @@ test_that("Can overwrite a grid", {
98110
})
99111

100112
test_that("Can overwrite a plot", {
101-
skip_on_cran()
102-
skip_if_not_master()
113+
skip_cloud_tests()
103114

104115
id <- new_id()
105116
p <- plot_ly()
@@ -110,8 +121,7 @@ test_that("Can overwrite a plot", {
110121
})
111122

112123
test_that("Can create plots with non-trivial src attributes", {
113-
skip_on_cran()
114-
skip_if_not_master()
124+
skip_cloud_tests()
115125

116126
expect_srcified <- function(x) {
117127
expect_length(strsplit(x, ":")[[1]], 3)
@@ -147,3 +157,20 @@ test_that("Can create plots with non-trivial src attributes", {
147157
expect_not_srcified(res$figure$layout$xaxis$tickvalssrc)
148158

149159
})
160+
161+
162+
test_that("filename supports names with paths included ", {
163+
skip_cloud_tests()
164+
165+
p <- plot_ly(mtcars, x = ~wt, y = ~vs)
166+
filename <- "directory/awesome"
167+
# trash the file if it already exists
168+
file <- api_lookup_file(filename)
169+
if (is.file(file)) {
170+
endpt <- sprintf("files/%s/trash", file$fid)
171+
res <- api(endpt, "POST")
172+
}
173+
f <- api_create(p, filename = filename)
174+
expect_match(f$filename, "awesome")
175+
expect_true(f$parented)
176+
})

tests/testthat/test-plotly-filename.R

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)