From fe3acb0df2fe47ab2e6e12cbadc2b1375dcb6fa3 Mon Sep 17 00:00:00 2001 From: wlandau-lilly Date: Mon, 4 Dec 2023 12:10:21 -0500 Subject: [PATCH] migrate unit tests --- tests/testthat/test-class_target.R | 20 ++++++++++---------- tests/testthat/test-class_torch.R | 1 + tests/testthat/test-tar_built.R | 9 +++++---- tests/testthat/test-tar_cancel.R | 4 ++-- tests/testthat/test-tar_completed.R | 12 ++++++++++++ tests/testthat/test-tar_dispatched.R | 16 ++++++++++++++++ tests/testthat/test-tar_make_clustermq.R | 11 ++++++++++- tests/testthat/test-tar_make_future.R | 2 +- tests/testthat/test-tar_progress.R | 4 ++-- tests/testthat/test-tar_progress_branches.R | 16 ++++++++-------- tests/testthat/test-tar_progress_summary.R | 6 +++--- tests/testthat/test-tar_started.R | 11 ++++++----- tests/testthat/test-tar_timestamp.R | 2 +- tests/testthat/test-utils_cli.R | 8 ++++---- 14 files changed, 81 insertions(+), 41 deletions(-) create mode 100644 tests/testthat/test-tar_completed.R create mode 100644 tests/testthat/test-tar_dispatched.R diff --git a/tests/testthat/test-class_target.R b/tests/testthat/test-class_target.R index a99381fad..755f5f8fb 100644 --- a/tests/testthat/test-class_target.R +++ b/tests/testthat/test-class_target.R @@ -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()) @@ -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) @@ -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( @@ -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( @@ -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") }) @@ -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))) @@ -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)) }) @@ -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))) }) @@ -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", { @@ -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) }) diff --git a/tests/testthat/test-class_torch.R b/tests/testthat/test-class_torch.R index 3359e10e1..8f97dacbd 100644 --- a/tests/testthat/test-class_torch.R +++ b/tests/testthat/test-class_torch.R @@ -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() diff --git a/tests/testthat/test-tar_built.R b/tests/testthat/test-tar_built.R index 6ff98952f..f7a43df0a 100644 --- a/tests/testthat/test-tar_built.R +++ b/tests/testthat/test-tar_built.R @@ -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") }) diff --git a/tests/testthat/test-tar_cancel.R b/tests/testthat/test-tar_cancel.R index e93c7ee00..2c3476cfc 100644 --- a/tests/testthat/test-tar_cancel.R +++ b/tests/testthat/test-tar_cancel.R @@ -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"))) } }) @@ -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"))) diff --git a/tests/testthat/test-tar_completed.R b/tests/testthat/test-tar_completed.R new file mode 100644 index 000000000..6c5ebdfbf --- /dev/null +++ b/tests/testthat/test-tar_completed.R @@ -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") +}) diff --git a/tests/testthat/test-tar_dispatched.R b/tests/testthat/test-tar_dispatched.R new file mode 100644 index 000000000..9509a2fa8 --- /dev/null +++ b/tests/testthat/test-tar_dispatched.R @@ -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") +}) diff --git a/tests/testthat/test-tar_make_clustermq.R b/tests/testthat/test-tar_make_clustermq.R index 9da7e2e9d..9152d2c3e 100644 --- a/tests/testthat/test-tar_make_clustermq.R +++ b/tests/testthat/test-tar_make_clustermq.R @@ -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() @@ -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() @@ -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() @@ -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()) @@ -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()) @@ -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() @@ -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() diff --git a/tests/testthat/test-tar_make_future.R b/tests/testthat/test-tar_make_future.R index b62f160b3..06028546a 100644 --- a/tests/testthat/test-tar_make_future.R +++ b/tests/testthat/test-tar_make_future.R @@ -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") }) diff --git a/tests/testthat/test-tar_progress.R b/tests/testthat/test-tar_progress.R index 432eae314..03bf6e593 100644 --- a/tests/testthat/test-tar_progress.R +++ b/tests/testthat/test-tar_progress.R @@ -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() @@ -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", { diff --git a/tests/testthat/test-tar_progress_branches.R b/tests/testthat/test-tar_progress_branches.R index 61abe7789..d49ab0f8a 100644 --- a/tests/testthat/test-tar_progress_branches.R +++ b/tests/testthat/test-tar_progress_branches.R @@ -23,8 +23,8 @@ tar_test("tar_progress_branches()", { "name", "branches", "skipped", - "started", - "built", + "dispatched", + "completed", "errored", "canceled" ) @@ -34,8 +34,8 @@ 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) @@ -43,8 +43,8 @@ tar_test("tar_progress_branches()", { 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) }) @@ -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) }) diff --git a/tests/testthat/test-tar_progress_summary.R b/tests/testthat/test-tar_progress_summary.R index b00af3d0d..f6d6393ac 100644 --- a/tests/testthat/test-tar_progress_summary.R +++ b/tests/testthat/test-tar_progress_summary.R @@ -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)) diff --git a/tests/testthat/test-tar_started.R b/tests/testthat/test-tar_started.R index 1b926ad5b..e93c17ec9 100644 --- a/tests/testthat/test-tar_started.R +++ b/tests/testthat/test-tar_started.R @@ -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", { @@ -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") }) diff --git a/tests/testthat/test-tar_timestamp.R b/tests/testthat/test-tar_timestamp.R index 40da048f1..1fad4118a 100644 --- a/tests/testthat/test-tar_timestamp.R +++ b/tests/testthat/test-tar_timestamp.R @@ -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") diff --git a/tests/testthat/test-utils_cli.R b/tests/testthat/test-utils_cli.R index 09a6bbbd1..adb4c07dd 100644 --- a/tests/testthat/test-utils_cli.R +++ b/tests/testthat/test-utils_cli.R @@ -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()", {