Skip to content

Commit

Permalink
Merge pull request #79 from florisvdh/special_args
Browse files Browse the repository at this point in the history
qgis_sanitize_arguments(): fix loss of special arguments
  • Loading branch information
paleolimbot authored Jan 21, 2022
2 parents 4a79540 + 0b86162 commit 3768999
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions R/qgis-arguments.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,14 @@ qgis_sanitize_arguments <- function(algorithm, ..., .algorithm_arguments = qgis_
message(glue("Ignoring unknown input '{ arg_name }'"))
}
}
special_args <- user_args[c("PROJECT_PATH", "ELLIPSOID")]
special_args <- special_args[!sapply(special_args, is.null)]

# generate argument list template and populate user-supplied values
args <- rep(list(qgis_default_value()), nrow(arg_meta))
names(args) <- arg_meta$name
args[intersect(names(args), names(user_args))] <- user_args[intersect(names(args), names(user_args))]
args <- c(args, special_args)

# get argument specs to pass to as_qgis_argument()
arg_spec <- Map(
Expand Down
17 changes: 16 additions & 1 deletion tests/testthat/test-qgis-arguments.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,27 @@ test_that("qgis_sanitize_arguments() ignores unknown inputs", {
unknown_arg = 1,
.algorithm_arguments = tibble::tibble(name = character())
),
rlang::set_names(list(), character())
list()
),
"Ignoring unknown input"
)
})

test_that("qgis_sanitize_arguments() doesn't drop special arguments", {
special <- list(PROJECT_PATH = "some_path", ELLIPSOID = "some_ellipse")
for (i in 1:3) {
if (i == 3) i <- 1:2
expect_identical(
qgis_sanitize_arguments(
"some_algorithm",
!!!special[i],
.algorithm_arguments = tibble::tibble(name = character())
),
!!special[i]
)
}
})

test_that("qgis_sanitize_arguments() accepts multiple input arguments", {
sanitized <- qgis_sanitize_arguments(
"some_algorithm",
Expand Down

0 comments on commit 3768999

Please sign in to comment.