Skip to content

Commit

Permalink
add outputs tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Hipson committed Oct 8, 2024
1 parent d69dd2f commit 6f4aa94
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ S3method(roclet_process,roclet_maestroHours)
S3method(roclet_process,roclet_maestroInputs)
S3method(roclet_process,roclet_maestroLogLevel)
S3method(roclet_process,roclet_maestroMonths)
S3method(roclet_process,roclet_maestroOutputs)
S3method(roclet_process,roclet_maestroSkip)
S3method(roclet_process,roclet_maestroStartTime)
S3method(roclet_process,roclet_maestroTz)
Expand All @@ -15,6 +16,7 @@ S3method(roxy_tag_parse,roxy_tag_maestroHours)
S3method(roxy_tag_parse,roxy_tag_maestroInputs)
S3method(roxy_tag_parse,roxy_tag_maestroLogLevel)
S3method(roxy_tag_parse,roxy_tag_maestroMonths)
S3method(roxy_tag_parse,roxy_tag_maestroOutputs)
S3method(roxy_tag_parse,roxy_tag_maestroSkip)
S3method(roxy_tag_parse,roxy_tag_maestroStartTime)
S3method(roxy_tag_parse,roxy_tag_maestroTz)
Expand Down
47 changes: 47 additions & 0 deletions R/roxy_maestro.R
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,16 @@ roxy_tag_parse.roxy_tag_maestroInputs <- function(x) {
x$raw <- x$raw |>
trimws()

if (x$raw == "") {
roxygen2::roxy_tag_warning(
x,
glue::glue(
"Empty maestroInputs. If pipeline doesn't take inputs, remove maestroInputs tag."
)
)
return(x)
}

x$val <- strsplit(x$raw, "\\s+")[[1]]

x
Expand All @@ -456,3 +466,40 @@ roclet_process.roclet_maestroInputs <- function(x, blocks, env, base_path) {
node = blocks[[1]]$object$topic
)
}

# maestroOutputs ----------------------------------------------------------

#' @exportS3Method
roxy_tag_parse.roxy_tag_maestroOutputs <- function(x) {

x$raw <- x$raw |>
trimws()

if (x$raw == "") {
roxygen2::roxy_tag_warning(
x,
glue::glue(
"Empty maestroOutputs. If pipeline doesn't take inputs, remove maestroOutputs tag."
)
)
return(x)
}

x$val <- strsplit(x$raw, "\\s+")[[1]]

x
}

maestroOutputs_roclet <- function() {
roxygen2::roclet("maestroOutputs")
}

#' @exportS3Method
roclet_process.roclet_maestroOutputs <- function(x, blocks, env, base_path) {
tags <- roxygen2::block_get_tag(blocks[[1]], "maestroOutputs")
list(
val = tags$val,
node = blocks[[1]]$object$topic
)
}

32 changes: 31 additions & 1 deletion tests/testthat/test-roclets.R
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,39 @@ test_that("invalid maestroMonths warns", {
test_that("parse maestroInputs works", {
res <- roxygen2::roc_proc_text(
maestroInputs_roclet(),
readLines(test_path("test_pipelines/test_pipeline_inputs.R"))
readLines(test_path("test_pipelines/test_pipeline_inputs_good.R"))
)

expect_type(res$val, "character")
expect_length(res$val, 3L)
})

test_that("parse maestroInputs warns if empty", {
res <- roxygen2::roc_proc_text(
maestroInputs_roclet(),
readLines(test_path("test_pipelines/test_pipeline_inputs_bad.R"))
) |>
expect_warning()

expect_null(res$val)
})

test_that("parse maestroOutputs works", {
res <- roxygen2::roc_proc_text(
maestroOutputs_roclet(),
readLines(test_path("test_pipelines/test_pipeline_outputs_good.R"))
)

expect_type(res$val, "character")
expect_length(res$val, 3L)
})

test_that("parse maestroOutputs warns if empty", {
res <- roxygen2::roc_proc_text(
maestroOutputs_roclet(),
readLines(test_path("test_pipelines/test_pipeline_outputs_bad.R"))
) |>
expect_warning()

expect_null(res$val)
})
4 changes: 4 additions & 0 deletions tests/testthat/test_pipelines/test_pipeline_inputs_bad.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#' @maestroInputs
some_inputs <- function(.input) {

}
4 changes: 4 additions & 0 deletions tests/testthat/test_pipelines/test_pipeline_outputs_bad.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#' @maestroOutputs
some_outputs <- function() {

}
4 changes: 4 additions & 0 deletions tests/testthat/test_pipelines/test_pipeline_outputs_good.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#' @maestroOutputs fun1 fun2 fun3
some_outputs <- function() {

}

0 comments on commit 6f4aa94

Please sign in to comment.