Skip to content

Commit

Permalink
test-qgis-{help,run-algorithm}.R: add tests for alg deprecation warning
Browse files Browse the repository at this point in the history
  • Loading branch information
florisvdh committed Jan 10, 2024
1 parent 4b68ce3 commit a5b82a2
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/testthat/test-qgis-help.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,32 @@ test_that("algorithms with no outputs have zero-row qgis_get_output_specs()", {
skip_if_not(has_qgis())
expect_identical(nrow(qgis_get_output_specs("native:spatialiteexecutesql")), 0L)
})

test_that("Help functions & qgis_function() yield a warning with deprecated algorithms only", {
skip_if_not(has_qgis())
skip_if_not(qgis_using_json_output())
algs <- qgis_algorithms()
skip_if_not(
"deprecated" %in% colnames(algs) && sum(algs$deprecated) > 0,
paste(
"There are no deprecated algorithms available.",
"Rewrite this test to simulate deprecated algorithms."
)
)
local_edition(3) # if more than one warning pops up, it should be apparent from
# testthat output (only the first warning is swallowed in the
# third edition of testthat)

alg_deprecated <- sample(algs$algorithm[algs$deprecated], 1)
alg_non_deprecated <- sample(algs$algorithm[!algs$deprecated], 1)
expect_warning(capture.output(qgis_show_help(alg_deprecated)))
expect_no_warning(capture.output(qgis_show_help(alg_non_deprecated)))
expect_warning(qgis_get_description(alg_deprecated))
expect_no_warning(qgis_get_description(alg_non_deprecated))
expect_warning(qgis_get_argument_specs(alg_deprecated))
expect_no_warning(qgis_get_argument_specs(alg_non_deprecated))
expect_warning(qgis_get_output_specs(alg_deprecated))
expect_no_warning(qgis_get_output_specs(alg_non_deprecated))
expect_warning(qgis_function(alg_deprecated))
expect_no_warning(qgis_function(alg_non_deprecated))
})
26 changes: 26 additions & 0 deletions tests/testthat/test-qgis-run-algorithm.R
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,29 @@ test_that(glue("qgis_run_algorithm() succeeds when it uses an aggregates input a
expect_identical(ll_res$depth, depth_vals)
expect_identical(ll_res$name[1], "a,f,k,p,u")
})

test_that("qgis_run_algorithm() yields a warning with a deprecated algorithm", {
skip_if_not(has_qgis())
skip_if_not(qgis_using_json_output())
algs <- qgis_algorithms()
skip_if_not(
"deprecated" %in% colnames(algs) && sum(algs$deprecated) > 0,
"There are no deprecated algorithms available."
)
skip_if_not(
"native:raisewarning" %in% algs$algorithm[algs$deprecated],
"'native:raisewarning' is not an available deprecated algorithm."
)
local_edition(3) # if more than one warning pops up, it should be apparent from
# testthat output (only the first warning is swallowed in the
# third edition of testthat)

suppressMessages(
expect_warning(
qgis_run_algorithm(
"native:raisewarning",
MESSAGE = "Some text than won't come back though."
)
)
)
})

0 comments on commit a5b82a2

Please sign in to comment.