Skip to content

Commit

Permalink
updated function refs
Browse files Browse the repository at this point in the history
  • Loading branch information
meetagrawal09 committed Sep 26, 2023
1 parent 71a6703 commit 0f19ee1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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
Expand Down
22 changes: 13 additions & 9 deletions modules/data.atmosphere/inst/integrationTests/test.download.ERA5.R
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit 0f19ee1

Please sign in to comment.