Skip to content

Commit

Permalink
add test for options
Browse files Browse the repository at this point in the history
  • Loading branch information
Aariq committed Apr 11, 2024
1 parent 90ef58d commit 35a395a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ Imports:
cli
Suggests:
terra,
testthat (>= 3.0.0)
testthat (>= 3.0.0),
withr
Config/testthat/edition: 3
URL: https://github.com/njtierney/geotargets
BugReports: https://github.com/njtierney/geotargets/issues
56 changes: 36 additions & 20 deletions tests/testthat/test-geotargets-option.R
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
# test_that("geotargets_options_get() retrieves options in correct priority", {
# withr::with_envvar(
#
# )
# })
targets::tar_test("geotargets_options_get() retrieves options in correct priority", {
#options takes precedent over env var
withr::with_envvar(
c("GEOTARGETS_GDAL_RASTER_DRIVER" = "COG"),
withr::with_options(list("geotargets.gdal.raster.driver" = "GIF"), {
targets::tar_script({
list(
targets::tar_target(
opt,
geotargets::geotargets_option_get("gdal.raster.driver")
)
)
})
targets::tar_make()
expect_equal(geotargets::geotargets_option_get("gdal.raster.driver"), "GIF")
})

targets::tar_test("Options are distributed to workers", {
targets::tar_script({
Sys.setenv("GEOTARGETS_GDAL_RASTER_DRIVER" = "GeoJSON")
targets::tar_option_set(
controller = crew::crew_controller_local(workers = 2)
)
list(
targets::tar_target(
opt,
Sys.getenv("GEOTARGETS_GDAL_RASTER_DRIVER")
)
)
})
targets::tar_make()
expect_equal(targets::tar_read(opt), "GeoJSON")
)
})



# targets::tar_test("Options are distributed to workers", {
# targets::tar_script({
# Sys.setenv("GEOTARGETS_GDAL_RASTER_DRIVER" = "COG")
# targets::tar_option_set(
# controller = crew::crew_controller_local(workers = 2)
# )
# list(
# targets::tar_target(
# opt,
# Sys.getenv("GEOTARGETS_GDAL_RASTER_DRIVER")
# )
# )
# })
# targets::tar_make()
# expect_equal(targets::tar_read(opt), "COG")
# })

0 comments on commit 35a395a

Please sign in to comment.