Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Nov 7, 2024
1 parent fcd927d commit 1587bef
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 35 deletions.
9 changes: 5 additions & 4 deletions tests/aws/test-class_inventory_aws.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
})
9 changes: 5 additions & 4 deletions tests/gcp/test-class_inventory_gcp.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
})
2 changes: 1 addition & 1 deletion tests/hpc/test-clustermq_sge.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions tests/interactive/test-class_url.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()", {
Expand Down
2 changes: 1 addition & 1 deletion tests/interactive/test-keras.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-class_bud.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
40 changes: 20 additions & 20 deletions tests/testthat/test-class_builder.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down Expand Up @@ -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"))
Expand All @@ -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", {
Expand All @@ -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", {
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
})
Expand Down

0 comments on commit 1587bef

Please sign in to comment.