From 41e716565dc731d32f182ddce7cc5a985093ccff Mon Sep 17 00:00:00 2001 From: Carlos Delgado Date: Tue, 10 Mar 2020 09:44:33 +0100 Subject: [PATCH 1/2] test for the error message when the dimension names in Step are incorrect --- tests/testthat/test-Compute-NumChunks.R | 38 ------------------------- tests/testthat/test-Step-DimNames.R | 30 +++++++++++++++++++ 2 files changed, 30 insertions(+), 38 deletions(-) delete mode 100644 tests/testthat/test-Compute-NumChunks.R create mode 100644 tests/testthat/test-Step-DimNames.R diff --git a/tests/testthat/test-Compute-NumChunks.R b/tests/testthat/test-Compute-NumChunks.R deleted file mode 100644 index 1b20e29b..00000000 --- a/tests/testthat/test-Compute-NumChunks.R +++ /dev/null @@ -1,38 +0,0 @@ -library(testthat) -library(startR) -context("Number of chunks tests.") -test_that("Single File - Local execution", { - -data = Start(dataset = '/esarchive/recon/jma/jra55/monthly_mean/$var$_f6h/$var$_$sdate$$month$.nc', - var = 'tas', - sdate = '2000', - month = indices(1), - lat = values(list(0, 14)), - lon = values(list(0, 28)), - synonims = list(lat = c('lat','latitude'), lon = c('lon','longitude')), - return_vars = list(lat = 'dataset', lon = 'dataset'), - lat_reorder = Sort(), - num_procs = 1, retrieve = FALSE) - -fun <- function(x) { - return(x) -} - -step <- Step(fun = fun, - target_dims = c('month'), - output_dims = c('month')) - -wf = AddStep(inputs = data, - step_fun = step) - -expect_equal(Compute(workflow = wf, - chunks = list(lat = 2,lon = 2), - threads_load = 2, - threads_compute = 4), - - Compute(workflow = wf, - chunks = list(lat = 3,lon = 3), - threads_load = 2, - threads_compute = 4), check.attributes = FALSE) - -}) \ No newline at end of file diff --git a/tests/testthat/test-Step-DimNames.R b/tests/testthat/test-Step-DimNames.R new file mode 100644 index 00000000..ad611a21 --- /dev/null +++ b/tests/testthat/test-Step-DimNames.R @@ -0,0 +1,30 @@ +library(testthat) +library(startR) +context("Error with bad dimensions tests.") +test_that("Single File - Local execution", { + + data = Start(dataset = '/esarchive/recon/jma/jra55/monthly_mean/$var$_f6h/$var$_$sdate$$month$.nc', + var = 'tas', + sdate = '2000', + month = indices(1), + lat = values(list(0, 14)), + lon = values(list(0, 28)), + synonims = list(lat = c('lat','latitude'), lon = c('lon','longitude')), + return_vars = list(lat = 'dataset', lon = 'dataset'), + lat_reorder = Sort(), + num_procs = 1, retrieve = FALSE) + + fun <- function(x) { + return(x) + } + + step <- Step(fun = fun, + target_dims = c('member'), + output_dims = c('member')) + + # Checking error because of dimension name doesn't exist: + expect_error(AddStep(inputs = data, + step_fun = step), + "The target dimensions required by 'step_fun' for the input 1 are not present in the corresponding provided object in 'inputs'.") + +}) \ No newline at end of file -- GitLab From f5ec9ec0482c7ac5c4862af93b6d2bb863fc59ae Mon Sep 17 00:00:00 2001 From: aho Date: Mon, 6 Apr 2020 13:26:42 +0200 Subject: [PATCH 2/2] Format adjustment and change file name. --- tests/testthat/test-AddStep-DimNames.R | 28 ++++++++++++++++++++++++ tests/testthat/test-Step-DimNames.R | 30 -------------------------- 2 files changed, 28 insertions(+), 30 deletions(-) create mode 100644 tests/testthat/test-AddStep-DimNames.R delete mode 100644 tests/testthat/test-Step-DimNames.R diff --git a/tests/testthat/test-AddStep-DimNames.R b/tests/testthat/test-AddStep-DimNames.R new file mode 100644 index 00000000..03e1d01f --- /dev/null +++ b/tests/testthat/test-AddStep-DimNames.R @@ -0,0 +1,28 @@ +context("Error with bad dimensions tests.") +test_that("Single File - Local execution", { + + data <- Start(dataset = '/esarchive/recon/jma/jra55/monthly_mean/$var$_f6h/$var$_$sdate$$month$.nc', + var = 'tas', + sdate = '2000', + month = indices(1), + lat = values(list(0, 14)), + lat_reorder = Sort(), + lon = values(list(0, 28)), + lon_reorder = CircularSort(0, 360), + synonims = list(lat = c('lat','latitude'), + lon = c('lon','longitude')), + return_vars = list(lat = 'dataset', lon = 'dataset'), + num_procs = 1, retrieve = FALSE) + + fun <- function(x) { + return(x) + } + step <- Step(fun = fun, + target_dims = c('member'), + output_dims = c('member')) + # Checking error because of dimension name doesn't exist: + expect_error(AddStep(inputs = data, + step_fun = step), + "The target dimensions required by 'step_fun' for the input 1 are not present in the corresponding provided object in 'inputs'.") + +}) diff --git a/tests/testthat/test-Step-DimNames.R b/tests/testthat/test-Step-DimNames.R deleted file mode 100644 index ad611a21..00000000 --- a/tests/testthat/test-Step-DimNames.R +++ /dev/null @@ -1,30 +0,0 @@ -library(testthat) -library(startR) -context("Error with bad dimensions tests.") -test_that("Single File - Local execution", { - - data = Start(dataset = '/esarchive/recon/jma/jra55/monthly_mean/$var$_f6h/$var$_$sdate$$month$.nc', - var = 'tas', - sdate = '2000', - month = indices(1), - lat = values(list(0, 14)), - lon = values(list(0, 28)), - synonims = list(lat = c('lat','latitude'), lon = c('lon','longitude')), - return_vars = list(lat = 'dataset', lon = 'dataset'), - lat_reorder = Sort(), - num_procs = 1, retrieve = FALSE) - - fun <- function(x) { - return(x) - } - - step <- Step(fun = fun, - target_dims = c('member'), - output_dims = c('member')) - - # Checking error because of dimension name doesn't exist: - expect_error(AddStep(inputs = data, - step_fun = step), - "The target dimensions required by 'step_fun' for the input 1 are not present in the corresponding provided object in 'inputs'.") - -}) \ No newline at end of file -- GitLab