Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qgis_sanitize_arguments(): fix loss of special arguments #79

Merged
merged 3 commits into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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