Commit 5fddab41 authored by Blodgett, David L.'s avatar Blodgett, David L.

test cleanup

parent 31e5b3d1
......@@ -2,6 +2,8 @@ library(RNetCDF)
library(ncdf4)
library(sf)
library(sp)
nc_file<-'data/test_output.nc'
compareSP <- function(polygonData, returnPolyData) {
polygonData <- sf::as_Spatial(polygonData)
returnPolyData <- sf::as_Spatial(returnPolyData)
......
context("orthogonal netcdf timeseries")
test_that("Create basic DSG file",{
test_that("Create basic DSG file", {
unlink(nc_file)
nc_summary<-'test summary'
nc_date_create<-'2099-01-01'
nc_creator_name='test creator'
......@@ -12,8 +13,6 @@ test_that("Create basic DSG file",{
creator_name=nc_creator_name,creator_email=nc_creator_email,
project=nc_project, processing_level=nc_proc_level)
nc_file<-'data/test_output.nc'
test_data <- get_sample_timeseries_data()
testnc<-write_timeseries_dsg(nc_file,
......@@ -149,26 +148,6 @@ test_that("Create basic DSG file",{
expect_equivalent(ncvar_get(testnc,varid="BCCA_0-125deg_pr_day_ACCESS1-0_rcp45_r1i1p1")[,71],test_data$all_data$`71`)
expect_equivalent(testnc$var$`BCCA_0-125deg_pr_day_ACCESS1-0_rcp45_r1i1p1`$units,"mm/d")
expect_equivalent(ncatt_get(testnc,varid=0,"summary")$value,'test summary')
expect("duplicate" %in% names(testnc$var), failure_message = names(testnc$var))
nc_close(testnc)
test_data$meta <- list(name = "character", long_name = "test")
char_test <- dplyr::mutate_all(test_data$var_data, as.character)
testnc<-write_timeseries_dsg(nc_file,
names(test_data$var_data),
test_data$lats, test_data$lons,
test_data$time, char_test,
test_data$alts,
data_unit=test_data$units,
data_prec='char',
data_metadata=test_data$meta,
attributes=global_attributes,
add_to_existing = TRUE)
testnc<-nc_open(nc_file)
expect("character" %in% names(testnc$var), failure_message = names(testnc$var))
# covers no altitude and iteration to write many rows.
test_dat2 <- dplyr::bind_rows(test_data$var_data, test_data$var_data)
......@@ -181,7 +160,7 @@ test_that("Create basic DSG file",{
data_prec='double',
data_metadata=test_data$meta,
attributes=global_attributes)
testnc<-nc_open(testnc)
expect(testnc$dim$time$len == 1460)
......@@ -199,6 +178,31 @@ test_that("Create basic DSG file",{
testnc<-nc_open(testnc)
expect(testnc$dim$time$len == 1460)
testthat::skip_on_cran()
expect("duplicate" %in% names(testnc$var), failure_message = names(testnc$var))
nc_close(testnc)
test_data$meta <- list(name = "character", long_name = "test")
char_test <- dplyr::mutate_all(test_data$var_data, as.character)
testnc<-write_timeseries_dsg(nc_file,
names(test_data$var_data),
test_data$lats, test_data$lons,
test_data$time, char_test,
test_data$alts,
data_unit=test_data$units,
data_prec='char',
data_metadata=test_data$meta,
attributes=global_attributes,
add_to_existing = TRUE)
testnc<-nc_open(nc_file)
expect("character" %in% names(testnc$var), failure_message = names(testnc$var))
})
test_that("bork the file", {
test_data <- get_sample_timeseries_data()
testlist<-read_timeseries_dsg(nc_file)
......@@ -314,4 +318,5 @@ test_that('soilmoisturetools data writes as expected', {
nc <- nc_open(nc_file)
expect(file.exists(nc_file))
unlink(nc_file)
})
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment