Skip to content

Commit

Permalink
testing addin modules
Browse files Browse the repository at this point in the history
  • Loading branch information
khufkens committed Apr 22, 2019
1 parent ea0396b commit 6bc15de
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 15 deletions.
9 changes: 9 additions & 0 deletions R/addin.R
Expand Up @@ -12,6 +12,11 @@ MARS2list_Addin <- function() {
# conversion function to translate a MARS query into
# a ecmwfr list statement
MARS_to_list <- function(MARS_text) {

if(missing(MARS_text)){
stop("No input text provided")
}

MARS_text <- strsplit(MARS_text, "\n")[[1]]
MARS_text <- strsplit(MARS_text, "=")
MARS_text <- MARS_text[lengths(MARS_text) == 2]
Expand Down Expand Up @@ -52,6 +57,10 @@ python2list_Addin <- function() {
# a ecmwfr list statement
python_to_list <- function(python_text) {

if(missing(python_text)){
stop("No input text provided")
}

python_text <- gsub('\'','"',python_text)

# grab anything between ()
Expand Down
66 changes: 51 additions & 15 deletions tests/testthat/test_helper_functions.R
@@ -1,22 +1,22 @@
# Test ancillary functions which help in (batch) downloading

# format request (see below)
my_request <- list(stream = "oper",
levtype = "sfc",
param = "165.128",
dataset = "interim",
step = "0",
grid = "0.75/0.75",
time = "00",
date = "2014-07-01/to/2014-07-31",
type = "an",
class = "ei",
area = "51/0/50/1",
format = "netcdf",
target = "tmp.nc")

test_that("create tests archetype", {

# format request
my_request <- list(stream = "oper",
levtype = "sfc",
param = "165.128",
dataset = "interim",
step = "0",
grid = "0.75/0.75",
time = "00",
date = "2014-07-01/to/2014-07-31",
type = "an",
class = "ei",
area = "51/0/50/1",
format = "netcdf",
target = "tmp.nc")

# create archetype
ERA_interim <- wf_archetype(
list(
Expand Down Expand Up @@ -56,3 +56,39 @@ test_that("create tests archetype", {
))
})

test_that("test addin",{
skip_on_cran()

cds <- "c.retrieve(
'reanalysis-era5-single-levels-monthly-means',
{
'format':'netcdf',
'product_type':'members-monthly-means-of-daily-means',
'variable':'2m_temperature',
'year':'1979',
'month':'01',
'time':'00:00'
},
'download.nc')"

mars <- 'retrieve,
class=ep,
dataset=cera20c,
date=19010101/19010201/19010301/19010401/19010501/19010601/19010701/19010801/19010901/19011001/19011101/19011201,
expver=1,
levtype=sfc,
number=0,
param=168.128,
stream=edmm,
time=00:00:00,
type=an,
target="output"'

expect_is(ecmwfr:::python_to_list(cds), class = "character")
expect_error(ecmwfr:::python_to_list())
expect_is(ecmwfr:::MARS_to_list(mars), class = "character")
expect_error(ecmwfr:::MARS_to_list())

})


0 comments on commit 6bc15de

Please sign in to comment.