Skip to content

Commit

Permalink
[tests] improve testfile_path() to download files (#785)
Browse files Browse the repository at this point in the history
* [tests] improve testfile_path() to download file with testfile_path(). this allows restoring parallel tests

* restore skip_on_ci()
  • Loading branch information
JanMarvin authored Oct 1, 2023
1 parent 304ff1b commit fcb6670
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 66 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ Encoding: UTF-8
RoxygenNote: 7.2.3
Roxygen: list(markdown = TRUE)
Config/testthat/edition: 3
Config/testthat/parallel: false
Config/testthat/parallel: true
Config/testthat/start-first: aaa
76 changes: 18 additions & 58 deletions tests/testthat/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -989,72 +989,32 @@ expected_shared_strings <- function() {
}


#' initiates testfiles in local testthat folder
download_testfiles <- function() {

fls <- c(
"charts.xlsx",
"cloneEmptyWorksheetExample.xlsx",
"cloneWorksheetExample.xlsx",
"ColorTabs3.xlsx",
"connection.xlsx",
"eurosymbol.xlsx",
"fichier_complementaire_ccam_descriptive_a_usage_pmsi_2021_v2.xlsx",
"form_control.xlsx",
"formula.xlsx",
"gh_issue_416.xlsm",
"gh_issue_504.xlsx",
"hyperlink.xlsb",
"inline_str.xlsx",
"inlineStr.xlsx",
"loadExample.xlsx",
"loadPivotTables.xlsx",
"loadThreadComment.xlsx",
"macro2.xlsm",
"mtcars_chart.xlsx",
"namedRegions.xlsx",
"namedRegions2.xlsx",
"nhs-core-standards-for-eprr-v6.1.xlsb",
"openxlsx2_example.xlsb",
"overwrite_formula.xlsx",
"oxlsx2_sheet.xlsx",
"pivot_notes.xlsx",
"readTest.xlsx",
"Single_hyperlink.xlsx",
"tableStyles.xlsx",
"umlauts.xlsx",
"unemployment-nrw202208.xlsx",
"update_test.xlsx",
"vml_numbering.xlsx"
)
#' provides testfile path for testthat
#' @param x a file assumed in testfiles folder
testfile_path <- function(x, replace = FALSE) {

test_path <- testthat::test_path("testfiles")

if (dir.exists(test_path)) {
if (all(file.exists(testthat::test_path("testfiles", fls)))) {
return(TRUE)
}

unlink(test_path, recursive = TRUE)
if (!dir.exists(test_path)) {
dir.create(test_path)
}

dir.create(test_path)
fl <- testthat::test_path("testfiles", x)

# relies on libcurl and was optional in R < 4.2.0 on Windows
out <- paste0(test_path, "/", fls)
url <- paste0("https://github.com/JanMarvin/openxlsx-data/raw/main/", fls)
try({
download.file(url, destfile = out, quiet = TRUE, method = "libcurl")
})
if (Sys.getenv("openxlsx2_testthat_fullrun") == "") {
if (isTRUE(as.logical(Sys.getenv("CI", "false")))) # on_ci()
return(testthat::skip("Skip on CI"))
}

return(TRUE)
}
# try to download
if (!file.exists(fl) || replace) {
out <- paste0(test_path, "/", x)
url <- paste0("https://github.com/JanMarvin/openxlsx-data/raw/main/", x)
try({
download.file(url, destfile = out, quiet = TRUE)
})
}

#' provides testfile path for testthat
#' @param x a file assumed in testfiles folder
testfile_path <- function(x) {
# apparently this runs in a different folder
fl <- testthat::test_path("testfiles", x)
if (!file.exists(fl)) {
return(testthat::skip("Testfile does not exist"))
} else {
Expand Down
12 changes: 6 additions & 6 deletions tests/testthat/test-aaa.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
test_that("testsetup", {

options("openxlsx2.datetimeCreated" = as.POSIXct("2023-07-20 23:32:14"))
options("openxlsx2.datetimeCreated" = as.POSIXct("2023-07-20 23:32:14", tz = "UTC"))

if (Sys.getenv("openxlsx2_testthat_fullrun") == "") {
skip_on_ci()
}
wb <- wb_workbook()

exp <- "2023-07-20T23:32:14Z"
got <- wb$get_properties()[["datetime_created"]]
expect_equal(exp, got)

skip_if_offline()
expect_true(download_testfiles())
})
3 changes: 2 additions & 1 deletion tests/testthat/test-class-comment.R
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ test_that("threaded comments work", {
done = c("0", "")
)
got <- wb_get_thread(wb)[, -1]
expect_equal(exp, got)
# somehow the row ordering differs for parallel and non-parallel testthat runs
expect_equal(exp[order(got$displayName), ], got, ignore_attr = TRUE)

exp <- "[Threaded comment]\n\nYour spreadsheet software allows you to read this threaded comment; however, any edits to it will get removed if the file is opened in a newer version of a certain spreadsheet software.\n\nComment: wow it works!\nReplie:fascinating"
got <- wb_get_comment(wb)$comment
Expand Down

0 comments on commit fcb6670

Please sign in to comment.