Skip to content

Commit

Permalink
skip tests if missing suggested package ncdf4
Browse files Browse the repository at this point in the history
  • Loading branch information
dblodgett-usgs committed Jan 24, 2024
1 parent a5fde17 commit 2700fcf
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 5 deletions.
3 changes: 2 additions & 1 deletion cran-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
* local windows

## Comment
* removed geoknife as suggested package
* removed geoknife as suggested package
* avoid ncdf4 tests if not installed
3 changes: 1 addition & 2 deletions tests/testthat/helper-functions.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
testthat::skip_if_not(require(ncdf4))

require(ncdf4)
library(RNetCDF)
library(sf)

Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test_check_ncdf.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ test_that("line", {
})

test_that("multi polygon holes", {
testthat::skip_if_not(require("ncdf4"))
polygonData <- get_fixture_data("multipolygons_holes")
nc_file <- write_geometry(nc_file=tempfile(), geom_data = polygonData)
nc<-nc_open(nc_file)
Expand All @@ -41,6 +42,7 @@ test_that("multi polygon holes", {
})

test_that("polygon", {
testthat::skip_if_not(require("ncdf4"))
polygonData <- get_fixture_data("polygon")
nc_file <- write_geometry(nc_file=tempfile(), geom_data = polygonData)
nc<-nc_open(nc_file)
Expand All @@ -54,6 +56,7 @@ test_that("polygon", {
})

test_that("basic point works", {
testthat::skip_if_not(require("ncdf4"))
pointData <- get_fixture_data("point")
nc_file <- write_geometry(nc_file=tempfile(), geom_data = pointData)
nc<-nc_open(nc_file)
Expand All @@ -64,6 +67,7 @@ test_that("basic point works", {
})

test_that("a crs gets found correctly", {
testthat::skip_if_not(require("ncdf4"))
polygonData <- sf::read_sf("data/Yahara_alb/Yahara_River_HRUs_alb_eq.shp")
nc_file <- write_geometry(nc_file=tempfile(), geom_data = polygonData)
nc<-nc_open(nc_file)
Expand All @@ -82,6 +86,7 @@ test_that("a crs gets found correctly", {
})

test_that("errors", {
testthat::skip_if_not(require("ncdf4"))
pointData <- get_fixture_data("point")
nc_file <- write_geometry(nc_file=tempfile(), geom_data = pointData)
nc <- nc_open(nc_file, write = TRUE)
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test_line.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
context("line")

test_that("linedata works", {
testthat::skip_if_not(require("ncdf4"))
lineData <- get_fixture_data("linestring")
nc_file <- write_geometry(nc_file=tempfile(), geom_data = lineData)
nc<-nc_open(nc_file)
Expand All @@ -16,6 +17,7 @@ test_that("linedata works", {
})

test_that("multiLine data works", {
testthat::skip_if_not(require("ncdf4"))
lineData <- get_fixture_data("multilinestring")
nc_file <- write_geometry(nc_file=tempfile(), geom_data = lineData)
nc<-nc_open(nc_file)
Expand All @@ -34,6 +36,7 @@ test_that("multiLine data works", {
})

test_that("multiline data frame works", {
testthat::skip_if_not(require("ncdf4"))
lineData <- get_fixture_data("multilinestring")
testdata<-as.data.frame(list("name"=c("test_name"), "id"=c(1)), stringsAsFactors = FALSE)
lineData <- sf::st_sf(dplyr::bind_cols(lineData, testdata))
Expand All @@ -46,6 +49,7 @@ test_that("multiline data frame works", {
})

test_that("shapefile line data works", {
testthat::skip_if_not(require("ncdf4"))
lineData <- sf::st_zm(sf::read_sf("data/NHDLine/NHDLine.shp"))
nc_file <- write_geometry(nc_file=tempfile(),
geom_data = lineData)
Expand Down
4 changes: 3 additions & 1 deletion tests/testthat/test_point.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
context("point")

test_that("Point_timeSeries", {

testthat::skip_if_not(require("ncdf4"))
pointData <- get_fixture_data("point")
nc_file <- write_geometry(nc_file=tempfile(), geom_data = pointData)
nc<-nc_open(nc_file)
Expand Down Expand Up @@ -44,6 +44,7 @@ test_that("multiPoint_timeSeries", {
})

test_that("shapefile_point", {
testthat::skip_if_not(require("ncdf4"))
pointData <- sf::read_sf("data/se_sites/se_sitest.shp")
nc_file <- write_geometry(nc_file = tempfile(), geom_data = pointData)
nc <- nc_open(nc_file)
Expand All @@ -65,6 +66,7 @@ test_that("shapefile_point", {
})

test_that("Point data can be written", {
testthat::skip_if_not(require("ncdf4"))
dataFrame <- read.csv(system.file("extdata/yahara_alb_attributes.csv", package = "ncdfgeom"))
nc_file <- ncdfgeom:::write_point_dsg(nc_file=tempfile(), lats = dataFrame$YCOORD, lons = dataFrame$XCOORD,
alts = rep(0, length(dataFrame$XCOORD)), times = as.POSIXct("1970-01-01 00:00:00 UTC", tz = "UTC"),
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test_poly.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
context("polygon")

test_that("data for basic polygon", {
testthat::skip_if_not(require("ncdf4"))
polygonData <- get_fixture_data("polygon")
nc_file <- write_geometry(nc_file=tempfile(), geom_data = polygonData)
nc<-nc_open(nc_file)
Expand Down Expand Up @@ -42,6 +43,7 @@ test_that("data for basic polygon", {
})

test_that("polygon with a hole.", {
testthat::skip_if_not(require("ncdf4"))
polygonData <- get_fixture_data("polygon_hole")
nc_file <- write_geometry(nc_file=tempfile(), geom_data = polygonData)
nc<-nc_open(nc_file)
Expand Down Expand Up @@ -69,6 +71,7 @@ test_that("polygon with a hole.", {
})

test_that("multipolygon.", {
testthat::skip_if_not(require("ncdf4"))
polygonData <- get_fixture_data("multipolygon")
nc_file <- write_geometry(nc_file=tempfile(), geom_data = polygonData)
nc<-nc_open(nc_file)
Expand All @@ -86,6 +89,7 @@ test_that("multipolygon.", {
})

test_that("multipolygon with a hole.", {
testthat::skip_if_not(require("ncdf4"))
polygonData <-get_fixture_data("multipolygon_hole")
nc_file <- write_geometry(nc_file=tempfile(), geom_data = polygonData)
nc<-nc_open(nc_file)
Expand Down Expand Up @@ -118,6 +122,7 @@ test_that("multipolygon with a hole.", {
})

test_that("multipolygons with holes.", {
testthat::skip_if_not(require("ncdf4"))
polygonData <- get_fixture_data("multipolygons_holes")
nc_file <- write_geometry(nc_file=tempfile(), geom_data = polygonData)
nc<-nc_open(nc_file)
Expand All @@ -141,6 +146,7 @@ test_that("multipolygons with holes.", {
})

test_that("A whole shapefile can be written", {
testthat::skip_if_not(require("ncdf4"))
polygonData <- read_sf("data/Yahara_alb/Yahara_River_HRUs_alb_eq.shp", check_ring_dir = TRUE)
nc_file <- write_geometry(nc_file=tempfile(), geom_data = polygonData)
nc<-nc_open(nc_file)
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test_read-write_attribute_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
context("instance attributes")

test_that("A dataframe can be round tripped to netCDF.", {
testthat::skip_if_not(require("ncdf4"))
dataFrame <- sf::st_set_geometry(sf::read_sf("data/NHDLine/NHDLine.shp"), NULL)
units<-c("unitless","date","unitless","unitless","unitless","km","unitless","unitless","unknown")
nc_file <- write_attribute_data(nc_file=tempfile(), att_data = dataFrame, instance_dim_name = "instance", units = units)
Expand All @@ -23,6 +24,7 @@ test_that("A dataframe can be round tripped to netCDF.", {
})

test_that("instance data can be added to an existing netcdf file.", {
testthat::skip_if_not(require("ncdf4"))
hucPolygons <- read_sf(system.file('extdata','example_huc_eta.json', package = 'ncdfgeom'))
hucPolygons <- st_set_geometry(hucPolygons, NULL)
outFile <- tempfile()
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/test_read-write_timeseries_dsg.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
context("orthogonal netcdf timeseries")

test_that("Create basic DSG file", {

testthat::skip_if_not(require("ncdf4"))
# NOTE: this code has been moved to helper files but was left here to not mess with it.
nc_file<-tempfile(fileext = ".nc")
nc_summary<-'test summary'
Expand Down Expand Up @@ -342,6 +342,7 @@ test_that("Create basic DSG file", {
})

test_that('soilmoisturetools data writes as expected', {
testthat::skip_if_not(require("ncdf4"))
ok<-readRDS("data/soilmoisturetools/ok.rds")
ok_meta<-readRDS("data/soilmoisturetools/ok_meta.rds")
attributes <- list(
Expand Down

0 comments on commit 2700fcf

Please sign in to comment.