Skip to content

Commit

Permalink
Merge pull request #57 from njtierney/crew-tests
Browse files Browse the repository at this point in the history
Add tests with multiple `crew` workers
  • Loading branch information
njtierney authored Apr 29, 2024
2 parents 527b509 + 3c116ab commit c148f7b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Imports:
rlang,
cli
Suggests:
crew,
terra,
testthat (>= 3.0.0),
withr
Expand Down
39 changes: 39 additions & 0 deletions tests/testthat/test-tar-terra.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,25 @@ targets::tar_test("tar_terra_rast() works", {
)
})

targets::tar_test("tar_terra_rast() works with multiple workers (tests marshaling/unmarshaling)", {
targets::tar_script({
targets::tar_option_set(controller = crew::crew_controller_local(workers = 2))
list(
geotargets::tar_terra_rast(
rast1,
terra::rast(system.file("ex/elev.tif", package = "terra"))
),
geotargets::tar_terra_rast(
rast2,
terra::rast(system.file("ex/elev.tif", package = "terra"))
)
)
})
targets::tar_make()
expect_true(all(is.na(targets::tar_meta()$error)))
expect_s4_class(targets::tar_read(rast1), "SpatRaster")
})

targets::tar_test("tar_terra_vect() works", {
targets::tar_script({
lux_area <- function(projection = "EPSG:4326") {
Expand Down Expand Up @@ -48,3 +67,23 @@ targets::tar_test("tar_terra_vect() works", {
expect_snapshot(y)
expect_equal(terra::values(x), terra::values(y))
})

targets::tar_test("tar_terra_vect() works with multiple workers (tests marshaling/unmarshaling)", {
targets::tar_script({
targets::tar_option_set(controller = crew::crew_controller_local(workers = 2))
list(
geotargets::tar_terra_vect(
vect1,
terra::vect(system.file("ex", "lux.shp", package = "terra"))
),
geotargets::tar_terra_vect(
vect2,
terra::vect(system.file("ex", "lux.shp", package = "terra"))
)
)
})
targets::tar_make()
expect_true(all(is.na(targets::tar_meta()$error)))
expect_s4_class(targets::tar_read(vect1), "SpatVector")
})

0 comments on commit c148f7b

Please sign in to comment.