Skip to content

Commit

Permalink
code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Nov 8, 2024
1 parent 7478056 commit f1fd2bf
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tests/testthat/test-tar_repository_cas.R
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,55 @@ tar_test("CAS repository works", {
tar_destroy()
})

tar_test("CAS repository works without list method", {
skip_cran()
skip_if_not_installed("qs")
tar_script({
repository <- tar_repository_cas(
upload = function(key, path) {
if (!file.exists("cas")) {
dir.create("cas", recursive = TRUE)
}
if (dir.exists(path)) {
stop("This CAS repository does not support directory outputs.")
}
file.copy(path, file.path("cas", key))
},
download = function(key, path) {
file.copy(file.path("cas", key), path)
},
exists = function(key) {
file.exists(file.path("cas", key))
},
consistent = FALSE
)
write_file <- function(object) {
writeLines(as.character(object), "file.txt")
"file.txt"
}
list(
tar_target(x, c(2L, 4L), repository = repository),
tar_target(
y,
x,
pattern = map(x),
format = "qs",
repository = repository
),
tar_target(z, write_file(y), format = "file", repository = repository)
)
})
tar_make(callr_function = NULL)
expect_equal(tar_read(x), c(2L, 4L))
expect_equal(unname(tar_read(y)), c(2L, 4L))
expect_equal(unname(tar_read(y, branches = 2L)), 4L)
expect_equal(readLines(tar_read(z)), c("2", "4"))
expect_equal(tar_outdated(callr_function = NULL), character(0L))
unlink(file.path("cas", tar_meta(z)$data))
expect_equal(tar_outdated(callr_function = NULL), "z")
tar_destroy()
})

tar_test("CAS repository works with transient memory and files", {
tar_script({
tar_option_set(memory = "transient")
Expand Down
17 changes: 17 additions & 0 deletions tests/testthat/test-utils_assert.R
Original file line number Diff line number Diff line change
Expand Up @@ -446,3 +446,20 @@ tar_test("tar_assert_meta()", {
file.create(meta)
expect_silent(tar_assert_meta(store))
})

tar_test("tar_assert_match()", {
skip_cran()
expect_silent(
tar_assert_match(
x = "abcde",
pattern = "^abc"
)
)
expect_error(
tar_assert_match(
x = "abcde",
pattern = "^Abc"
),
class = "tar_condition_validate"
)
})

0 comments on commit f1fd2bf

Please sign in to comment.