From 370ea0b02792db347a348ea45b354d55277bfabe Mon Sep 17 00:00:00 2001 From: "Andrew G. Brown" Date: Mon, 4 Jan 2021 15:21:03 -0800 Subject: [PATCH] Validations and tests RE: #149 #146 --- misc/validate-NASIS-results.R | 67 +++++++++++++++++++ tests/testthat/test-getHzErrorsNASIS.R | 2 +- .../test-get_text_notes_from_NASIS_db.R | 3 + 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 misc/validate-NASIS-results.R create mode 100644 tests/testthat/test-get_text_notes_from_NASIS_db.R diff --git a/misc/validate-NASIS-results.R b/misc/validate-NASIS-results.R new file mode 100644 index 00000000..e466ccce --- /dev/null +++ b/misc/validate-NASIS-results.R @@ -0,0 +1,67 @@ +## validation of NASIS-functionality for nasisDBI PR +## git shell command to list files changed in the PR + +# git diff --name-only master...nasisDBI | grep -E get\\|NASIS\\|fetch + +f <- read.table(text = "R/fetchNASIS.R + R/fetchNASIS_pedons.R + R/getHzErrorsNASIS.R + R/get_RMF_from_NASIS_db.R + R/get_colors_from_NASIS_db.R + R/get_component_data_from_NASIS_db.R + R/get_concentrations_from_NASIS_db.R + R/get_cosoilmoist_from_NASIS.R + R/get_extended_data_from_NASIS_db.R + R/get_hz_data_from_NASIS_db.R + R/get_lablayer_data_from_NASIS_db.R + R/get_labpedon_data_from_NASIS_db.R + R/get_phfmp_from_NASIS_db.R + R/get_phlabresults_data_from_NASIS_db.R + R/get_projectmapunit_from_NASIS.R + R/get_site_data_from_NASIS_db.R + R/get_text_notes_from_NASIS_db.R + R/get_veg_data_from_NASIS_db.R + R/get_vegplot_data_from_NASIS_db.R + R/openNASISchannel.R")$V1 + # R/dbQueryNASIS.R + # R/get_soilseries_from_NASIS.R + # man/dbConnectNASIS.Rd + # man/dbQueryNASIS.Rd + # man/fetchNASIS.Rd + # man/getHzErrorsNASIS.Rd + # misc/man-deprecated/fetchNASIS.Rd + # +library(soilDB) + +fnames <- sapply(f, function(x) { + spv <- evalSource(x, package = "soilDB") + # source(x) + names(as.list(spv)) +}) + +test <- lapply(fnames, function(fname) { + lapply(fname, function(FUN) { + message(sprintf("Testing: %s", FUN)) + try(get(FUN, envir = as.environment("package:soilDB"))()) + }) + }) + +res <- unlist(lapply(names(test), function(x) lapply(seq_along(test[[x]]), function(y) { + res <- inherits(test[[x]][[y]], 'try-error') + names(res) <- fnames[[x]][y] + res + }))) + +res[which(res)] + +# Fixed: Text fields must come at end of query per MSSQL specs +# get_text_notes_from_NASIS_db() + +# Fixed: same as above +# get_vegplot_location_from_NASIS_db() + +# Fixed: +# get_vegplot_textnote_from_NASIS_db() + +# Relatively rare data update soon with input from Jay +# get_vegplot_transpecies_from_NASIS_db() diff --git a/tests/testthat/test-getHzErrorsNASIS.R b/tests/testthat/test-getHzErrorsNASIS.R index df5f3cc8..926c2d40 100644 --- a/tests/testthat/test-getHzErrorsNASIS.R +++ b/tests/testthat/test-getHzErrorsNASIS.R @@ -1,3 +1,3 @@ test_that("getHzErrorsNASIS works", { - expect_silent({test <- getHzErrorsNASIS()}) + expect_silent({suppressMessages(getHzErrorsNASIS())}) }) diff --git a/tests/testthat/test-get_text_notes_from_NASIS_db.R b/tests/testthat/test-get_text_notes_from_NASIS_db.R new file mode 100644 index 00000000..5567a7d9 --- /dev/null +++ b/tests/testthat/test-get_text_notes_from_NASIS_db.R @@ -0,0 +1,3 @@ +test_that("get_text_notes_from_NASIS_db works", { + expect_silent({get_text_notes_from_NASIS_db()}) +})