Skip to content

Commit

Permalink
[misc] skip if not online function
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMarvin committed Aug 31, 2024
1 parent 4eec0a0 commit b241c10
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
14 changes: 14 additions & 0 deletions tests/testthat/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -1043,3 +1043,17 @@ testsetup <- function() {
}

}

skip_if_not_online <- function(url = "https://r-project.org") {
skip_on_cran()

Check warning on line 1048 in tests/testthat/helper.R

View workflow job for this annotation

GitHub Actions / lint

file=tests/testthat/helper.R,line=1048,col=3,[object_usage_linter] no visible global function definition for 'skip_on_cran'
res <- tryCatch(
{
con <- url(url) # Try to open a connection to Google
open(con) # Open the connection
close(con) # Close the connection
TRUE # If successful, return TRUE
},
error = function(e) FALSE # On error, return FALSE
)
skip_if_not(res, "offline")

Check warning on line 1058 in tests/testthat/helper.R

View workflow job for this annotation

GitHub Actions / lint

file=tests/testthat/helper.R,line=1058,col=3,[object_usage_linter] no visible global function definition for 'skip_if_not'
}
8 changes: 4 additions & 4 deletions tests/testthat/test-read_sources.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
test_that("read_xlsx from different sources", {

skip_if_offline()
skip_if_not_online()

## URL
xlsxFile <- "https://github.com/JanMarvin/openxlsx2/raw/main/inst/extdata/oxlsx2_sheet.xlsx"
Expand All @@ -26,7 +26,7 @@ test_that("read_xlsx from different sources", {

test_that("wb_load from different sources", {

skip_if_offline()
skip_if_not_online()

## URL
xlsxFile <- "https://github.com/JanMarvin/openxlsx2/raw/main/inst/extdata/oxlsx2_sheet.xlsx"
Expand Down Expand Up @@ -194,7 +194,7 @@ test_that("reading charts", {

test_that("load file with xml namespace", {

skip_if_offline()
skip_if_not_online()

fl <- "https://github.com/ycphs/openxlsx/files/8480120/2022-04-12-11-42-36-DP_Melanges1.xlsx"

Expand Down Expand Up @@ -305,7 +305,7 @@ test_that("reading of formControl works", {

test_that("reading xml escapes works", {

skip_if_offline()
skip_if_not_online()

fl <- "https://github.com/ycphs/openxlsx/files/10032200/sample_data.xlsx"
wb <- wb_load(fl)
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-read_xlsb.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
test_that("reading xlsb works", {

skip_if_offline()
skip_if_not_online()

xlsxFile <- testfile_path("openxlsx2_example.xlsb")

Expand All @@ -21,7 +21,7 @@ test_that("reading xlsb works", {

test_that("reading complex xlsb works", {

skip_if_offline()
skip_if_not_online()

xlsxFile <- testfile_path("hyperlink.xlsb")

Expand Down Expand Up @@ -65,7 +65,7 @@ test_that("reading complex xlsb works", {

test_that("worksheets with real world formulas", {

skip_if_offline()
skip_if_not_online()

xlsxFile <- testfile_path("nhs-core-standards-for-eprr-v6.1.xlsb")

Expand Down

0 comments on commit b241c10

Please sign in to comment.