Skip to content

Commit

Permalink
Skip netCDF block size test if terra cannot write netCDF
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaston committed Jul 5, 2023
1 parent 02dae55 commit dd56996
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions tests/testthat/test_helper_blocksize.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2021 ISciences, LLC.
# Copyright (c) 2021-2023 ISciences, LLC.
# All rights reserved.
#
# This software is licensed under the Apache License, Version 2.0 (the "License").
Expand Down Expand Up @@ -30,20 +30,22 @@ test_that('blockSize reports block size in row-col order', {
# netCDF uses a different code path, so copy our test input to netCDF format
# and repeat. GDAL doesn't let us control the block size, so hopefully it
# is stable.
nc_fname <- tempfile(fileext = '.nc')
suppressWarnings({
terra::writeRaster(terra::rast(landcov_fname), nc_fname, gdal=c('FORMAT=NC4', 'COMPRESS=DEFLATE'))
})

expect_equal(
.blockSize(raster::raster(nc_fname)),
c(1, 3840)
)

expect_equal(
.blockSize(terra::rast(nc_fname)),
c(1, 3840)
)

file.remove(nc_fname)
if ('netCDF' %in% terra::gdal(drivers=TRUE)$name) {
nc_fname <- tempfile(fileext = '.nc')
suppressWarnings({
terra::writeRaster(terra::rast(landcov_fname), nc_fname, gdal=c('FORMAT=NC4', 'COMPRESS=DEFLATE'))
})

expect_equal(
.blockSize(raster::raster(nc_fname)),
c(1, 3840)
)

expect_equal(
.blockSize(terra::rast(nc_fname)),
c(1, 3840)
)

file.remove(nc_fname)
}
})

0 comments on commit dd56996

Please sign in to comment.