context("ISSR800.wcs() -- requires internet connection") # NOTES: # * ISSR800.wcs() will stop() if rast() fails test_that("works as expected", { skip_if_offline() skip_on_cran() skip_if_not_installed("sf") skip_if_not_installed("terra", minimum_version = "1.8.93") skip_if_not(terra::proj_ok()) x <- NULL # check built-in metadata expect_true(inherits(WCS_details("ISSR800"), 'data.frame')) # make a request # typical failure modes: # * network error # * server maintenance # * incomplete terra package installation, missing proj.db x <- try( ISSR800.wcs( aoi = list(aoi = c(-114.16, 47.6,-114.15, 47.7), crs = 'EPSG:4326'), var = 'paws', quiet = TRUE ) ) expect_true(inherits(x, 'SpatRaster') || inherits(x, 'try-error')) # if it downloaded if (inherits(x, 'SpatRaster')) { # expected dimensions expect_true(all(dim(x) == c(14, 4, 1))) # no RAT expect_null(terra::cats(x)[[1]]) } }) test_that("categorical data", { skip_if_offline() skip_on_cran() skip_if_not_installed("sf") skip_if_not_installed("terra", minimum_version = "1.8.93") skip_if_not(terra::proj_ok()) x <- NULL # make a request # typical failure modes: # * network error # * server maintenance # * incomplete terra package installation, missing proj.db x <- try( ISSR800.wcs( aoi = list(aoi = c(-114.16, 47.6,-114.15, 47.7), crs = 'EPSG:4326'), var = 'texture_2550cm', quiet = TRUE ) ) expect_true(inherits(x, 'SpatRaster') || inherits(x, 'try-error')) # if it downloaded if (inherits(x, 'SpatRaster')) { # expected dimensions expect_true(all(dim(x) == c(14, 4, 1))) # there must be a RAT expect_false(is.null(terra::levels(x))) expect_equivalent(colnames(terra::cats(x)[[1]]), c('ID','class','hex','names')) } # make a request # typical failure modes: # * network error # * server maintenance # * incomplete terra package installation, missing proj.db x2 <- try( ISSR800.wcs( aoi = list(aoi = c(-114.16, 47.6,-114.15, 47.7), crs = 'EPSG:4326'), var = 'suborder', quiet = TRUE ) ) expect_true(inherits(x2, 'SpatRaster') || inherits(x2, 'try-error')) if (!inherits(x2, 'try-error')) { expect_equivalent(colnames(terra::cats(x2)[[1]]), c('ID', 'suborder')) } })