Skip to content

Commit

Permalink
Fix tests for when GRASS is missing from system
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenpawley committed Jan 20, 2025
1 parent cec2fbf commit 81e072d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tests/testthat/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ download_nc_basic <- function() {

get_gisbase <- function() {
if (Sys.info()["sysname"] == "Linux") {
gisBase <- system2("grass", "--config path", stdout = TRUE)
gisBase <- try(system2("grass", "--config path", stdout = TRUE), silent = TRUE)
} else {
gisBase <- Sys.getenv("GRASS_INSTALLATION")
gisBase <- try(Sys.getenv("GRASS_INSTALLATION"), silent = TRUE)
}

if (inherits(gisBase, "try-error")) {
message("GRASS GIS not found on PATH")
return(NULL)
}
return(gisBase)
}
4 changes: 4 additions & 0 deletions tests/testthat/test-initGRASS.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ test_that("testing basic initGRASS", {
})

test_that("testing initialization from SpatRaster", {
skip_if_not(!is.null(gisBase), "GRASS GIS not found on PATH")

meuse_grid <- rast(system.file("ex/meuse.tif", package = "terra"))
loc <- initGRASS(gisBase = gisBase, SG = meuse_grid, override = TRUE)
expect_s3_class(loc, "gmeta")
Expand All @@ -51,6 +53,8 @@ test_that("testing remove_GISRC", {
})

test_that("testing set/unset.GIS_LOCK", {
skip_if_not(!is.null(gisBase), "GRASS GIS not found on PATH")

loc <- initGRASS(
gisBase = gisBase,
gisDbase = testdata$gisDbase,
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-read_VECT.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ test_that("testing read_VECT", {
})

test_that("testing write_VECT", {
skip_if_not(!is.null(gisBase), "GRASS GIS not found on PATH")

shp <- vect(system.file("ex/lux.shp", package = "terra"))
elev <- rast(system.file("ex/elev.tif", package = "terra"))

Expand Down

0 comments on commit 81e072d

Please sign in to comment.