Skip to content

Commit

Permalink
Migrate testing
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau-lilly committed Sep 24, 2023
1 parent 7743f30 commit f336534
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 54 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Description: Pipeline tools coordinate the pieces of computationally
The methodology in this package
borrows from GNU 'Make' (2015, ISBN:978-9881443519)
and 'drake' (2018, <doi:10.21105/joss.00550>).
Version: 1.3.0.9001
Version: 1.3.0.9002
License: MIT + file LICENSE
URL: https://docs.ropensci.org/targets/, https://github.com/ropensci/targets
BugReports: https://github.com/ropensci/targets/issues
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# targets 1.3.0.9001 (development)
# targets 1.3.0.9002 (development)

* Add `tar_config_projects()` and `tar_config_yaml()` (#1153, @psychelzh).
* Apply error modes to `builder_wait_correct_hash()` in `target_conclude.tar_builder()` (#1154, @gadenbuie).
Expand Down
4 changes: 1 addition & 3 deletions R/class_builder.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ builder_should_run <- function(target, meta) {
if (cue_format(cue, target, meta, record)) return(TRUE)
if (cue_repository(cue, target, meta, record)) return(TRUE)
if (cue_iteration(cue, target, meta, record)) return(TRUE)
if (cue_seed(cue, target, meta, record)) return(TRUE)
if (cue_file(cue, target, meta, record)) return(TRUE)
FALSE
}
Expand Down Expand Up @@ -527,7 +526,6 @@ builder_sitrep <- function(target, meta) {
NA,
cue_iteration(cue, target, meta, record)
),
file = if_any(cue_record, NA, cue_file(cue, target, meta, record)),
seed = if_any(cue_record, NA, cue_seed(cue, target, meta, record))
file = if_any(cue_record, NA, cue_file(cue, target, meta, record))
)
}
21 changes: 3 additions & 18 deletions R/class_cue.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ cue_init <- function(
format = TRUE,
repository = TRUE,
iteration = TRUE,
file = TRUE,
seed = TRUE
file = TRUE
) {
cue_new(
mode = mode,
Expand All @@ -15,8 +14,7 @@ cue_init <- function(
format = format,
repository = repository,
iteration = iteration,
file = file,
seed = seed
file = file
)
}

Expand All @@ -27,8 +25,7 @@ cue_new <- function(
format = NULL,
repository = NULL,
iteration = NULL,
file = NULL,
seed = NULL
file = NULL
) {
force(mode)
force(command)
Expand All @@ -37,7 +34,6 @@ cue_new <- function(
force(repository)
force(iteration)
force(file)
force(seed)
enclass(environment(), "tar_cue")
}

Expand Down Expand Up @@ -132,15 +128,6 @@ cue_file <- function(cue, target, meta, record) {
!store_has_correct_hash(target$store)
}

cue_seed <- function(cue, target, meta, record) {
if (!cue$seed) {
return(FALSE)
}
old <- as.integer(record$seed)
new <- as.integer(target$command$seed)
anyNA(new) || !identical(old, new)
}

cue_validate <- function(cue) {
tar_assert_correct_fields(cue, cue_new)
tar_assert_chr(cue$mode)
Expand All @@ -151,15 +138,13 @@ cue_validate <- function(cue) {
tar_assert_lgl(cue$repository)
tar_assert_lgl(cue$iteration)
tar_assert_lgl(cue$file)
tar_assert_lgl(cue$seed)
tar_assert_scalar(cue$mode)
tar_assert_scalar(cue$command)
tar_assert_scalar(cue$depend)
tar_assert_scalar(cue$format)
tar_assert_scalar(cue$repository)
tar_assert_scalar(cue$iteration)
tar_assert_scalar(cue$file)
tar_assert_scalar(cue$seed)
}

#' @export
Expand Down
25 changes: 15 additions & 10 deletions R/tar_cue.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,10 @@
#' [tar_target()] or [tar_option_set()].
#' @param file Logical, whether to rerun the target if the file(s) with the
#' return value changed or at least one is missing.
#' @param seed Logical, whether to rerun the target if pseudo-random
#' number generator seed either changed or is `NA`.
#' The reproducible deterministic target-specific
#' seeds are controlled by `tar_option_get("seed")` and the target names.
#' See [tar_option_set()] for details.
#' @param seed Deprecated in version 1.3.0.9002 on 2023-09-24.
#' For details on how `targets` handles
#' pseudo-random numbers, please see
#' <https://books.ropensci.org/targets/random.html>.
#' @examples
#' # The following target will always run when the pipeline runs.
#' x <- tar_target(x, download_data(), cue = tar_cue(mode = "always"))
Expand All @@ -100,30 +99,36 @@ tar_cue <- function(
repository = TRUE,
iteration = TRUE,
file = TRUE,
seed = TRUE
seed = NULL
) {
tar_assert_lgl(command)
tar_assert_lgl(depend)
tar_assert_lgl(format)
tar_assert_lgl(repository)
tar_assert_lgl(iteration)
tar_assert_lgl(file)
tar_assert_lgl(seed)
tar_assert_scalar(command)
tar_assert_scalar(depend)
tar_assert_scalar(format)
tar_assert_scalar(repository)
tar_assert_scalar(iteration)
tar_assert_scalar(file)
tar_assert_scalar(seed)
if (!is.null(seed)) {
tar_warn_deprecate(
"The seed argument of tar_cue() was deprecated ",
"in {targets} version 1.3.0.9002 on 2023-09-24. ",
"For details on how `targets` handles ",
"pseudo-random numbers, please see ",
"https://books.ropensci.org/targets/random.html"
)
}
cue_init(
mode = match.arg(mode),
command = command,
depend = depend,
format = format,
repository = repository,
iteration = iteration,
file = file,
seed = seed
file = file
)
}
11 changes: 5 additions & 6 deletions man/tar_cue.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 0 additions & 15 deletions tests/testthat/test-class_cue.R
Original file line number Diff line number Diff line change
Expand Up @@ -318,21 +318,6 @@ tar_test("cue_iteration() suppressed", {
expect_equal(out, "x")
})

tar_test("cue_seed() suppressed", {
on.exit(tar_option_reset())
tar_option_set(seed = NA)
x <- target_init("x", quote(1L))
local <- local_init(pipeline_init(list(x)))
local$run()
for (index in seq_len(3)) {
x <- target_init("x", quote(1L), cue = tar_cue(seed = FALSE))
local <- local_init(pipeline_init(list(x)))
local$run()
out <- counter_get_names(local$scheduler$progress$built)
expect_equal(out, character(0))
}
})

tar_test("cue_file()", {
x <- target_init("x", quote(1L))
local <- local_init(pipeline_init(list(x)))
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-tar_cue.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ tar_test("tar_cue() works", {
tar_test("tar_cue() takes only allowed modes", {
expect_error(tar_cue(mode = "nope"))
})

tar_test("tar_cue() deprecate seed", {
expect_warning(tar_cue(seed = TRUE), class = "tar_condition_deprecate")
})

0 comments on commit f336534

Please sign in to comment.