From e50e0093a8365f4d8aeae5f2ee2fa6a429d726e0 Mon Sep 17 00:00:00 2001 From: meetagrawal09 Date: Mon, 27 May 2024 18:16:53 +0530 Subject: [PATCH] tested .download.raw.met.module --- .../tests/testthat/test.do_conversions.R | 3 ++ modules/data.atmosphere/DESCRIPTION | 1 + .../testthat/test.download.raw.met.module.R | 34 +++++++++++++++++++ .../tests/testthat/test.met.process.R | 3 ++ 4 files changed, 41 insertions(+) create mode 100644 base/workflow/tests/testthat/test.do_conversions.R create mode 100644 modules/data.atmosphere/tests/testthat/test.download.raw.met.module.R create mode 100644 modules/data.atmosphere/tests/testthat/test.met.process.R diff --git a/base/workflow/tests/testthat/test.do_conversions.R b/base/workflow/tests/testthat/test.do_conversions.R new file mode 100644 index 00000000000..d9364072a17 --- /dev/null +++ b/base/workflow/tests/testthat/test.do_conversions.R @@ -0,0 +1,3 @@ +test_that("`do_conversions` ", { + +}) \ No newline at end of file diff --git a/modules/data.atmosphere/DESCRIPTION b/modules/data.atmosphere/DESCRIPTION index 5cf32fac9b6..ff73c6c2554 100644 --- a/modules/data.atmosphere/DESCRIPTION +++ b/modules/data.atmosphere/DESCRIPTION @@ -64,6 +64,7 @@ Suggests: foreach, furrr, future, + mockery, parallel, PEcAn.settings, progress, diff --git a/modules/data.atmosphere/tests/testthat/test.download.raw.met.module.R b/modules/data.atmosphere/tests/testthat/test.download.raw.met.module.R new file mode 100644 index 00000000000..363a9b823d7 --- /dev/null +++ b/modules/data.atmosphere/tests/testthat/test.download.raw.met.module.R @@ -0,0 +1,34 @@ +test_that("`.download.raw.met.module` throws an error if register$site is unknown", { + register <- list(scale = 'example') + expect_error( + .download.raw.met.module(dir = NULL, met = NULL, register = register, str_ns = NULL), + "Unknown register\\$scale" + ) +}) + +test_that("`.download.raw.met.module` is able to call the right download function based on met value", { + mocked_res <- mockery::mock(10) + mockery::stub(.download.raw.met.module, 'PEcAn.DB::convert_input', mocked_res) + register <- list(scale = 'site') + res <- .download.raw.met.module( + dir = NULL, + met = 'ERA5', + register = register, + machine = NULL, + start_date = '2010-01-01', + end_date = '2010-01-01', + str_ns = NULL, + con = NULL, + input_met = NULL, + site.id = 1, + lat.in = 1, + lon.in = 1, + host = NULL, + site = NULL, + username = NULL, + dbparms = NULL) + args <- mockery::mock_args(mocked_res) + mockery::expect_called(mocked_res, 1) + expect_equal(res, 10) + expect_equal(args[[1]]$fcn, 'download.ERA5') +}) \ No newline at end of file diff --git a/modules/data.atmosphere/tests/testthat/test.met.process.R b/modules/data.atmosphere/tests/testthat/test.met.process.R new file mode 100644 index 00000000000..54582ff00a0 --- /dev/null +++ b/modules/data.atmosphere/tests/testthat/test.met.process.R @@ -0,0 +1,3 @@ +test_that("`met.process` ", { + +}) \ No newline at end of file