Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests] improve testfile_path() to download files #785

Merged
merged 2 commits into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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