Skip to content

Commit

Permalink
Complete working_directory tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Mar 18, 2024
1 parent afe4ee9 commit 4543c53
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 1 deletion.
45 changes: 45 additions & 0 deletions tests/testthat/test-tar_quarto_rep.R
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,51 @@ targets::tar_test("tar_quarto_rep() run", {
expect_equal(out, status_completed())
})

targets::tar_test("tar_quarto_rep() with custom working directory", {
skip_on_cran()
skip_rmarkdown()
lines <- c(
"---",
"title: report",
"output_format: html",
"params:",
" par: \"default value\"",
"---",
"",
"```{r}",
"targets::tar_read(upstream, store = '../_targets')",
"file.create(\"here\")",
"```"
)
writeLines(lines, "report.qmd")
dir.create("out")
on.exit(unlink("out", recursive = TRUE))
targets::tar_script({
library(tarchetypes)
list(
tar_target(upstream, "UPSTREAM_SUCCEEDED"),
tar_quarto_rep(
report,
"report.qmd",
execute_params = data.frame(
par = "parval1",
stringsAsFactors = FALSE
),
working_directory = "out",
batches = 1
)
)
})
expect_false(file.exists("here"))
expect_false(file.exists(file.path("out", "here")))
suppressMessages(targets::tar_make(callr_function = NULL))
expect_false(file.exists("here"))
expect_true(file.exists(file.path("out", "here")))
lines <- suppressWarnings(readLines(list.files(pattern = "html$")[1L]))
expect_true(any(grepl("UPSTREAM_SUCCEEDED", lines)))
expect_equal(targets::tar_outdated(callr_function = NULL), character(0L))
})

targets::tar_test("tar_quarto_rep() run with output_file specified", {
skip_on_cran()
skip_quarto()
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-tar_render.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ targets::tar_test("tar_render() with custom output_file and working dir", {
"---",
"",
"```{r}",
"tar_read(upstream, store = '../_targets')",
"targets::tar_read(upstream, store = '../_targets')",
"file.create(\"here\")",
"```"
)
Expand Down
45 changes: 45 additions & 0 deletions tests/testthat/test-tar_render_rep.R
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,51 @@ targets::tar_test("tar_render_rep() with output_file and _files", {
}
})

targets::tar_test("tar_render_rep() with custom working directory", {
skip_on_cran()
skip_rmarkdown()
lines <- c(
"---",
"title: report",
"output_format: html_document",
"params:",
" par: \"default value\"",
"---",
"",
"```{r}",
"tar_read(upstream, store = '../_targets')",
"file.create(\"here\")",
"```"
)
writeLines(lines, "report.Rmd")
dir.create("out")
on.exit(unlink("out", recursive = TRUE))
targets::tar_script({
library(tarchetypes)
list(
tar_target(upstream, "UPSTREAM_SUCCEEDED"),
tar_render_rep(
report,
"report.Rmd",
params = data.frame(
par = "parval1",
stringsAsFactors = FALSE
),
working_directory = "out",
batches = 1
)
)
})
expect_false(file.exists("here"))
expect_false(file.exists(file.path("out", "here")))
suppressMessages(targets::tar_make(callr_function = NULL))
expect_false(file.exists("here"))
expect_true(file.exists(file.path("out", "here")))
lines <- readLines(list.files(pattern = "html$")[1L])
expect_true(any(grepl("UPSTREAM_SUCCEEDED", lines)))
expect_equal(targets::tar_outdated(callr_function = NULL), character(0L))
})

targets::tar_test("tar_render_rep_run_params", {
params <- tibble::tibble(param1 = letters[seq_len(4)])
out <- tar_render_rep_run_params(params, 1)
Expand Down

0 comments on commit 4543c53

Please sign in to comment.