-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Wasin Pipattungsakul
committed
Nov 20, 2024
1 parent
1c5d10f
commit 0416696
Showing
7 changed files
with
59 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
.DS_Store | ||
.quarto | ||
docs | ||
.Renviron |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
test_that("A valid collection combination passes", { | ||
expect_null(.check_collection_agreement("totalbucket", as.Date("2007-01-01"))) | ||
expect_null(.check_collection_agreement("some_collection", as.Date("2007-01-01"))) | ||
expect_null(.check_collection_agreement("some_collection", lubridate::today() - 7)) | ||
}) | ||
|
||
test_that("An invalid collection combination throws an error", { | ||
last_week <- lubridate::today() - 7 | ||
|
||
error_msg <- paste0("The data are not available before 2005 and roughly much past ", last_week) | ||
expect_error( | ||
.check_collection_agreement("some_collection", lubridate::today()), | ||
error_msg | ||
) | ||
expect_error( | ||
.check_collection_agreement("totalbucket", as.Date("2004-01-01")), | ||
error_msg | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,4 @@ | ||
test_that("An error is raised when the API key is the example string", { | ||
# multiple dates | ||
expect_error( | ||
.check_not_example_api_key("your_api_key"), | ||
"You have copied the example code and not provided a proper API key. | ||
An API key may be requested from TERN to access this resource. Please | ||
see the help file for {.fn get_key} for more information." | ||
) | ||
expect_error(.check_not_example_api_key("your_api_key")) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
test_that("A valid url part is created", { | ||
date_ <- as.Date("2020-01-01") | ||
|
||
# different collections | ||
expect_equal(.make_smips_url("totalbucket", date_), "smips_totalbucket_mm_20200101.tif") | ||
expect_equal(.make_smips_url("SMindex", date_), "smips_smi_perc_20200101.tif") | ||
expect_equal(.make_smips_url("bucket1", date_), "smips_bucket1_mm_20200101.tif") | ||
expect_equal(.make_smips_url("bucket2", date_), "smips_bucket2_mm_20200101.tif") | ||
expect_equal(.make_smips_url("deepD", date_), "smips_deepD_mm_20200101.tif") | ||
|
||
# different date | ||
expect_equal(.make_smips_url("runoff", as.Date("2020-01-02")), "smips_runoff_mm_20200102.tif") | ||
}) | ||
|
||
test_that("An invalid collection throws an error", { | ||
valid_collections <- c( | ||
"totalbucket", | ||
"SMindex", | ||
"bucket1", | ||
"bucket2", | ||
"deepD", | ||
"runoff" | ||
) | ||
valid_collections_str <- paste(valid_collections[seq_along(valid_collections) - 1], collapse = '", "') | ||
valid_collections_str <- paste0('"', valid_collections_str, '", "', tail(valid_collections, 1), '"') | ||
|
||
# TODO: check error message | ||
error_msg <- paste0("`.collection` must be one of ", valid_collections_str, ', not "asdf".') | ||
expect_error(.make_smips_url("asdf", as.Date("2020-01-01"))) | ||
}) |