From b3df8c2897c08485ad2eb16b5bfec6fff07829fb Mon Sep 17 00:00:00 2001 From: Eric Scott Date: Tue, 9 Apr 2024 17:08:16 -0700 Subject: [PATCH 1/4] add tests with crew_controller_local() --- DESCRIPTION | 1 + tests/testthat/test-tar-terra.R | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/DESCRIPTION b/DESCRIPTION index b9560e3..ead2fbe 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -36,6 +36,7 @@ Imports: rlang, cli Suggests: + crew, terra, testthat (>= 3.0.0) Config/testthat/edition: 3 diff --git a/tests/testthat/test-tar-terra.R b/tests/testthat/test-tar-terra.R index 15f0175..5e44838 100644 --- a/tests/testthat/test-tar-terra.R +++ b/tests/testthat/test-tar-terra.R @@ -17,6 +17,29 @@ targets::tar_test("tar_terra_rast() works", { ) }) +targets::tar_test("tar_terra_rast() works with multiple workers", { + targets::tar_script({ + targets::tar_option_set(controller = crew::crew_controller_local(workers = 2)) + list( + geotargets::tar_terra_rast( + test1, + terra::rast(system.file("ex/elev.tif", package = "terra")) + ), + geotargets::tar_terra_rast( + test2, + terra::rast(system.file("ex/elev.tif", package = "terra")) + ), + geotargets::tar_terra_rast( + combined, + rast(list(test1, test2)) + ) + ) + }) + targets::tar_make() + expect_s4_class(targets::tar_read(test1), "SpatRaster") + expect_s4_class(targets::tar_read(test2), "SpatRaster") +}) + targets::tar_test("tar_terra_vect() works", { targets::tar_script({ lux_area <- function(projection = "EPSG:4326") { @@ -48,3 +71,5 @@ targets::tar_test("tar_terra_vect() works", { expect_snapshot(y) expect_equal(terra::values(x), terra::values(y)) }) + + From 7e45853648dab48a5dc050e2a7cbf5e33f891e36 Mon Sep 17 00:00:00 2001 From: Eric Scott Date: Thu, 11 Apr 2024 09:12:06 -0700 Subject: [PATCH 2/4] test using crew --- tests/testthat/test-tar-terra.R | 34 +++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/tests/testthat/test-tar-terra.R b/tests/testthat/test-tar-terra.R index 5e44838..45c9234 100644 --- a/tests/testthat/test-tar-terra.R +++ b/tests/testthat/test-tar-terra.R @@ -22,22 +22,26 @@ targets::tar_test("tar_terra_rast() works with multiple workers", { targets::tar_option_set(controller = crew::crew_controller_local(workers = 2)) list( geotargets::tar_terra_rast( - test1, + rast_raw, terra::rast(system.file("ex/elev.tif", package = "terra")) ), geotargets::tar_terra_rast( - test2, - terra::rast(system.file("ex/elev.tif", package = "terra")) + rast_plus, + rast_raw + 1 + ), + geotargets::tar_terra_rast( + rast_minus, + rast_raw - 1 ), geotargets::tar_terra_rast( combined, - rast(list(test1, test2)) + rast(unname(list(rast_plus, rast_minus))) ) ) }) targets::tar_make() - expect_s4_class(targets::tar_read(test1), "SpatRaster") - expect_s4_class(targets::tar_read(test2), "SpatRaster") + expect_true(all(is.na(tar_meta()$error))) + expect_snapshot(tar_read(combined)) }) targets::tar_test("tar_terra_vect() works", { @@ -72,4 +76,22 @@ targets::tar_test("tar_terra_vect() works", { expect_equal(terra::values(x), terra::values(y)) }) +targets::tar_test("tar_terra_vect() works with multiple workers", { + 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_s4_class(targets::tar_read(vect1), "SpatVector") + expect_s4_class(targets::tar_read(vect2), "SpatVector") +}) From d117e39e912e4c4b807440e223eaf68196e27672 Mon Sep 17 00:00:00 2001 From: Eric Scott Date: Wed, 24 Apr 2024 13:53:29 -0700 Subject: [PATCH 3/4] fix tests and make more minimal --- tests/testthat/test-tar-terra.R | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/tests/testthat/test-tar-terra.R b/tests/testthat/test-tar-terra.R index 53c91e6..27c387a 100644 --- a/tests/testthat/test-tar-terra.R +++ b/tests/testthat/test-tar-terra.R @@ -22,26 +22,17 @@ targets::tar_test("tar_terra_rast() works with multiple workers", { targets::tar_option_set(controller = crew::crew_controller_local(workers = 2)) list( geotargets::tar_terra_rast( - rast_raw, + rast1, terra::rast(system.file("ex/elev.tif", package = "terra")) ), geotargets::tar_terra_rast( - rast_plus, - rast_raw + 1 - ), - geotargets::tar_terra_rast( - rast_minus, - rast_raw - 1 - ), - geotargets::tar_terra_rast( - combined, - rast(unname(list(rast_plus, rast_minus))) + rast2, + terra::rast(system.file("ex/elev.tif", package = "terra")) ) ) }) targets::tar_make() - expect_true(all(is.na(tar_meta()$error))) - expect_snapshot(tar_read(combined)) + expect_true(all(is.na(targets::tar_meta()$error))) }) targets::tar_test("tar_terra_vect() works", { @@ -91,7 +82,6 @@ targets::tar_test("tar_terra_vect() works with multiple workers", { ) }) targets::tar_make() - expect_s4_class(targets::tar_read(vect1), "SpatVector") - expect_s4_class(targets::tar_read(vect2), "SpatVector") + expect_true(all(is.na(targets::tar_meta()$error))) }) From 3c116ab6cc97f8123b5a07545c078fd43dd7a6db Mon Sep 17 00:00:00 2001 From: Eric Scott Date: Wed, 24 Apr 2024 13:58:13 -0700 Subject: [PATCH 4/4] test unmarshaling --- tests/testthat/test-tar-terra.R | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-tar-terra.R b/tests/testthat/test-tar-terra.R index 27c387a..802debf 100644 --- a/tests/testthat/test-tar-terra.R +++ b/tests/testthat/test-tar-terra.R @@ -17,7 +17,7 @@ targets::tar_test("tar_terra_rast() works", { ) }) -targets::tar_test("tar_terra_rast() works with multiple workers", { +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( @@ -33,6 +33,7 @@ targets::tar_test("tar_terra_rast() works with multiple workers", { }) 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", { @@ -67,7 +68,7 @@ targets::tar_test("tar_terra_vect() works", { expect_equal(terra::values(x), terra::values(y)) }) -targets::tar_test("tar_terra_vect() works with multiple workers", { +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( @@ -83,5 +84,6 @@ targets::tar_test("tar_terra_vect() works with multiple workers", { }) targets::tar_make() expect_true(all(is.na(targets::tar_meta()$error))) + expect_s4_class(targets::tar_read(vect1), "SpatVector") })