Skip to content

Commit

Permalink
Skip tests if offline (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikemahoney218 authored Jan 18, 2024
1 parent 9260010 commit fc2b981
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/testthat/test-spectral_indices.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ test_that("spectral_indices_url() respects environment variables", {
})

test_that("no cache", {
skip_if_offline()
indices_path <- file.path(tools::R_user_dir("rsi"), "indices.rda")
if (file.exists(indices_path)) file.remove(indices_path)
expect_no_warning(spectral_indices())
Expand All @@ -71,101 +72,118 @@ test_that("no cache, download and update false", {
})

test_that("no cache, update true", {
skip_if_offline()
indices_path <- file.path(tools::R_user_dir("rsi"), "indices.rda")
if (file.exists(indices_path)) file.remove(indices_path)
expect_no_warning(spectral_indices(update_cache = TRUE))
})

test_that("no cache, download true", {
skip_if_offline()
indices_path <- file.path(tools::R_user_dir("rsi"), "indices.rda")
if (file.exists(indices_path)) file.remove(indices_path)
expect_no_warning(spectral_indices(download_indices = TRUE))
})

test_that("no cache, download and update true", {
skip_if_offline()
indices_path <- file.path(tools::R_user_dir("rsi"), "indices.rda")
if (file.exists(indices_path)) file.remove(indices_path)
expect_no_warning(spectral_indices(download_indices = TRUE, update_cache = TRUE))
})

test_that("new cache", {
skip_if_offline()
invisible(spectral_indices(update_cache = TRUE))
expect_no_warning(spectral_indices())
})

test_that("new cache, update false", {
skip_if_offline()
invisible(spectral_indices(update_cache = TRUE))
expect_no_warning(spectral_indices(update_cache = FALSE))
})

test_that("new cache, download false", {
skip_if_offline()
invisible(spectral_indices(update_cache = TRUE))
expect_no_warning(spectral_indices(download_indices = FALSE))
})

test_that("new cache, download and update false", {
skip_if_offline()
invisible(spectral_indices(update_cache = TRUE))
expect_no_warning(spectral_indices(download_indices = FALSE, update_cache = FALSE))
})

test_that("new cache, update true", {
skip_if_offline()
invisible(spectral_indices(update_cache = TRUE))
expect_no_warning(spectral_indices(update_cache = TRUE))
})

test_that("new cache, download true", {
skip_if_offline()
invisible(spectral_indices(update_cache = TRUE))
expect_no_warning(spectral_indices(download_indices = TRUE))
})

test_that("new cache, download and update true", {
skip_if_offline()
invisible(spectral_indices(update_cache = TRUE))
expect_no_warning(spectral_indices(download_indices = TRUE, update_cache = TRUE))
})

test_that("old cache", {
skip_if_offline()
indices_path <- file.path(tools::R_user_dir("rsi"), "indices.rda")
invisible(spectral_indices(update_cache = TRUE))
Sys.setFileTime(indices_path, "1970-01-01")
expect_no_warning(spectral_indices())
})

test_that("old cache, update false", {
skip_if_offline()
indices_path <- file.path(tools::R_user_dir("rsi"), "indices.rda")
invisible(spectral_indices(update_cache = TRUE))
Sys.setFileTime(indices_path, "1970-01-01")
expect_no_warning(spectral_indices(update_cache = FALSE))
})

test_that("old cache, download false", {
skip_if_offline()
indices_path <- file.path(tools::R_user_dir("rsi"), "indices.rda")
invisible(spectral_indices(update_cache = TRUE))
Sys.setFileTime(indices_path, "1970-01-01")
expect_no_warning(spectral_indices(download_indices = FALSE))
})

test_that("old cache, download and update false", {
skip_if_offline()
indices_path <- file.path(tools::R_user_dir("rsi"), "indices.rda")
invisible(spectral_indices(update_cache = TRUE))
Sys.setFileTime(indices_path, "1970-01-01")
expect_no_warning(spectral_indices(download_indices = FALSE, update_cache = FALSE))
})

test_that("old cache, update true", {
skip_if_offline()
indices_path <- file.path(tools::R_user_dir("rsi"), "indices.rda")
invisible(spectral_indices(update_cache = TRUE))
Sys.setFileTime(indices_path, "1970-01-01")
expect_no_warning(spectral_indices(update_cache = TRUE))
})

test_that("old cache, download true", {
skip_if_offline()
indices_path <- file.path(tools::R_user_dir("rsi"), "indices.rda")
invisible(spectral_indices(update_cache = TRUE))
Sys.setFileTime(indices_path, "1970-01-01")
expect_no_warning(spectral_indices(download_indices = TRUE))
})

test_that("old cache, download and update true", {
skip_if_offline()
indices_path <- file.path(tools::R_user_dir("rsi"), "indices.rda")
invisible(spectral_indices(update_cache = TRUE))
Sys.setFileTime(indices_path, "1970-01-01")
Expand Down

0 comments on commit fc2b981

Please sign in to comment.