Skip to content

Commit

Permalink
adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
khufkens committed Aug 27, 2024
1 parent 301c247 commit ca96ca8
Showing 1 changed file with 34 additions and 10 deletions.
44 changes: 34 additions & 10 deletions tests/testthat/test_ds.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,25 @@ if(server_check & ON_GIT){
# the user is not created
login_check <- inherits(user, "try-error")
} else {
login_check <- TRUE

# assume local run
if(!inherits(wf_get_key(), "try-error")){
Sys.setenv(CDS = wf_get_key())
login_check <- FALSE
} else{
login_check <- TRUE
}
}

#----- formal checks ----
test_that("set key", {
skip_on_cran()
skip_if(login_check)
expect_message(wf_set_key(Sys.getenv("CDS")))
expect_message(wf_set_key(Sys.getenv("CDS")))

# set system variable and check key again
Sys.setenv(ecmwfr_PAT=Sys.getenv("CDS"))
expect_identical(wf_get_key(), Sys.getenv("CDS"))
})

test_that("cds datasets returns data.frame or list", {
Expand Down Expand Up @@ -101,13 +112,15 @@ test_that("cds request", {
)

# job test (can't run headless)
expect_error(
wf_request(
request = cds_request,
transfer = TRUE,
job_name = "jobtest"
if(ON_GIT){
expect_error(
wf_request(
request = cds_request,
transfer = TRUE,
job_name = "jobtest"
)
)
}

# faulty request
expect_error(
Expand Down Expand Up @@ -138,12 +151,22 @@ test_that("cds request", {

# is R6 class
expect_true(inherits(r, "R6"))
r$delete() # cleanup
url <- r$get_url()

# test delete routine
expect_error(
wf_delete(url = "50340909as")
)

# cleanup
expect_message(
r$delete()
)

# error on second call
expect_error(
wf_delete(url)
)
})


Expand Down Expand Up @@ -183,8 +206,9 @@ test_that("required arguments missing for cds_* functions", {
expect_error(wf_transfer(url = "http://google.com"))

# check product listing
expect_output(str(wf_dataset_info("reanalysis-era5-single-levels",
simplify = FALSE)))
expect_output(str(wf_dataset_info(
"reanalysis-era5-single-levels",
simplify = FALSE)))
})

test_that("batch request tests", {
Expand Down

0 comments on commit ca96ca8

Please sign in to comment.