Skip to content

Commit

Permalink
migrate unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau-lilly committed Dec 4, 2023
1 parent 8bf498c commit fe3acb0
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 41 deletions.
20 changes: 10 additions & 10 deletions tests/testthat/test-class_target.R
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ tar_test("invalidation: repeated non-branching run skipped", {
skip_cran()
local <- local_init(pipeline_order())
local$run()
out <- counter_get_names(local$scheduler$progress$built)
out <- counter_get_names(local$scheduler$progress$completed)
exp <- pipeline_get_names(local$pipeline)
expect_equal(sort(out), sort(exp))
local <- local_init(pipeline_order())
Expand All @@ -180,7 +180,7 @@ tar_test("invalidation: repeated branching run skipped", {
skip_cran()
local <- local_init(pipeline_map())
local$run()
out <- counter_get_names(local$scheduler$progress$built)
out <- counter_get_names(local$scheduler$progress$completed)
exp <- pipeline_get_names(local$pipeline)
exp <- setdiff(exp, paste0("map", seq_len(6)))
exp <- grep("data[0-9]_", invert = TRUE, value = TRUE, x = exp)
Expand Down Expand Up @@ -214,7 +214,7 @@ tar_test("invalidation: update an existing branch", {
target_get_children(pipeline_get_target(pipeline, "y"))[2],
target_get_children(pipeline_get_target(pipeline, "z"))[2]
)
exp <- counter_get_names(local$scheduler$progress$built)
exp <- counter_get_names(local$scheduler$progress$completed)
expect_equal(sort(c("x", "w", out)), sort(exp))
for (branch in out) {
expect_equal(
Expand Down Expand Up @@ -243,7 +243,7 @@ tar_test("invalidation: insert a branch", {
target_get_children(pipeline_get_target(pipeline, "y"))[2],
target_get_children(pipeline_get_target(pipeline, "z"))[2]
)
exp <- counter_get_names(local$scheduler$progress$built)
exp <- counter_get_names(local$scheduler$progress$completed)
expect_equal(sort(c("x", out)), sort(exp))
for (branch in out) {
expect_equal(
Expand All @@ -267,7 +267,7 @@ tar_test("invalidation: remove a branch", {
pipeline <- pipeline_init(list(x, y, z))
local <- local_init(pipeline)
local$run()
out <- counter_get_names(local$scheduler$progress$built)
out <- counter_get_names(local$scheduler$progress$completed)
expect_equal(out, "x")
})

Expand All @@ -279,7 +279,7 @@ tar_test("invalidation: depend on all branches", {
pipeline <- pipeline_init(list(x, y, z), clone_targets = FALSE)
local <- local_init(pipeline)
local$run()
out <- counter_get_names(local$scheduler$progress$built)
out <- counter_get_names(local$scheduler$progress$completed)
exp <- c("x", "z", target_get_children(y))
expect_equal(sort(out), sort(exp))
x <- target_init("x", quote(c(1L, 5L, 3L)))
Expand All @@ -288,7 +288,7 @@ tar_test("invalidation: depend on all branches", {
pipeline <- pipeline_init(list(x, y, z), clone_targets = FALSE)
local <- local_init(pipeline)
local$run()
out <- counter_get_names(local$scheduler$progress$built)
out <- counter_get_names(local$scheduler$progress$completed)
exp <- c("x", "z", target_get_children(y)[2])
expect_equal(sort(out), sort(exp))
})
Expand Down Expand Up @@ -317,7 +317,7 @@ tar_test("invalidation: map over a stem with no branches previously", {
meta <- meta_init()$database$read_condensed_data()
last_children <- unlist(meta$children[meta$name == "z"])
expect_equal(intersect(first_children, last_children), character(0))
out <- counter_get_names(local$scheduler$progress$built)
out <- counter_get_names(local$scheduler$progress$completed)
expect_equal(length(out), 2L)
expect_true(all(grepl("^z_", out)))
})
Expand Down Expand Up @@ -377,7 +377,7 @@ tar_test("invalidation: chg pattern iter forces downstream reaggregation", {
)
local <- local_init(pipeline)
local$run()
expect_true("z" %in% counter_get_names(local$scheduler$progress$built))
expect_true("z" %in% counter_get_names(local$scheduler$progress$completed))
})

tar_test("invalidation: change a nested function", {
Expand Down Expand Up @@ -424,7 +424,7 @@ tar_test("invalidation: change a nested function", {
out <- tar_outdated(callr_function = NULL, targets_only = FALSE)
expect_true(all(c("f", "g", "x") %in% out))
tar_make(callr_function = NULL)
expect_equal(tar_progress()$progress, "built")
expect_equal(tar_progress()$progress, "completed")
expect_equal(tar_read(x), 3L)
})

Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-class_torch.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ tar_test("torch format with in-memory serialization", {

tar_test("torch in-memory serialization of deps", {
skip_cran()
skip_on_os("mac")
skip_on_os("solaris")
skip_on_os("windows")
require_clustermq()
Expand Down
9 changes: 5 additions & 4 deletions tests/testthat/test-tar_built.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
tar_test("tar_built() empty", {
expect_equal(tar_built(), character(0))
expect_equal(tar_built(contains("x")), character(0))
expect_warning(tar_built(), class = "crew_condition_deprecate")
expect_equal(suppressWarnings(tar_built()), character(0))
expect_equal(suppressWarnings(tar_built(contains("x"))), character(0))
})

tar_test("tar_built() nonempty", {
skip_cran()
tar_script(list(tar_target(x, 1), tar_target(y, 1)))
tar_make(callr_function = NULL)
expect_equal(sort(tar_built()), sort(c("x", "y")))
expect_equal(tar_built(contains("x")), "x")
expect_equal(sort(suppressWarnings(tar_built())), sort(c("x", "y")))
expect_equal(suppressWarnings(tar_built(contains("x"))), "x")
})
4 changes: 2 additions & 2 deletions tests/testthat/test-tar_cancel.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ tar_test("tar_cancel(TRUE)", {
expect_equal(nrow(data), 0L)
progress <- local$scheduler$progress$database$read_data()
expect_equal(progress$name, c("x", "x"))
expect_equal(progress$progress, c("started", "canceled"))
expect_equal(progress$progress, c("dispatched", "canceled"))
expect_false(file.exists(file.path("_targets", "objects", "x")))
}
})
Expand All @@ -29,7 +29,7 @@ tar_test("tar_cancel(FALSE)", {
)
expect_equal(out, character(0))
out <- counter_get_names(
local$scheduler$progress$built
local$scheduler$progress$completed
)
expect_equal(out, "x")
expect_true(file.exists(file.path("_targets", "objects", "x")))
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-tar_completed.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
tar_test("tar_completed() empty", {
expect_equal(tar_completed(), character(0))
expect_equal(tar_completed(contains("x")), character(0))
})

tar_test("tar_completed() nonempty", {
skip_cran()
tar_script(list(tar_target(x, 1), tar_target(y, 1)))
tar_make(callr_function = NULL)
expect_equal(sort(tar_completed()), sort(c("x", "y")))
expect_equal(tar_completed(contains("x")), "x")
})
16 changes: 16 additions & 0 deletions tests/testthat/test-tar_dispatched.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
tar_test("tar_dispatched() empty", {
expect_equal(tar_dispatched(), character(0))
expect_equal(tar_dispatched(contains("x")), character(0))
})

tar_test("tar_dispatched() nonempty", {
skip_cran()
tar_script(list(tar_target(x, 1), tar_target(y, 1)))
tar_make(callr_function = NULL)
path <- path_progress(path_store_default())
lines <- readLines(path)
lines <- lines[!grepl("completed", lines)]
writeLines(lines, path)
expect_equal(sort(tar_dispatched()), sort(c("x", "y")))
expect_equal(tar_dispatched(contains("x")), "x")
})
11 changes: 10 additions & 1 deletion tests/testthat/test-tar_make_clustermq.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ crew_test_sleep()

tar_test("tar_make_clustermq() works with callr_function = NULL", {
skip_cran()
skip_on_os("mac")
skip_on_os("windows")
skip_on_os("solaris")
require_clustermq()
Expand All @@ -22,6 +23,7 @@ tar_test("tar_make_clustermq() works with callr_function = NULL", {

tar_test("tar_make_clustermq() works", {
skip_cran()
skip_on_os("mac")
skip_on_os("windows")
skip_on_os("solaris")
require_clustermq()
Expand All @@ -39,6 +41,7 @@ tar_test("tar_make_clustermq() works", {

tar_test("tar_make_clustermq() can use tidyselect", {
skip_cran()
skip_on_os("mac")
skip_on_os("windows")
skip_on_os("solaris")
require_clustermq()
Expand Down Expand Up @@ -67,6 +70,8 @@ tar_test("custom script and store args", {
skip_cran()
require_clustermq()
skip_on_covr()
skip_on_os("mac")
skip_on_os("solaris")
skip_on_os("windows")
expect_equal(tar_config_get("script"), path_script_default())
expect_equal(tar_config_get("store"), path_store_default())
Expand Down Expand Up @@ -102,6 +107,8 @@ tar_test("custom script and store args with callr function", {
skip_cran()
require_clustermq()
skip_on_covr()
skip_on_os("mac")
skip_on_os("solaris")
skip_on_os("windows")
expect_equal(tar_config_get("script"), path_script_default())
expect_equal(tar_config_get("store"), path_store_default())
Expand Down Expand Up @@ -135,6 +142,8 @@ tar_test("custom script and store args with callr function", {

tar_test("bootstrap builder for shortcut", {
skip_cran()
skip_on_os("mac")
skip_on_os("solaris")
skip_on_os("windows")
require_clustermq()
skip_on_covr()
Expand Down Expand Up @@ -169,7 +178,7 @@ tar_test("bootstrap builder for shortcut", {
progress <- tar_progress()
expect_equal(nrow(progress), 1L)
expect_equal(progress$name, "z")
expect_equal(progress$progress, "built")
expect_equal(progress$progress, "completed")
})

crew_test_sleep()
2 changes: 1 addition & 1 deletion tests/testthat/test-tar_make_future.R
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,5 @@ tar_test("bootstrap builder for shortcut", {
progress <- tar_progress()
expect_equal(nrow(progress), 1L)
expect_equal(progress$name, "z")
expect_equal(progress$progress, "built")
expect_equal(progress$progress, "completed")
})
4 changes: 2 additions & 2 deletions tests/testthat/test-tar_progress.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tar_test("tar_progress() with defaults", {
for (result in c("built", "skipped")) {
for (result in c("completed", "skipped")) {
pipeline <- pipeline_init(list(target_init("x", quote(1))))
local_init(pipeline = pipeline)$run()
out <- tar_progress()
Expand All @@ -18,7 +18,7 @@ tar_test("tar_progress() with fields = NULL", {
expect_equal(out$type, "stem")
expect_equal(out$parent, "x")
expect_equal(out$branches, 0L)
expect_equal(out$progress, "built")
expect_equal(out$progress, "completed")
})

tar_test("tar_progress() tidyselect", {
Expand Down
16 changes: 8 additions & 8 deletions tests/testthat/test-tar_progress_branches.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ tar_test("tar_progress_branches()", {
"name",
"branches",
"skipped",
"started",
"built",
"dispatched",
"completed",
"errored",
"canceled"
)
Expand All @@ -34,17 +34,17 @@ tar_test("tar_progress_branches()", {
expect_equal(colnames(out), cols)
expect_equal(out$name, "y")
expect_equal(out$branches, 1)
expect_equal(out$started, 0)
expect_equal(out$built, 1)
expect_equal(out$dispatched, 0)
expect_equal(out$completed, 1)
expect_equal(out$canceled, 0)
expect_equal(out$errored, 0)
out <- tar_progress_branches(names = z)
expect_equal(nrow(out), 1)
expect_equal(colnames(out), cols)
expect_equal(out$name, "z")
expect_equal(out$branches, 1)
expect_equal(out$started, 0)
expect_equal(out$built, 0)
expect_equal(out$dispatched, 0)
expect_equal(out$completed, 0)
expect_equal(out$canceled, 0)
expect_equal(out$errored, 1)
})
Expand All @@ -58,8 +58,8 @@ tar_test("tar_progress_branches() with fields", {
)
}, ask = FALSE)
tar_make(callr_function = NULL)
out <- tar_progress_branches(fields = started)
exp <- tibble::tibble(name = "y", started = 0L)
out <- tar_progress_branches(fields = dispatched)
exp <- tibble::tibble(name = "y", dispatched = 0L)
expect_equal(out, exp)
})

Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-tar_progress_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ tar_test("default progress", {
out <- tar_progress_summary()
expect_equal(
colnames(out),
c("skipped", "started", "built", "errored", "canceled", "since")
c("skipped", "dispatched", "completed", "errored", "canceled", "since")
)
expect_equal(out$started, 0L)
expect_equal(out$built, 4L)
expect_equal(out$dispatched, 0L)
expect_equal(out$completed, 4L)
expect_equal(out$errored, 2L)
expect_equal(out$canceled, 5L)
expect_true(is.character(out$since))
Expand Down
11 changes: 6 additions & 5 deletions tests/testthat/test-tar_started.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
tar_test("tar_started() empty", {
expect_equal(tar_started(), character(0))
expect_equal(tar_started(contains("x")), character(0))
expect_warning(tar_started(), class = "tar_condition_deprecate")
expect_equal(suppressWarnings(tar_started()), character(0))
expect_equal(suppressWarnings(tar_started(contains("x"))), character(0))
})

tar_test("tar_started() nonempty", {
Expand All @@ -9,8 +10,8 @@ tar_test("tar_started() nonempty", {
tar_make(callr_function = NULL)
path <- path_progress(path_store_default())
lines <- readLines(path)
lines <- lines[!grepl("built", lines)]
lines <- lines[!grepl("completed", lines)]
writeLines(lines, path)
expect_equal(sort(tar_started()), sort(c("x", "y")))
expect_equal(tar_started(contains("x")), "x")
expect_equal(sort(suppressWarnings(tar_started())), sort(c("x", "y")))
expect_equal(suppressWarnings(tar_started(contains("x"))), "x")
})
2 changes: 1 addition & 1 deletion tests/testthat/test-tar_timestamp.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ tar_test("use timestamp in a target", {
expect_true(inherits(out, "POSIXct"))
expect_identical(as.numeric(out), as.numeric(file_time_reference))
progress <- tar_progress()
expect_equal(progress$progress[progress$name == "y"], "built")
expect_equal(progress$progress[progress$name == "y"], "completed")
tar_make(callr_function = NULL)
progress <- tar_progress()
expect_equal(progress$progress[progress$name == "y"], "canceled")
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-utils_cli.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
tar_test("cli_start()", {
tar_test("cli_dispatched()", {
skip_cran()
expect_message(cli_start("x", time_stamp = TRUE))
expect_message(cli_dispatched("x", time_stamp = TRUE))
})

tar_test("cli_built()", {
tar_test("cli_completed()", {
skip_cran()
expect_message(cli_built("x", time_stamp = TRUE))
expect_message(cli_completed("x", time_stamp = TRUE))
})

tar_test("cli_skip()", {
Expand Down

0 comments on commit fe3acb0

Please sign in to comment.