From 1587befe17c11fe5881b105abb9a95288daea0c6 Mon Sep 17 00:00:00 2001 From: wlandau Date: Thu, 7 Nov 2024 14:59:35 -0500 Subject: [PATCH] testing --- tests/aws/test-class_inventory_aws.R | 9 ++++--- tests/gcp/test-class_inventory_gcp.R | 9 ++++--- tests/hpc/test-clustermq_sge.R | 2 +- tests/interactive/test-class_url.R | 8 +++--- tests/interactive/test-keras.R | 2 +- tests/testthat/test-class_bud.R | 4 +-- tests/testthat/test-class_builder.R | 40 ++++++++++++++-------------- 7 files changed, 39 insertions(+), 35 deletions(-) diff --git a/tests/aws/test-class_inventory_aws.R b/tests/aws/test-class_inventory_aws.R index 62105aed7..8cf2e27a5 100644 --- a/tests/aws/test-class_inventory_aws.R +++ b/tests/aws/test-class_inventory_aws.R @@ -20,16 +20,17 @@ tar_test("inventory_aws class", { ) ) store <- store_init(repository = "aws", resources = resources) + file <- file_init() expect_equal(inventory$list_cache(), character(0L)) expect_equal(inventory$downloads, 0L) expect_equal(inventory$misses, 0L) for (key in rev(file.path(prefix, c("w", "x", "y", "z")))) { - store$file$path <- store_produce_aws_path( + file$path <- store_produce_aws_path( store = store, name = basename(key), path_store = path_store_default() ) - out <- inventory$get_cache(store) + out <- inventory$get_cache(store, file) expect_equal(inventory$misses, 1L) expect_equal(inventory$downloads, 1L) expect_equal(out, hash_object(head[[key]]$ETag)) @@ -44,12 +45,12 @@ tar_test("inventory_aws class", { ) ) } - store$file$path <- store_produce_aws_path( + file$path <- store_produce_aws_path( store = store, name = "nope", path_store = path_store_default() ) - expect_null(inventory$get_cache(store)) + expect_null(inventory$get_cache(store, file)) expect_equal(inventory$downloads, 1L) expect_equal(inventory$misses, 2L) }) diff --git a/tests/gcp/test-class_inventory_gcp.R b/tests/gcp/test-class_inventory_gcp.R index 57e7e6fdf..97c150c57 100644 --- a/tests/gcp/test-class_inventory_gcp.R +++ b/tests/gcp/test-class_inventory_gcp.R @@ -24,16 +24,17 @@ tar_test("inventory_gcp class", { ) ) store <- store_init(repository = "gcp", resources = resources) + file <- file_init() expect_equal(inventory$list_cache(), character(0L)) expect_equal(inventory$downloads, 0L) expect_equal(inventory$misses, 0L) for (key in rev(file.path(prefix, c("w", "x", "y", "z")))) { - store$file$path <- store_produce_gcp_path( + file$path <- store_produce_gcp_path( store = store, name = basename(key), path_store = path_store_default() ) - out <- inventory$get_cache(store) + out <- inventory$get_cache(store, file) expect_equal(inventory$misses, 1L) expect_equal(inventory$downloads, 1L) expect_equal(out, hash_object(head[[key]]$md5)) @@ -48,12 +49,12 @@ tar_test("inventory_gcp class", { ) ) } - store$file$path <- store_produce_gcp_path( + file$path <- store_produce_gcp_path( store = store, name = "nope", path_store = path_store_default() ) - expect_null(inventory$get_cache(store)) + expect_null(inventory$get_cache(store, file)) expect_equal(inventory$downloads, 1L) expect_equal(inventory$misses, 2L) }) diff --git a/tests/hpc/test-clustermq_sge.R b/tests/hpc/test-clustermq_sge.R index f8becff65..295c89a79 100644 --- a/tests/hpc/test-clustermq_sge.R +++ b/tests/hpc/test-clustermq_sge.R @@ -238,7 +238,7 @@ test_that("clustermq with a dynamic file", { cmq$run() out <- names(cmq$scheduler$progress$completed$envir) expect_equal(out, "x") - saveRDS(2L, pipeline_get_target(pipeline, "x")$store$file$path) + saveRDS(2L, pipeline_get_target(pipeline, "x")$file$path) x <- tar_target_raw("x", quote(save1()), format = "file") pipeline <- pipeline_init(list(x)) cmq <- clustermq_init(pipeline) diff --git a/tests/interactive/test-class_url.R b/tests/interactive/test-class_url.R index 98c37d505..0a4f33c27 100644 --- a/tests/interactive/test-class_url.R +++ b/tests/interactive/test-class_url.R @@ -443,9 +443,11 @@ tar_test("inherits from tar_external", { }) tar_test("store_row_path()", { - store <- tar_target(x, "x_value", format = "url")$store - store$file$path <- "path" - expect_equal(store_row_path(store), "path") + target <- tar_target(x, "x_value", format = "url") + store <- target$store + file <- target$file + file$path <- "path" + expect_equal(store_row_path(store, file), "path") }) tar_test("store_path_from_record()", { diff --git a/tests/interactive/test-keras.R b/tests/interactive/test-keras.R index de902e307..87bcb0649 100644 --- a/tests/interactive/test-keras.R +++ b/tests/interactive/test-keras.R @@ -42,7 +42,7 @@ tar_test("keras format", { inherits(x$value$object, "keras.engine.training.Model") ) builder_update_paths(x, path_store_default()) - x$store$file$stage <- tempfile() + x$file$stage <- tempfile() builder_update_object(x) expect_true( inherits(target_read_value(x)$object, "keras.engine.training.Model") diff --git a/tests/testthat/test-class_bud.R b/tests/testthat/test-class_bud.R index 42c6f966d..0cc171c49 100644 --- a/tests/testthat/test-class_bud.R +++ b/tests/testthat/test-class_bud.R @@ -91,9 +91,9 @@ tar_test("buds can load values from memory", { parent <- pipeline_get_target(pipeline, "data") target_load_value(parent, pipeline) expect_false(is.null(parent$value)) - unlink(parent$store$file$path) + unlink(parent$file$path) expect_error(suppressWarnings(target_load_value(parent, pipeline))) - expect_false(file.exists(parent$store$file$path)) + expect_false(file.exists(parent$file$path)) expect_null(bud$value) expect_equal(counter_get_names(pipeline$loaded), "data") target_load_value(bud, pipeline) diff --git a/tests/testthat/test-class_builder.R b/tests/testthat/test-class_builder.R index 07a57d4ce..a7fd0d5c9 100644 --- a/tests/testthat/test-class_builder.R +++ b/tests/testthat/test-class_builder.R @@ -18,7 +18,7 @@ tar_test("target_run() on a good builder", { expect_silent(value_validate(x$value)) expect_equal(x$value$object, "x") builder_update_object(x) - expect_true(file.exists(x$store$file$path)) + expect_true(file.exists(x$file$path)) }) tar_test("target_run() on a errored builder", { @@ -76,7 +76,7 @@ tar_test("builders with different names use different seeds", { tar_test("read and write objects", { x <- target_init(name = "abc", expr = quote(a), format = "rds") tmp <- tempfile() - file <- x$store$file + file <- x$file file$path <- tmp file$stage <- tempfile() builder_update_build(x, tmpenv(a = "123")) @@ -91,11 +91,11 @@ tar_test("error = \"stop\" means stop on error", { y <- target_init("y", expr = quote(stop(456)), error = "stop") pipeline <- pipeline_init(list(x, y)) expect_error(local_init(pipeline)$run(), class = "tar_condition_run") - expect_equal(x$store$file$path, character(0)) + expect_equal(x$file$path, character(0)) meta <- meta_init()$database$read_condensed_data() expect_true(all(nzchar(meta$error))) - expect_equal(x$store$file$path, character(0)) - expect_equal(y$store$file$path, character(0)) + expect_equal(x$file$path, character(0)) + expect_equal(y$file$path, character(0)) }) tar_test("error = \"continue\" means continue on error", { @@ -109,12 +109,12 @@ tar_test("error = \"continue\" means continue on error", { class = "tar_condition_run" ) ) - expect_equal(x$store$file$path, character(0)) - expect_equal(y$store$file$path, character(0)) + expect_equal(x$file$path, character(0)) + expect_equal(y$file$path, character(0)) meta <- meta_init()$database$read_condensed_data() expect_true(all(nzchar(meta$error))) - expect_equal(x$store$file$path, character(0)) - expect_equal(y$store$file$path, character(0)) + expect_equal(x$file$path, character(0)) + expect_equal(y$file$path, character(0)) }) tar_test("error = \"abridge\" means do not schedule new targets", { @@ -168,13 +168,13 @@ tar_test("builder writing from main", { pipeline <- pipeline_init(list(x)) scheduler <- scheduler_init(pipeline, meta_init()) target_run(x, tar_option_get("envir"), path_store_default()) - expect_false(file.exists(x$store$file$path)) - expect_true(is.na(x$store$file$hash)) + expect_false(file.exists(x$file$path)) + expect_true(is.na(x$file$hash)) meta <- meta_init() memory_set_object(meta$depends, "abc", NA_character_) target_conclude(x, pipeline, scheduler, meta) - expect_true(file.exists(x$store$file$path)) - expect_false(is.na(x$store$file$hash)) + expect_true(file.exists(x$file$path)) + expect_false(is.na(x$file$hash)) path <- file.path("_targets", "objects", "abc") expect_equal(readRDS(path), "123") expect_equal(target_read_value(x)$object, "123") @@ -194,8 +194,8 @@ tar_test("builder writing from worker", { deployment = "worker" ) target_run(x, tar_option_get("envir"), path_store_default()) - expect_true(file.exists(x$store$file$path)) - expect_false(is.na(x$store$file$hash)) + expect_true(file.exists(x$file$path)) + expect_false(is.na(x$file$hash)) path <- file.path("_targets", "objects", "abc") expect_equal(readRDS(path), "123") expect_equal(target_read_value(x)$object, "123") @@ -303,8 +303,8 @@ tar_test("dynamic file writing from main", { file } target_run(x, tar_option_get("envir"), path_store_default()) - expect_true(file.exists(x$store$file$path)) - expect_false(is.na(x$store$file$hash)) + expect_true(file.exists(x$file$path)) + expect_false(is.na(x$file$hash)) pipeline <- pipeline_init(list(x)) scheduler <- scheduler_init(pipeline, meta_init()) meta <- meta_init() @@ -365,8 +365,8 @@ tar_test("dynamic file writing from worker", { } target_run(x, tar_option_get("envir"), path_store_default()) expect_null(x$value) - expect_true(file.exists(x$store$file$path)) - expect_false(is.na(x$store$file$hash)) + expect_true(file.exists(x$file$path)) + expect_false(is.na(x$file$hash)) pipeline <- pipeline_init(list(x)) meta <- meta_init() scheduler <- scheduler_init(pipeline, meta = meta) @@ -517,7 +517,7 @@ tar_test("validate with nonmissing file and value", { skip_cran() x <- target_init(name = "abc", expr = quote(1L + 1L)) x$value <- value_init(123) - file <- x$store$file + file <- x$file file$path <- tempfile() expect_silent(tmp <- target_validate(x)) })