-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,49 @@ | |
#' @noRd | ||
throwaway <- "[email protected]" | ||
|
||
#' Install metacheck in temp library path | ||
#' Necessary for any testing in testthat with [future::multisession()] | ||
#' @noRd | ||
local_mc <- function(env = parent.frame()) { | ||
withr::local_temp_libpaths(.local_envir = env) | ||
remotes::install_local( | ||
path = usethis::proj_get(), | ||
dependencies = FALSE, | ||
upgrade = FALSE, | ||
force = TRUE | ||
) | ||
} | ||
|
||
#' Temporarily set future plan | ||
#' @inheritParams future::strategy | ||
#' @noRd | ||
local_strategy <- function(strategy, env = parent.frame()) { | ||
old_plan <- future::plan(strategy = strategy) | ||
withr::defer(future::plan(old_plan), env = env) | ||
} | ||
|
||
#' Future strategies to be tested | ||
#' @noRd | ||
strategies <- list( | ||
sequential = future::sequential, | ||
multicore = future::multicore, | ||
multisession = future::multisession | ||
) | ||
|
||
#' Skipping unsupported strategies | ||
skip_if_strategy_unsupported <- function(strategy_name = names(strategies)) { | ||
strategy_name <- rlang::arg_match(strategy_name) | ||
if (strategy_name == "multicore" && !future::supportsMulticore()) { | ||
return(testthat::skip("Multicore is not supported")) | ||
} | ||
if (strategy_name == "multisession" && testthat::is_parallel()) { | ||
return(testthat::skip( | ||
"Multisession futures cannot be tested inside parallel tests." | ||
)) | ||
} | ||
invisible(TRUE) | ||
} | ||
|
||
#' used often b/c plain json doesn't cover complex objects | ||
#' @noRd | ||
expect_snapshot_value2 <- purrr::partial( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# multisession futures need locally installed metacheck | ||
local_mc(env = testthat::teardown_env()) |