From 0f19ee17c04da61248efb28828c9cd81de22fa5f Mon Sep 17 00:00:00 2001 From: meetagrawal09 Date: Wed, 27 Sep 2023 01:10:58 +0530 Subject: [PATCH 1/4] updated function refs --- .../test.download.AmerifluxLBL.R | 18 +++++++++------ .../integrationTests/test.download.CRUNCEP.R | 22 +++++++++++-------- .../integrationTests/test.download.ERA5.R | 22 +++++++++++-------- 3 files changed, 37 insertions(+), 25 deletions(-) diff --git a/modules/data.atmosphere/inst/integrationTests/test.download.AmerifluxLBL.R b/modules/data.atmosphere/inst/integrationTests/test.download.AmerifluxLBL.R index 659f016e5dd..07412b4de31 100644 --- a/modules/data.atmosphere/inst/integrationTests/test.download.AmerifluxLBL.R +++ b/modules/data.atmosphere/inst/integrationTests/test.download.AmerifluxLBL.R @@ -1,19 +1,23 @@ library(testthat) +library(mockery) +library(PEcAn.DB) +library(PEcAn.logger) +library(withr) test_download_AmerifluxLBL <- function(start_date, end_date, sitename, lat.in, lon.in) { # putting logger to debug mode - PEcAn.logger::logger.setUseConsole(TRUE, FALSE) - on.exit(PEcAn.logger::logger.setUseConsole(TRUE, TRUE), add = TRUE) - PEcAn.logger::logger.setLevel("DEBUG") + logger.setUseConsole(TRUE, FALSE) + on.exit(logger.setUseConsole(TRUE, TRUE), add = TRUE) + logger.setLevel("DEBUG") # mocking functions - mockery::stub(PEcAn.DB::convert_input, 'dbfile.input.check', data.frame()) - mockery::stub(PEcAn.DB::convert_input, 'db.query', data.frame(id = 1)) + stub(convert_input, 'dbfile.input.check', data.frame()) + stub(convert_input, 'db.query', data.frame(id = 1)) - withr::with_dir(tempdir(), { + with_dir(tempdir(), { tmpdir <- getwd() # calling download function - res <- PEcAn.DB::convert_input( + res <- convert_input( input.id = NA, outfolder = tmpdir, formatname = NULL, diff --git a/modules/data.atmosphere/inst/integrationTests/test.download.CRUNCEP.R b/modules/data.atmosphere/inst/integrationTests/test.download.CRUNCEP.R index 8512b49f34d..832667c101e 100644 --- a/modules/data.atmosphere/inst/integrationTests/test.download.CRUNCEP.R +++ b/modules/data.atmosphere/inst/integrationTests/test.download.CRUNCEP.R @@ -1,19 +1,23 @@ library(testthat) library(ncdf4) +library(mockery) +library(PEcAn.DB) +library(PEcAn.logger) +library(withr) test_download_CRUNCEP <- function(start_date, end_date, lat.in, lon.in, method, maxErrors, sleep) { # putting logger to debug mode - PEcAn.logger::logger.setUseConsole(TRUE, FALSE) - on.exit(PEcAn.logger::logger.setUseConsole(TRUE, TRUE), add = TRUE) - PEcAn.logger::logger.setLevel("DEBUG") + logger.setUseConsole(TRUE, FALSE) + on.exit(logger.setUseConsole(TRUE, TRUE), add = TRUE) + logger.setLevel("DEBUG") # mocking functions - mockery::stub(PEcAn.DB::convert_input, 'dbfile.input.check', data.frame()) - mockery::stub(PEcAn.DB::convert_input, 'db.query', data.frame(id = 1)) + stub(convert_input, 'dbfile.input.check', data.frame()) + stub(convert_input, 'db.query', data.frame(id = 1)) - withr::with_dir(tempdir(), { + with_dir(tempdir(), { tmpdir <- getwd() - PEcAn.DB::convert_input( + convert_input( input.id = NA, outfolder = tmpdir, formatname = NULL, @@ -44,8 +48,8 @@ test_download_CRUNCEP <- function(start_date, end_date, lat.in, lon.in, method, test_that("NetCDF file contains lat and lon variables", { - mask_nc <- ncdf4::nc_open(paste0(tmpdir, "/cruncep_landwater_mask.nc")) - on.exit(ncdf4::nc_close(mask_nc), add = TRUE) + mask_nc <- nc_open(paste0(tmpdir, "/cruncep_landwater_mask.nc")) + on.exit(nc_close(mask_nc), add = TRUE) expect_true("land_water_mask" %in% names(mask_nc$var)) # Check the dimensions of "land_water_mask" variable diff --git a/modules/data.atmosphere/inst/integrationTests/test.download.ERA5.R b/modules/data.atmosphere/inst/integrationTests/test.download.ERA5.R index fbcff615fd6..30c6e7af027 100644 --- a/modules/data.atmosphere/inst/integrationTests/test.download.ERA5.R +++ b/modules/data.atmosphere/inst/integrationTests/test.download.ERA5.R @@ -1,24 +1,28 @@ library(testthat) library(ncdf4) +library(mockery) +library(PEcAn.DB) +library(PEcAn.logger) +library(withr) test_download_ERA5 <- function(start_date, end_date, lat.in, lon.in, product_types, reticulate_python) { # putting logger to debug mode - PEcAn.logger::logger.setUseConsole(TRUE, FALSE) - on.exit(PEcAn.logger::logger.setUseConsole(TRUE, TRUE), add = TRUE) - PEcAn.logger::logger.setLevel("DEBUG") + logger.setUseConsole(TRUE, FALSE) + on.exit(logger.setUseConsole(TRUE, TRUE), add = TRUE) + logger.setLevel("DEBUG") # mocking functions - mockery::stub(PEcAn.DB::convert_input, 'dbfile.input.check', data.frame()) - mockery::stub(PEcAn.DB::convert_input, 'db.query', data.frame(id = 1)) + stub(convert_input, 'dbfile.input.check', data.frame()) + stub(convert_input, 'db.query', data.frame(id = 1)) # additional mocks needed since download.ERA5 does not return data as other download functions - mockery::stub(PEcAn.DB::convert_input, 'length', 2) - mockery::stub(PEcAn.DB::convert_input, 'purrr::map_dfr', data.frame(missing = c(FALSE), empty = c(FALSE))) + stub(convert_input, 'length', 2) + stub(convert_input, 'purrr::map_dfr', data.frame(missing = c(FALSE), empty = c(FALSE))) - withr::with_dir(tempdir(), { + with_dir(tempdir(), { tmpdir <- getwd() - PEcAn.DB::convert_input( + convert_input( input.id = NA, outfolder = tmpdir, formatname = NULL, From 0baebb5aba368711d0d545d0f1a0820245a51bf6 Mon Sep 17 00:00:00 2001 From: meetagrawal09 Date: Wed, 27 Sep 2023 09:46:28 +0530 Subject: [PATCH 2/4] added namespaces --- .../test.download.AmerifluxLBL.R | 15 ++++++--------- .../integrationTests/test.download.CRUNCEP.R | 15 ++++++--------- .../integrationTests/test.download.ERA5.R | 19 ++++++++----------- 3 files changed, 20 insertions(+), 29 deletions(-) diff --git a/modules/data.atmosphere/inst/integrationTests/test.download.AmerifluxLBL.R b/modules/data.atmosphere/inst/integrationTests/test.download.AmerifluxLBL.R index 07412b4de31..372f5bfb11d 100644 --- a/modules/data.atmosphere/inst/integrationTests/test.download.AmerifluxLBL.R +++ b/modules/data.atmosphere/inst/integrationTests/test.download.AmerifluxLBL.R @@ -1,20 +1,17 @@ library(testthat) -library(mockery) library(PEcAn.DB) -library(PEcAn.logger) -library(withr) test_download_AmerifluxLBL <- function(start_date, end_date, sitename, lat.in, lon.in) { # putting logger to debug mode - logger.setUseConsole(TRUE, FALSE) - on.exit(logger.setUseConsole(TRUE, TRUE), add = TRUE) - logger.setLevel("DEBUG") + PEcAn.logger::logger.setUseConsole(TRUE, FALSE) + on.exit(PEcAn.logger::logger.setUseConsole(TRUE, TRUE), add = TRUE) + PEcAn.logger::logger.setLevel("DEBUG") # mocking functions - stub(convert_input, 'dbfile.input.check', data.frame()) - stub(convert_input, 'db.query', data.frame(id = 1)) + mockery::stub(convert_input, 'dbfile.input.check', data.frame()) + mockery::stub(convert_input, 'db.query', data.frame(id = 1)) - with_dir(tempdir(), { + withr::with_dir(tempdir(), { tmpdir <- getwd() # calling download function res <- convert_input( diff --git a/modules/data.atmosphere/inst/integrationTests/test.download.CRUNCEP.R b/modules/data.atmosphere/inst/integrationTests/test.download.CRUNCEP.R index 832667c101e..396c7a0aae7 100644 --- a/modules/data.atmosphere/inst/integrationTests/test.download.CRUNCEP.R +++ b/modules/data.atmosphere/inst/integrationTests/test.download.CRUNCEP.R @@ -1,21 +1,18 @@ library(testthat) library(ncdf4) -library(mockery) library(PEcAn.DB) -library(PEcAn.logger) -library(withr) test_download_CRUNCEP <- function(start_date, end_date, lat.in, lon.in, method, maxErrors, sleep) { # putting logger to debug mode - logger.setUseConsole(TRUE, FALSE) - on.exit(logger.setUseConsole(TRUE, TRUE), add = TRUE) - logger.setLevel("DEBUG") + PEcAn.logger::logger.setUseConsole(TRUE, FALSE) + on.exit(PEcAn.logger::logger.setUseConsole(TRUE, TRUE), add = TRUE) + PEcAn.logger::logger.setLevel("DEBUG") # mocking functions - stub(convert_input, 'dbfile.input.check', data.frame()) - stub(convert_input, 'db.query', data.frame(id = 1)) + mockery::stub(convert_input, 'dbfile.input.check', data.frame()) + mockery::stub(convert_input, 'db.query', data.frame(id = 1)) - with_dir(tempdir(), { + withr::with_dir(tempdir(), { tmpdir <- getwd() convert_input( input.id = NA, diff --git a/modules/data.atmosphere/inst/integrationTests/test.download.ERA5.R b/modules/data.atmosphere/inst/integrationTests/test.download.ERA5.R index 30c6e7af027..bf84c31dd85 100644 --- a/modules/data.atmosphere/inst/integrationTests/test.download.ERA5.R +++ b/modules/data.atmosphere/inst/integrationTests/test.download.ERA5.R @@ -1,26 +1,23 @@ library(testthat) library(ncdf4) -library(mockery) library(PEcAn.DB) -library(PEcAn.logger) -library(withr) test_download_ERA5 <- function(start_date, end_date, lat.in, lon.in, product_types, reticulate_python) { # putting logger to debug mode - logger.setUseConsole(TRUE, FALSE) - on.exit(logger.setUseConsole(TRUE, TRUE), add = TRUE) - logger.setLevel("DEBUG") + PEcAn.logger::logger.setUseConsole(TRUE, FALSE) + on.exit(PEcAn.logger::logger.setUseConsole(TRUE, TRUE), add = TRUE) + PEcAn.logger::logger.setLevel("DEBUG") # mocking functions - stub(convert_input, 'dbfile.input.check', data.frame()) - stub(convert_input, 'db.query', data.frame(id = 1)) + mockery::stub(convert_input, 'dbfile.input.check', data.frame()) + mockery::stub(convert_input, 'db.query', data.frame(id = 1)) # additional mocks needed since download.ERA5 does not return data as other download functions - stub(convert_input, 'length', 2) - stub(convert_input, 'purrr::map_dfr', data.frame(missing = c(FALSE), empty = c(FALSE))) + mockery::stub(convert_input, 'length', 2) + mockery::stub(convert_input, 'purrr::map_dfr', data.frame(missing = c(FALSE), empty = c(FALSE))) - with_dir(tempdir(), { + withr::with_dir(tempdir(), { tmpdir <- getwd() convert_input( input.id = NA, From dfb1dae78e82053af92d46560348c227e235ab42 Mon Sep 17 00:00:00 2001 From: meetagrawal09 Date: Wed, 27 Sep 2023 09:48:25 +0530 Subject: [PATCH 3/4] added ns --- .../inst/integrationTests/test.download.CRUNCEP.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/data.atmosphere/inst/integrationTests/test.download.CRUNCEP.R b/modules/data.atmosphere/inst/integrationTests/test.download.CRUNCEP.R index 396c7a0aae7..cfad888104b 100644 --- a/modules/data.atmosphere/inst/integrationTests/test.download.CRUNCEP.R +++ b/modules/data.atmosphere/inst/integrationTests/test.download.CRUNCEP.R @@ -45,8 +45,8 @@ test_download_CRUNCEP <- function(start_date, end_date, lat.in, lon.in, method, test_that("NetCDF file contains lat and lon variables", { - mask_nc <- nc_open(paste0(tmpdir, "/cruncep_landwater_mask.nc")) - on.exit(nc_close(mask_nc), add = TRUE) + mask_nc <- ncdf4::nc_open(paste0(tmpdir, "/cruncep_landwater_mask.nc")) + on.exit(ncdf4::nc_close(mask_nc), add = TRUE) expect_true("land_water_mask" %in% names(mask_nc$var)) # Check the dimensions of "land_water_mask" variable From 1aa068f07676a1a4b7822448ee61f78221584f9c Mon Sep 17 00:00:00 2001 From: meetagrawal09 Date: Mon, 2 Oct 2023 19:27:54 +0530 Subject: [PATCH 4/4] updated edit url --- book_source/_bookdown.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book_source/_bookdown.yml b/book_source/_bookdown.yml index 45407cef0bc..fb22b3b1e6e 100644 --- a/book_source/_bookdown.yml +++ b/book_source/_bookdown.yml @@ -1,2 +1,2 @@ rmd_subdir: true -edit: https://github.com/tonygardella/pecan/edit/release/vtonydoc/book_source/%s +edit: https://github.com/PecanProject/pecan/edit/develop/book_source/%s