Skip to content

Commit

Permalink
remove store from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Nov 7, 2024
1 parent 1587bef commit faa43ce
Show file tree
Hide file tree
Showing 20 changed files with 95 additions and 72 deletions.
2 changes: 1 addition & 1 deletion tests/testthat/test-class_clustermq.R
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ tar_test("clustermq with a dynamic file", {
suppressWarnings(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
6 changes: 3 additions & 3 deletions tests/testthat/test-class_cue.R
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ tar_test("cue_file()", {
local$run()
out <- counter_get_names(local$scheduler$progress$completed)
expect_equal(out, "x")
saveRDS(2L, x$store$file$path)
saveRDS(2L, x$file$path)
x <- target_init("x", quote(1L))
local <- local_init(pipeline_init(list(x)))
local$run()
Expand Down Expand Up @@ -432,7 +432,7 @@ tar_test("cue_file() suppressed", {
local$run()
out <- counter_get_names(local$scheduler$progress$completed)
expect_equal(out, "x")
saveRDS(2L, x$store$file$path)
saveRDS(2L, x$file$path)
x <- target_init("x", quote(1L), cue = cue)
local <- local_init(pipeline_init(list(x)))
local$run()
Expand All @@ -453,7 +453,7 @@ tar_test("cue_file() on a dynamic file", {
local$run()
out <- counter_get_names(local$scheduler$progress$completed)
expect_equal(out, "x")
saveRDS(2L, x$store$file$path)
saveRDS(2L, x$file$path)
x <- target_init("x", quote(save1()), format = "file")
local <- local_init(pipeline_init(list(x)))
local$run()
Expand Down
10 changes: 6 additions & 4 deletions tests/testthat/test-class_feather.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tar_test("feather format", {
exp <- envir$f()
expect_equal(
as.data.frame(
eval(parse(text = "arrow::read_feather"))(x$store$file$path)
eval(parse(text = "arrow::read_feather"))(x$file$path)
),
as.data.frame(exp)
)
Expand Down Expand Up @@ -130,9 +130,11 @@ tar_test("does not inherit from tar_external", {
tar_test("store_row_path()", {
skip_cran()
skip_if_not_installed("arrow")
store <- tar_target(x, "x_value", format = "feather")$store
store$file$path <- "path"
expect_equal(store_row_path(store), NA_character_)
target <- tar_target(x, "x_value", format = "feather")
store <- target$store
file <- target$file
file$path <- "path"
expect_equal(store_row_path(store, file), NA_character_)
})

tar_test("store_path_from_record()", {
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-class_frames.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ tar_test("target_frames_deps()", {
frames <- frames_init()
tmp <- tempfile()
saveRDS("value", tmp)
file <- x$store$file$path <- tmp
file <- y$store$file$path <- tmp
file <- x$file$path <- tmp
file <- y$file$path <- tmp
expect_named(frames_get_envir(frames), character(0))
x <- pipeline_get_target(pipeline, "abc")
y <- pipeline_get_target(pipeline, "def")
Expand Down
10 changes: 6 additions & 4 deletions tests/testthat/test-class_fst.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ tar_test("fst format", {
builder_update_paths(x, path_store_default())
builder_update_object(x)
exp <- envir$f()
expect_equal(fst::read_fst(x$store$file$path), exp)
expect_equal(fst::read_fst(x$file$path), exp)
expect_equal(target_read_value(x)$object, exp)
expect_silent(target_validate(x))
})
Expand Down Expand Up @@ -92,9 +92,11 @@ tar_test("does not inherit from tar_external", {

tar_test("store_row_path()", {
skip_if_not_installed("fst")
store <- tar_target(x, "x_value", format = "fst")$store
store$file$path <- "path"
expect_equal(store_row_path(store), NA_character_)
target <- tar_target(x, "x_value", format = "fst")
store <- target$store
file <- target$file
file$path <- "path"
expect_equal(store_row_path(store, file), NA_character_)
})

tar_test("store_path_from_record()", {
Expand Down
10 changes: 6 additions & 4 deletions tests/testthat/test-class_fst_dt.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ tar_test("fst_dt format", {
builder_update_paths(x, path_store_default())
builder_update_object(x)
exp <- envir$f()
file <- x$store$file
file <- x$file
out <- fst::read_fst(file$path, as.data.table = TRUE)
expect_equal(out, exp)
expect_equal(target_read_value(x)$object, exp)
Expand Down Expand Up @@ -70,9 +70,11 @@ tar_test("does not inherit from tar_external", {
tar_test("store_row_path()", {
skip_if_not_installed("data.table")
skip_if_not_installed("fst")
store <- tar_target(x, "x_value", format = "fst_dt")$store
store$file$path <- "path"
expect_equal(store_row_path(store), NA_character_)
target <- tar_target(x, "x_value", format = "fst_dt")
store <- target$store
file <- target$file
file$path <- "path"
expect_equal(store_row_path(store, file), NA_character_)
})

tar_test("store_path_from_record()", {
Expand Down
10 changes: 6 additions & 4 deletions tests/testthat/test-class_fst_tbl.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ tar_test("fst_tbl format", {
builder_update_paths(x, path_store_default())
builder_update_object(x)
exp <- envir$f()
out <- tibble::as_tibble(fst::read_fst(x$store$file$path))
out <- tibble::as_tibble(fst::read_fst(x$file$path))
expect_equal(out, exp)
expect_equal(target_read_value(x)$object, exp)
expect_silent(target_validate(x))
Expand Down Expand Up @@ -89,9 +89,11 @@ tar_test("does not inherit from tar_external", {
tar_test("store_row_path()", {
skip_if_not_installed("fst")
skip_if_not_installed("tibble")
store <- tar_target(x, "x_value", format = "fst_tbl")$store
store$file$path <- "path"
expect_equal(store_row_path(store), NA_character_)
target <- tar_target(x, "x_value", format = "fst_tbl")
store <- target$store
file <- target$file
file$path <- "path"
expect_equal(store_row_path(store, file), NA_character_)
})

tar_test("store_path_from_record()", {
Expand Down
10 changes: 6 additions & 4 deletions tests/testthat/test-class_gcp.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@ tar_test("inherits from tar_external", {
})

tar_test("store_row_path()", {
store <- tar_target(
target <- tar_target(
x,
"x_value",
format = "feather",
repository = "gcp"
)$store
store$file$path <- "path"
expect_equal(store_row_path(store), "path")
)
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
10 changes: 6 additions & 4 deletions tests/testthat/test-class_gcp_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ tar_test("inherits from tar_external", {
})

tar_test("store_row_path()", {
store <- tar_target(
target <- tar_target(
x,
"x_value",
format = "file",
repository = "gcp"
)$store
store$file$path <- "path"
expect_equal(store_row_path(store), "path")
)
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
8 changes: 5 additions & 3 deletions tests/testthat/test-class_keras.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ tar_test("does not inherit from tar_external", {

tar_test("store_row_path()", {
skip_cran()
store <- tar_target(x, "x_value", format = "keras")$store
store$file$path <- "path"
expect_equal(store_row_path(store), NA_character_)
target <- tar_target(x, "x_value", format = "keras")
store <- target$store
file <- target$file
file$path <- "path"
expect_equal(store_row_path(store, file), NA_character_)
})

tar_test("store_path_from_record()", {
Expand Down
10 changes: 6 additions & 4 deletions tests/testthat/test-class_parquet.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tar_test("parquet format", {
exp <- envir$f()
expect_equal(
as.data.frame(
eval(parse(text = "arrow::read_parquet"))(x$store$file$path)
eval(parse(text = "arrow::read_parquet"))(x$file$path)
),
as.data.frame(exp)
)
Expand Down Expand Up @@ -130,9 +130,11 @@ tar_test("does not inherit from tar_external", {
tar_test("store_row_path()", {
skip_cran()
skip_if_not_installed("arrow")
store <- tar_target(x, "x_value", format = "parquet")$store
store$file$path <- "path"
expect_equal(store_row_path(store), NA_character_)
target <- tar_target(x, "x_value", format = "parquet")
store <- target$store
file <- target$file
file$path <- "path"
expect_equal(store_row_path(store, file), NA_character_)
})

tar_test("store_path_from_record()", {
Expand Down
10 changes: 6 additions & 4 deletions tests/testthat/test-class_qs.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ tar_test("qs format", {
builder_update_paths(x, path_store_default())
builder_update_object(x)
exp <- 2L
expect_equal(qs::qread(x$store$file$path), exp)
expect_equal(qs::qread(x$file$path), exp)
expect_equal(target_read_value(x)$object, exp)
expect_silent(target_validate(x))
})
Expand Down Expand Up @@ -70,9 +70,11 @@ tar_test("does not inherit from tar_external", {
})

tar_test("store_row_path()", {
store <- tar_target(x, "x_value", format = "qs")$store
store$file$path <- "path"
expect_equal(store_row_path(store), NA_character_)
target <- tar_target(x, "x_value", format = "qs")
store <- target$store
file <- target$file
file$path <- "path"
expect_equal(store_row_path(store, file), NA_character_)
})

tar_test("store_path_from_record()", {
Expand Down
16 changes: 9 additions & 7 deletions tests/testthat/test-class_rds.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ tar_test("rds update_object()", {
x <- target_init(name = "abc", expr = quote(a), format = "rds")
builder_update_build(x, tmpenv(a = "123"))
builder_update_paths(x, 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))
store_update_stage_early(x$store, "abc", path_store_default())
builder_update_object(x)
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 @@ -32,9 +32,11 @@ tar_test("does not inherit from tar_external", {
})

tar_test("store_row_path()", {
store <- tar_target(x, "x_value", format = "rds")$store
store$file$path <- "path"
expect_equal(store_row_path(store), NA_character_)
target <- tar_target(x, "x_value", format = "rds")
store <- target$store
file <- target$file
file$path <- "path"
expect_equal(store_row_path(store, file), NA_character_)
})

tar_test("store_path_from_record()", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-class_stem.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tar_test("target_load_value()", {
x <- target_init(name = "abc", expr = quote(2L), format = "rds")
tmp <- tempfile()
saveRDS("abc", tmp)
file <- x$store$file
file <- x$file
file$path <- tmp
pipeline <- pipeline_init(list(x))
expect_equal(counter_get_names(pipeline$loaded), character(0))
Expand Down
5 changes: 2 additions & 3 deletions tests/testthat/test-class_store.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ tar_test("store_wait_correct_hash()", {
file <- file_init(path = tmp)
writeLines("lines", tmp)
store <- store_init()
store$file <- file
store$resources <- tar_resources(
network = suppressWarnings(tar_resources_network(max_tries = 1L))
)
expect_error(
store_wait_correct_hash(store),
store_wait_correct_hash(store, file),
class = "tar_condition_expire"
)
file_update_hash(file)
expect_silent(store_wait_correct_hash(store))
expect_silent(store_wait_correct_hash(store, file))
})

tar_test("default serialization/unserialization methods", {
Expand Down
24 changes: 13 additions & 11 deletions tests/testthat/test-class_store_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ tar_test("dynamic files work", {
file
}
builder_update_build(x, envir)
expect_equal(x$store$file$path, character(0))
expect_true(is.na(x$store$file$hash))
expect_equal(x$file$path, character(0))
expect_true(is.na(x$file$hash))
builder_update_paths(x, path_store_default())
expect_true(file.exists(x$store$file$path))
expect_true(nzchar(x$store$file$path))
expect_false(is.na(x$store$file$hash))
expect_true(file.exists(x$file$path))
expect_true(nzchar(x$file$path))
expect_false(is.na(x$file$hash))
expect_silent(store_validate(x$store))
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))
builder_update_object(x)
expect_false(file.exists(file.path("_targets", "objects", "abc")))
expect_equal(readLines(x$value$object), "lines")
out <- target_read_value(x)$object
exp <- x$store$file$path
exp <- x$file$path
expect_equal(out, exp)
})

Expand Down Expand Up @@ -57,9 +57,11 @@ tar_test("inherits from tar_external", {
})

tar_test("store_row_path()", {
store <- tar_target(x, "x_value", format = "file")$store
store$file$path <- "path"
expect_equal(store_row_path(store), "path")
target <- tar_target(x, "x_value", format = "file")
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
4 changes: 2 additions & 2 deletions tests/testthat/test-class_target.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ tar_test("target_ensure_value() loads values", {
x <- target_init(name = "abc", expr = quote(2L), format = "rds")
tmp <- tempfile()
saveRDS("abc", tmp)
file <- x$store$file
file <- x$file
file$path <- tmp
pipeline <- pipeline_init(list(x))
for (index in seq_len(2)) {
Expand All @@ -99,7 +99,7 @@ tar_test("target_ensure_dep()", {
pipeline <- pipeline_init(list(x, y))
tmp <- tempfile()
saveRDS("value", tmp)
file <- y$store$file
file <- y$file
file$path <- tmp
expect_null(y$value$object)
for (index in seq_len(2)) {
Expand Down
8 changes: 5 additions & 3 deletions tests/testthat/test-class_torch.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ tar_test("does not inherit from tar_external", {
})

tar_test("store_row_path()", {
store <- tar_target(x, "x_value", format = "torch")$store
store$file$path <- "path"
expect_equal(store_row_path(store), NA_character_)
target <- tar_target(x, "x_value", format = "torch")
store <- target$store
file <- target$file
file$path <- "path"
expect_equal(store_row_path(store, file), NA_character_)
})

tar_test("store_path_from_record()", {
Expand Down
Loading

0 comments on commit faa43ce

Please sign in to comment.