Skip to content

Commit

Permalink
make references even lighter
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Nov 9, 2024
1 parent 9c53941 commit 83b706c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 43 deletions.
8 changes: 4 additions & 4 deletions R/class_reference.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
reference_new <- function(parent, path = NULL, stage = NULL) {
c(parent = parent, path = path, stage = stage)
c(parent, path, stage)
}

reference_parent <- function(reference) {
as.character(.subset(reference, "parent"))
.subset(reference, 1L)
}

reference_path <- function(reference) {
as.character(.subset(reference, "path"))
.subset(reference, 2L)
}

reference_stage <- function(reference) {
as.character(.subset2(reference, "stage"))
.subset2(reference, 3L)
}

reference_produce_target <- function(reference, pipeline, name) {
Expand Down
22 changes: 4 additions & 18 deletions tests/testthat/test-class_pipeline.R
Original file line number Diff line number Diff line change
Expand Up @@ -306,17 +306,10 @@ tar_test("managing lightweight references to targets in pipelines", {
branch_name <- junction_splits(map$junction)[index]
bud <- pipeline_get_target(local$pipeline, bud_name)
branch <- pipeline_get_target(local$pipeline, branch_name)
expect_equal(
pipeline$targets[[bud_name]],
c(parent = "data")
)
expect_equal(pipeline$targets[[bud_name]], "data")
expect_equal(
pipeline$targets[[branch_name]],
c(
parent = "map",
path = branch$file$path,
stage = branch$file$stage
)
c("map", branch$file$path, branch$file$stage)
)
expect_s3_class(bud, "tar_bud")
expect_s3_class(branch, "tar_branch")
Expand All @@ -327,17 +320,10 @@ tar_test("managing lightweight references to targets in pipelines", {
expect_s3_class(local$pipeline$targets[[bud_name]], "tar_bud")
expect_s3_class(local$pipeline$targets[[branch_name]], "tar_branch")
pipeline_unload_loaded(local$pipeline)
expect_equal(
pipeline$targets[[bud_name]],
c(parent = "data")
)
expect_equal(pipeline$targets[[bud_name]], "data")
expect_equal(
pipeline$targets[[branch_name]],
c(
parent = "map",
path = branch$file$path,
stage = branch$file$stage
)
c("map", branch$file$path, branch$file$stage)
)
}
})
31 changes: 10 additions & 21 deletions tests/testthat/test-class_reference.R
Original file line number Diff line number Diff line change
@@ -1,37 +1,30 @@
tar_test("reference with only parent", {
out <- reference_new(parent = "my_parent")
expect_equal(out, c(parent = "my_parent"))
expect_equal(out, c("my_parent"))
})

tar_test("reference with parent and path", {
tar_test("reference with parent and path but no stage", {
out <- reference_new(parent = "my_parent", path = "my_path")
expect_equal(out, c(parent = "my_parent", path = "my_path"))
})

tar_test("reference with parent and stage", {
out <- reference_new(parent = "my_parent", stage = "my_stage")
expect_equal(out, c(parent = "my_parent", stage = "my_stage"))
expect_equal(out, c("my_parent", "my_path"))
})

tar_test("reference with parent and path", {
out <- reference_new(
parent = "my_parent",
path = "my_path",
stage = "my_stage"
"my_parent",
"my_path",
"my_stage"
)
expect_equal(
out,
c(parent = "my_parent", path = "my_path", stage = "my_stage")
c("my_parent", "my_path", "my_stage")
)
})

tar_test("reference_produce_target() and its inverse", {
skip_cran()
pipeline <- pipeline_init(
list(
target_init(
name = "data",
expr = quote(seq_len(3L))
target_init(name = "data", expr = quote(seq_len(3L))
),
target_init(
name = "map",
Expand All @@ -53,14 +46,10 @@ tar_test("reference_produce_target() and its inverse", {
expect_equal(target_produce_reference(map), map)
bud_reference <- target_produce_reference(bud)
branch_reference <- target_produce_reference(branch)
expect_equal(bud_reference, c(parent = "data"))
expect_equal(bud_reference, "data")
expect_equal(
branch_reference,
c(
parent = "map",
path = branch$file$path,
stage = branch$file$stage
)
c("map", branch$file$path, branch$file$stage)
)
expect_equal(basename(dirname(branch$file$path)), "objects")
expect_equal(basename(dirname(branch$file$stage)), "scratch")
Expand Down

0 comments on commit 83b706c

Please sign in to comment.