From d2cd4bc7d6b2785bb3c1b5b9104ed37670857d4e Mon Sep 17 00:00:00 2001 From: Julia Silge Date: Thu, 3 Oct 2024 17:00:35 -0600 Subject: [PATCH] Remove and update legacy tests --- tests/testthat/_snaps/legacy_board.md | 9 ++ tests/testthat/_snaps/legacy_local.md | 4 - tests/testthat/_snaps/pin.md | 25 ------ tests/testthat/_snaps/pin_info.md | 3 + tests/testthat/test-legacy_azure.R | 37 -------- tests/testthat/test-legacy_datatxt.R | 51 ----------- tests/testthat/test-legacy_gcloud.R | 25 ------ tests/testthat/test-legacy_github.R | 33 ------- tests/testthat/test-legacy_local.R | 45 ---------- tests/testthat/test-legacy_packages.R | 3 + tests/testthat/test-legacy_s3.R | 37 -------- tests/testthat/test-pin.R | 123 -------------------------- tests/testthat/test-pin_versions.R | 1 + 13 files changed, 16 insertions(+), 380 deletions(-) delete mode 100644 tests/testthat/_snaps/legacy_local.md delete mode 100644 tests/testthat/_snaps/pin.md delete mode 100644 tests/testthat/test-legacy_azure.R delete mode 100644 tests/testthat/test-legacy_datatxt.R delete mode 100644 tests/testthat/test-legacy_gcloud.R delete mode 100644 tests/testthat/test-legacy_github.R delete mode 100644 tests/testthat/test-legacy_local.R delete mode 100644 tests/testthat/test-legacy_s3.R delete mode 100644 tests/testthat/test-pin.R diff --git a/tests/testthat/_snaps/legacy_board.md b/tests/testthat/_snaps/legacy_board.md index edcf34afb..6d87cf572 100644 --- a/tests/testthat/_snaps/legacy_board.md +++ b/tests/testthat/_snaps/legacy_board.md @@ -4,16 +4,25 @@ board <- board_temp() pin(mtcars, "mtcars", board = board) Condition + Warning: + `pin()` was deprecated in pins 1.4.0. + i Please use `pin_write()` instead. Error in `board_pin_create()`: ! Use `pin_write()` with this board, not `pin()` Code pin_get("mtcars", board = board) Condition + Warning: + `pin_get()` was deprecated in pins 1.4.0. + i Please use `pin_read()` instead. Error in `board_pin_get()`: ! Use `pin_read()` with this board, not `pin_get()` Code pin_find("mtcars", board = board) Condition + Warning: + `pin_find()` was deprecated in pins 1.4.0. + i Please use `pin_search()` instead. Error in `board_pin_find()`: ! Use `pin_search()` with this board, not `pin_find()` Code diff --git a/tests/testthat/_snaps/legacy_local.md b/tests/testthat/_snaps/legacy_local.md deleted file mode 100644 index 8e6bf9d05..000000000 --- a/tests/testthat/_snaps/legacy_local.md +++ /dev/null @@ -1,4 +0,0 @@ -# can version a local pin - - Version 'doesnt-exist' is not valid, please select from pin_versions(). - diff --git a/tests/testthat/_snaps/pin.md b/tests/testthat/_snaps/pin.md deleted file mode 100644 index 22d4fc6f4..000000000 --- a/tests/testthat/_snaps/pin.md +++ /dev/null @@ -1,25 +0,0 @@ -# unavailable url can use cache - - Code - pin(url, "test", board = board) - Condition - Error in `pin()`: - ! Client error: (404) Not Found. Failed to download remote file: http://127.0.0.1:/status/404 - Code - pin(1:10, "test", board = board) - x <- pin(url, "test", board = board) - Condition - Warning: - Failed to re-download pin; using cached value - * Client error: (404) Not Found. Failed to download remote file: http://127.0.0.1:/status/404 - Code - expect_equal(x, 1:10) - -# can pin() with custom metadata - - Code - pin(iris, "iris2", board = board, custom_metadata = meta) - Condition - Warning: - `custom_metadata` is deprecated; please use `metadata` instead - diff --git a/tests/testthat/_snaps/pin_info.md b/tests/testthat/_snaps/pin_info.md index cc5e3c3c3..01533aac9 100644 --- a/tests/testthat/_snaps/pin_info.md +++ b/tests/testthat/_snaps/pin_info.md @@ -48,6 +48,9 @@ board <- board_temp() pin_info("mtcars", board = board) Condition + Warning: + `pin_info()` was deprecated in pins 1.4.0. + i Please use `pin_meta()` instead. Error in `pin_info()`: ! Use `pin_meta()` with this board, not `pin_info()` diff --git a/tests/testthat/test-legacy_azure.R b/tests/testthat/test-legacy_azure.R deleted file mode 100644 index 0142ac95f..000000000 --- a/tests/testthat/test-legacy_azure.R +++ /dev/null @@ -1,37 +0,0 @@ -skip_if_not_installed("mime") -skip_if_not_installed("openssl") - -test_that("board contains proper azure headers", { - mock_board <- list(key = jsonlite::base64_enc(as.raw(1:3)), url = "https://foo.com") - headers <- names(azure_headers(mock_board, "PUT", "x", "files/hello.txt")$headers) - - expect_true("x-ms-date" %in% headers) - expect_true("x-ms-version" %in% headers) - expect_true("x-ms-blob-type" %in% headers) - expect_true("Authorization" %in% headers) -}) - -# Live API --------------------------------------------------------------------- - -skip_if_missing_envvars( - tests = "legacy_azure()", - envvars = c("TEST_AZURE_CONTAINER", "TEST_AZURE_ACCOUNT", "TEST_AZURE_KEY") -) - -board <- legacy_azure( - container = Sys.getenv("TEST_AZURE_CONTAINER"), - account = Sys.getenv("TEST_AZURE_ACCOUNT"), - key = Sys.getenv("TEST_AZURE_KEY"), - cache = tempfile() -) -board_test(board, suite = "default") - -board <- legacy_azure( - name = "test-azure-2", - container = Sys.getenv("TEST_AZURE_CONTAINER"), - account = Sys.getenv("TEST_AZURE_ACCOUNT"), - key = Sys.getenv("TEST_AZURE_KEY"), - versions = TRUE, - cache = tempfile() -) -board_test(board, suite = "versions") diff --git a/tests/testthat/test-legacy_datatxt.R b/tests/testthat/test-legacy_datatxt.R deleted file mode 100644 index ba3b0b7b9..000000000 --- a/tests/testthat/test-legacy_datatxt.R +++ /dev/null @@ -1,51 +0,0 @@ -skip_if_not_installed("filelock") - -test_that("can board_register() a data.txt board", { - skip_on_cran() - - board_register_datatxt( - name = "simpletxt", - url = "https://raw.githubusercontent.com/rstudio/pins-r/master/tests/testthat/datatxt/data.txt", - cache = tempfile() - ) - - expect_true("simpletxt" %in% board_list()) -}) - -test_that("can pin_get() iris from a data.txt board", { - skip_on_cran() - - b <- local_legacy_datatxt() - iris <- pin_get("iris", board = b) - - expect_equal(dim(iris), c(150, 5)) -}) - -test_that("doen't evaluate expressions in data.txt", { - skip_on_cran() - - b <- local_legacy_datatxt() - json <- pin_find("mtcars_expr", board = b, metadata = TRUE)$metadata - meta <- jsonlite::fromJSON(json) - - expect_equal(meta$rows, "30+2") -}) - -test_that("can board_register() with URL", { - skip_on_cran() - - board_name <- board_register( - "https://raw.githubusercontent.com/rstudio/pins-r/master/tests/testthat/datatxt/data.txt", - name = "simpletxt", - cache = tempfile() - ) - withr::defer(board_deregister("simpletxt")) - expect_equal(board_name, "simpletxt") - - board_name <- board_register( - "https://raw.githubusercontent.com/rstudio/pins-r/master/tests/testthat/datatxt/data.txt", - cache = tempfile() - ) - withr::defer(board_deregister("raw")) - expect_equal(board_name, "raw") -}) diff --git a/tests/testthat/test-legacy_gcloud.R b/tests/testthat/test-legacy_gcloud.R deleted file mode 100644 index 98e534ec4..000000000 --- a/tests/testthat/test-legacy_gcloud.R +++ /dev/null @@ -1,25 +0,0 @@ -skip_if_not_installed("mime") - -test_that("board contains proper gcloud headers", { - headers <- names(gcloud_headers(list(token = "abc"), "PUT", "x", "files/hello.txt")$headers) - - expect_true("Content-Type" %in% headers) - expect_true("Authorization" %in% headers) -}) - -# Live API --------------------------------------------------------------------- - -skip_if_missing_envvars("legacy_gcloud()", "TEST_GOOGLE_BUCKET") - -board <- legacy_gcloud( - bucket = Sys.getenv("TEST_GOOGLE_BUCKET"), - cache = tempfile() -) -board_test(board, suite = "default") - -board <- legacy_gcloud( - bucket = Sys.getenv("TEST_GOOGLE_BUCKET"), - versions = TRUE, - cache = tempfile() -) -board_test(board, suite = "versions") diff --git a/tests/testthat/test-legacy_github.R b/tests/testthat/test-legacy_github.R deleted file mode 100644 index e858830b6..000000000 --- a/tests/testthat/test-legacy_github.R +++ /dev/null @@ -1,33 +0,0 @@ -skip_if_missing_envvars( - tests = "legacy_github()", - envvars = c("TEST_GITHUB_REPO", "TEST_GITHUB_BRANCH") -) - -board <- legacy_github( - repo = Sys.getenv("TEST_GITHUB_REPO"), - branch = Sys.getenv("TEST_GITHUB_BRANCH"), - cache = tempfile() -) - -board_test(board, suite = "default") -board_test(board, suite = "versions") - -test_that("can pin large resources in github releases", { - pin(iris, "iris_large", board = board, release_storage = TRUE) - - retrieved <- pin_get("iris_large", board = board) - - expect_true(is.data.frame(retrieved)) - - pin_remove("iris_large", board = board) - - expect_true(!"iris_large" %in% pin_find(board = board)$name) -}) - -test_that("uninitialized repo returns empty results", { - skip_if_missing_envvars("legacy_github()", "GITHUB_PAT") - - board <- legacy_github("rstudio/sparklyr", cache = tempfile()) - total <- nrow(pin_find("", board = board)) - expect_equal(total, 0) -}) diff --git a/tests/testthat/test-legacy_local.R b/tests/testthat/test-legacy_local.R deleted file mode 100644 index 96a06b0bf..000000000 --- a/tests/testthat/test-legacy_local.R +++ /dev/null @@ -1,45 +0,0 @@ -skip_if_not_installed("filelock") - -board_test(legacy_temp(), suite = "default") -board_test(legacy_temp(versions = TRUE), suite = "versions") - -test_that("local board registered by default", { - expect_true("local" %in% board_list()) -}) - -test_that(paste("can add and delete pin"), { - b <- legacy_temp() - expect_equal(pin_list(b), character()) - - hello <- test_path("files/hello.txt") - path <- pin(hello, board = b) - expect_equal(pin_list(b), "hello") - - expect_true(file.exists(path)) - expect_equal(readLines(path), "hello world") - - pin_remove("hello", b) - expect_equal(pin_list(b), character()) -}) - -test_that("can version a local pin", { - b <- legacy_temp(versions = TRUE) - - versions <- pin_versions("df", b) - expect_equal(versions, data.frame()) - - pin(data.frame(x = 1), "df", board = b) - pin(data.frame(x = 2), "df", board = b) - pin(data.frame(x = 3), "df", board = b) - - versions <- pin_versions("df", b) - expect_equal(nrow(versions), 3) - - newest <- pin_get("df", version = versions$version[[1]], board = b) - oldest <- pin_get("df", version = versions$version[[3]], board = b) - expect_equal(newest$x, 3) - expect_equal(oldest$x, 1) - - expect_snapshot_error(pin_get("df", version = "doesnt-exist", board = b)) -}) - diff --git a/tests/testthat/test-legacy_packages.R b/tests/testthat/test-legacy_packages.R index f805a9bce..c14cd67d5 100644 --- a/tests/testthat/test-legacy_packages.R +++ b/tests/testthat/test-legacy_packages.R @@ -1,4 +1,5 @@ test_that("can pin_find() package data", { + withr::local_options(lifecycle_verbosity = "quiet") board <- board_packages() results <- pin_find(board = board) @@ -12,12 +13,14 @@ test_that("can pin_find() package data", { }) test_that("can retrieve data from a package", { + withr::local_options(lifecycle_verbosity = "quiet") board <- board_packages() data <- pin_get("datasets/AirPassengers", board = board) expect_equal(data, datasets::AirPassengers) }) test_that("bad pin names give useful errors", { + withr::local_options(lifecycle_verbosity = "quiet") board <- board_packages() expect_snapshot(error = TRUE, { diff --git a/tests/testthat/test-legacy_s3.R b/tests/testthat/test-legacy_s3.R deleted file mode 100644 index 61ce47e45..000000000 --- a/tests/testthat/test-legacy_s3.R +++ /dev/null @@ -1,37 +0,0 @@ -skip_if_not_installed("openssl") - -test_that("board contains proper s3 headers", { - headers <- names(s3_headers(list(), "PUT", "x")$headers) - - expect_true("Host" %in% headers) - expect_true("Date" %in% headers) - expect_true("Content-Type" %in% headers) - expect_true("Authorization" %in% headers) -}) - -# Live API --------------------------------------------------------------------- - -skip_if_missing_envvars( - tests = "legacy_s3()", - envvars = c("TEST_AWS_BUCKET", "TEST_AWS_KEY", "TEST_AWS_SECRET", "TEST_AWS_REGION") -) - -board <- legacy_s3( - bucket = Sys.getenv("TEST_AWS_BUCKET"), - key = Sys.getenv("TEST_AWS_KEY"), - secret = Sys.getenv("TEST_AWS_SECRET"), - cache = tempfile(), - region = Sys.getenv("TEST_AWS_REGION") -) -board_test(board, suite = "default") - -board <- legacy_s3( - name = "test-s3-2", - bucket = Sys.getenv("TEST_AWS_BUCKET"), - key = Sys.getenv("TEST_AWS_KEY"), - secret = Sys.getenv("TEST_AWS_SECRET"), - versions = TRUE, - cache = tempfile(), - region = Sys.getenv("TEST_AWS_REGION") -) -board_test(board, suite = "versions") diff --git a/tests/testthat/test-pin.R b/tests/testthat/test-pin.R deleted file mode 100644 index 9a063efba..000000000 --- a/tests/testthat/test-pin.R +++ /dev/null @@ -1,123 +0,0 @@ -skip_if_not_installed("filelock") -skip_if_not_installed("webfakes") -skip_on_cran() - -httpbin <- local_httpbin_app() -httpbin_port <- httpbin$get_port() -redact_port <- function(snapshot) { - snapshot <- gsub(httpbin_port, "", snapshot, fixed = TRUE) -} - -# main types -------------------------------------------------------------- - -test_that("can pin() a data frame", { - board <- legacy_temp() - - df <- data.frame( - raw = charToRaw("asdas"), - posix = as.POSIXlt(Sys.time(), "EST"), - date = as.Date(35981, origin = "1899-12-30"), - integer = 1L, - numeric = 1, - logical = TRUE, - stringsAsFactors = FALSE - ) - pin(df, "df", board = board) - expect_equal(pin_get("df", board = board), df) -}) - -test_that("can pin() a data.table", { - skip_if_not_installed("data.table") - board <- legacy_temp() - - dt <- data.table::data.table(x = 1:2, y = list("a", "b")) - pin(dt, "dt", board = board) - expect_equal(pin_get("dt", board = board), dt) - - # Check that pin_safe_csv() hasn't mutated original data.table - expect_named(dt, c("x", "y")) -}) - -test_that("can pin an arbitrary object", { - board <- legacy_temp() - - x <- list(1, letters, c(TRUE, FALSE, NA)) - pin(x, "x", board = board) - expect_equal(pin_get("x", board = board), x) -}) - -test_that("AsIs class stripped when using I", { - board <- legacy_temp() - - df <- data.frame(x = 1) - pin(I(df), "df", board = board) - expect_equal(pin_get("df", board = board), df) -}) - -test_that("can pin a file", { - board <- legacy_temp() - - pin(test_path("files/hello.txt"), "hello", board = board) - expect_equal( - pin_get("hello", board = board), - as.character(pin_registry_path(board, "hello", "hello.txt")) - ) -}) - -test_that("can pin() remote CSV with URL and name", { - board <- legacy_temp() - - url <- "https://raw.githubusercontent.com/rstudio/pins-r/master/tests/testthat/datatxt/iris/data.csv" - pin <- pin(url, "iris", board = board) - - expect_equal(dim(read.csv(pin)), c(150, 5)) -}) - -test_that("unavailable url can use cache", { - skip_on_cran() - board <- legacy_temp() - url <- httpbin$url("/status/404") - - expect_snapshot({ - pin(url, "test", board = board) - pin(1:10, "test", board = board) - x <- pin(url, "test", board = board) - expect_equal(x, 1:10) - }, error = TRUE, transform = redact_port) -}) - -# custom metadata ------------------------------------------------------------------- - -test_that("can pin() with custom metadata", { - withr::local_options(lifecycle_verbosity = "quiet") - board <- legacy_temp() - - meta <- list( - source = "The R programming language", - extra_info = list( - list(name = "Species", description = "Really like this column"), - list(name = "Sepal.Length", description = "Sepal Length"), - list(name = "Sepal.Width", description = "Sepal Width"), - list(name = "Petal.Length", description = "Petal Length"), - list(name = "Petal.Width", description = "Petal Width") - ) - ) - pin(iris, "iris", metadata = meta, board = board) - meta2 <- pin_info("iris", board) - expect_equal(meta2[c("source", "extra_info")], meta) - - expect_snapshot(pin(iris, "iris2", board = board, custom_metadata = meta)) - meta2 <- pin_info("iris2", board) - expect_equal(meta2[c("source", "extra_info")], meta) -}) - -# helpers ----------------------------------------------------------------- - -test_that("can sanitize data frame names", { - name <- "___sdf ds32___42342 dsf dsf dsfds____" - expect_equal( - pin_default_name(name, board_temp()), - "sdf-ds32-42342-dsf-dsf-dsfds" - ) -}) - diff --git a/tests/testthat/test-pin_versions.R b/tests/testthat/test-pin_versions.R index 7ceffd533..8939058ec 100644 --- a/tests/testthat/test-pin_versions.R +++ b/tests/testthat/test-pin_versions.R @@ -1,6 +1,7 @@ skip_if_not_installed("filelock") test_that("can use old pin_versions() api", { + withr::local_options(lifecycle_verbosity = "quiet") board <- legacy_local() pin(x = 1:5, "x", board = board) withr::defer(pin_remove("x", board))