diff --git a/.Rbuildignore b/.Rbuildignore index b2d65166..cb7cbd26 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -6,6 +6,7 @@ sandbox/ ^LICENSE\.md$ ^\.github$ .claude/ +.opencode/ ^doc$ ^Meta$ ^_pkgdown\.yml$ diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 00000000..c422a06d --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,54 @@ +# Contributing to entsoeapi + +Thank you for taking the time to contribute! This document outlines the process for reporting issues and submitting code changes. + +## Code of Conduct + +Please review and follow our [Code of Conduct](CODE_OF_CONDUCT.md). + +## Reporting bugs + +Use the [bug report template](https://github.com/krose/entsoeapi/issues/new?template=bug_report.md) and include: + +- A minimal reproducible example (ideally using `reprex::reprex()`) +- The ENTSO-E API endpoint involved and the query parameters used +- Your OS, R version, and `entsoeapi` version (`packageVersion("entsoeapi")`) + +Do **not** include your ENTSO-E security token in the report. + +## Requesting features + +Open a [feature request](https://github.com/krose/entsoeapi/issues/new?template=feature_request.md) describing the ENTSO-E endpoint or data domain you would like covered and a brief use case. + +## Submitting a pull request + +1. Fork the repository and create a branch from `main`. + +2. Install development dependencies: `devtools::install_dev_deps()`. + +3. Make your changes. Keep each PR focused on a single concern. + +4. Add or update tests — the package targets 100% test coverage. + +5. Run the full check suite locally before pushing: + + ``` r + lintr::lint_package() + devtools::document() + devtools::test() + devtools::check() + covr::package_coverage() + ``` + +6. Open the pull request against `master` and describe what changed and why. + +### Conventions + +- Follow the existing code style (snake_case, `cli::` for user-facing messages, `checkmate::` for input validation). +- New user-facing functions must have `@examplesIf` blocks (see existing functions for the pattern). +- All exported functions need a `@return` tag in their roxygen documentation. +- ENTSO-E security tokens must never appear in code, tests, or fixtures — use the `ENTSOE_PAT` environment variable. + +## Questions + +For general usage questions, open a [GitHub Discussion](https://github.com/krose/entsoeapi/discussions) rather than an issue. diff --git a/.gitignore b/.gitignore index e2f5665f..1e0d60ba 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ sandbox/ test-coverage.yml .claude/ +.opencode/ inst/doc /doc/ /Meta/ diff --git a/.urlchecker b/.urlchecker deleted file mode 100644 index 8347e274..00000000 --- a/.urlchecker +++ /dev/null @@ -1,2 +0,0 @@ -[exclusions] -https://transparencyplatform.zendesk.com diff --git a/DESCRIPTION b/DESCRIPTION index 4e6a7d84..fb7556e8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: entsoeapi Type: Package Title: R Client for the 'ENTSO-E' Transparency Platform API -Version: 0.9.6 +Version: 0.9.7 Authors@R: c(person("Kenneth", "Rose", role=c("aut", "cph"), email="kennethrose82@gmail.com"), person("Sándor", "Budai", role=c("aut", "cre", "cph"), email="sbudai.ga@gmail.com")) Description: Provides a standardized R client for the 'ENTSO-E' (European Network of @@ -15,10 +15,7 @@ Imports: cachem, cli, checkmate, - curl, - data.table, dplyr, - fs, httr2, lubridate, purrr, @@ -26,8 +23,6 @@ Imports: stringr, tibble, tidyr, - tidyselect, - utf8, utils, xml2, xmlconvert @@ -46,9 +41,10 @@ Suggests: ggplot2 VignetteBuilder: knitr Config/testthat/edition: 3 -Collate: +Collate: 'entsoeapi-package.R' 'data.R' + 'constants.R' 'utils.R' 'en_helpers.R' 'en_market.R' diff --git a/NEWS.md b/NEWS.md index 8b63e302..9cdc7f84 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,21 @@ -# entsoeapi v0.9.6 (2026-03-12) +# entsoeapi v0.9.7 (2026-03-17) + +## New functionality + +- None. + +## Miscellaneous + +- The code base simplified. +- The package level constants have been placed into a standalone file. +- These dependency (Imports) packages removed from the code: `curl`, `data.table`, `fs`, `tidyselect`, `utf8` +- The sapply() calls have been removed from some unit tests. +- The global assignment operators have been removed from the code. +- The .github/CONTRIBUTING.md file has been created and added. +- The DESCRIPTION document has been updated. +- A contributor guide has been added. + +# entsoeapi v0.9.6 (2026-03-12), ## New functionality @@ -11,7 +28,7 @@ - Across all R files @examples blocks replaced by @examplesIf blocks — since they require an ENTSOE_PAT env var that isn't available in CI. - @return section has been added to each exported function. - The cran-comments.md has been created and has been added to .Rbuildignore. -- the .urlchecker config file has been created and has been added to .Rbuildignore. +- The .urlchecker config file has been created and has been added to .Rbuildignore. - The DESCRIPTION and the LICENSE documents have been updated. # entsoeapi v0.9.5.1 (2026-03-09) diff --git a/R/constants.R b/R/constants.R new file mode 100644 index 00000000..e179f487 --- /dev/null +++ b/R/constants.R @@ -0,0 +1,9 @@ +.api_scheme <- "https://" +.api_domain <- "web-api.tp.entsoe.eu/" +.api_name <- "api?" +.req_timeout <- 60 +.max_age <- 3600 +possible_eic_chars <- stats::setNames( + object = 0L:36L, + nm = c(as.character(0:9), LETTERS, "-") +) diff --git a/R/en_generation.R b/R/en_generation.R index fa5daa9a..336df915 100644 --- a/R/en_generation.R +++ b/R/en_generation.R @@ -401,10 +401,9 @@ gen_per_gen_unit <- function( if (is.null(gen_type)) { par_matrix <- par_matrix |> dplyr::mutate( - periodEnd = data.table::shift( + periodEnd = dplyr::lead( x = periodStart, - type = "lead", - fill = as.POSIXct( + default = as.POSIXct( x = period_end, format = "%Y%m%d%H%M", tz = "UTC" @@ -415,10 +414,9 @@ gen_per_gen_unit <- function( par_matrix <- par_matrix |> dplyr::group_by(psrType) |> dplyr::mutate( - periodEnd = data.table::shift( + periodEnd = dplyr::lead( x = periodStart, - type = "lead", - fill = as.POSIXct( + default = as.POSIXct( x = period_end, format = "%Y%m%d%H%M", tz = "UTC" diff --git a/R/en_helpers.R b/R/en_helpers.R index a9b085a2..de415892 100644 --- a/R/en_helpers.R +++ b/R/en_helpers.R @@ -5,19 +5,31 @@ utils::globalVariables( "eic_code_status", "eic_code_status_value", "get_eiccodes", + "cache_get_or_compute", "type", "type_def" ) ) +#' @importFrom stats setNames +NULL #' @title -#' instantiate a memory cache store for maximum 1 hour +#' Download and cache an EIC CSV file #' -#' @importFrom cachem cache_mem +#' @param csv_file Character scalar. The CSV filename +#' (e.g. `"X_eicCodes.csv"`). +#' @param cache_key Character scalar. The cache key +#' (e.g. `"party_eic_df_key"`). #' #' @noRd -mh <- cachem::cache_mem(max_age = 3600) +fetch_eic_csv <- function(csv_file, cache_key) { + cache_get_or_compute( # nolint: object_usage_linter + key = cache_key, + label = paste(csv_file, "file"), + compute_fn = \() get_eiccodes(f = csv_file) + ) +} #' @title @@ -29,7 +41,7 @@ mh <- cachem::cache_mem(max_age = 3600) #' https://www.entsoe.eu/data/energy-identification-codes-eic/eic-approved-codes #' It covers market participants. #' -#' @returns +#' @return #' A tibble of accordingly filtered EIC codes, which contains such columns as #' `EicCode`, `EicDisplayName`, `EicLongName`, `EicParent`, #' `EicResponsibleParty`, `EicStatus`, `MarketParticipantPostalCode`, @@ -44,25 +56,10 @@ mh <- cachem::cache_mem(max_age = 3600) #' dplyr::glimpse(eic_party) #' party_eic <- function() { - # set the link of the csv file - f <- "X_eicCodes.csv" - - # check if there is any cached value of 'party_eic_name' - cache_key <- "party_eic_df_key" - if (mh$exists(key = cache_key)) { - # recall res_df values - res_df <- mh$get(key = cache_key, missing = get_eiccodes(f = f)) - cli::cli_alert_info("pulling {f} file from cache") - } else { - # download and import the csv file - cli::cli_alert_info("downloading {f} file ...") - res_df <- get_eiccodes(f = f) - - # cache res_df as cache_key - mh$set(key = cache_key, value = res_df) - } - - res_df + fetch_eic_csv( + csv_file = "X_eicCodes.csv", + cache_key = "party_eic_df_key" + ) } @@ -74,7 +71,7 @@ party_eic <- function() { #' energy identification codes from this site: #' https://www.entsoe.eu/data/energy-identification-codes-eic/eic-approved-codes #' -#' @returns +#' @return #' A tibble of accordingly filtered EIC codes, which contains such columns as #' `EicCode`, `EicDisplayName`, `EicLongName`, `EicParent`, #' `EicResponsibleParty`, `EicStatus`, `MarketParticipantPostalCode`, @@ -89,25 +86,10 @@ party_eic <- function() { #' dplyr::glimpse(eic_area) #' area_eic <- function() { - # set the link of the csv file - f <- "Y_eicCodes.csv" - - # check if there is any cached value of 'area_eic_name' - cache_key <- "area_eic_df_key" - if (mh$exists(key = cache_key)) { - # recall res_df values - res_df <- mh$get(key = cache_key, missing = get_eiccodes(f = f)) - cli::cli_alert_info("pulling {f} file from cache") - } else { - # download and import the csv file - cli::cli_alert_info("downloading {f} file ...") - res_df <- get_eiccodes(f = f) - - # cache res_df as cache_key - mh$set(key = cache_key, value = res_df) - } - - res_df + fetch_eic_csv( + csv_file = "Y_eicCodes.csv", + cache_key = "area_eic_df_key" + ) } @@ -121,7 +103,7 @@ area_eic <- function() { #' An entity under balance responsibility where balance supplier change #' can take place and for which commercial business processes are defined. #' -#' @returns +#' @return #' A tibble of accordingly filtered EIC codes, which contains such columns as #' `EicCode`, `EicDisplayName`, `EicLongName`, `EicParent`, #' `EicResponsibleParty`, `EicStatus`, `MarketParticipantPostalCode`, @@ -136,25 +118,10 @@ area_eic <- function() { #' dplyr::glimpse(eic_accounting_point) #' accounting_point_eic <- function() { - # set the link of the csv file - f <- "Z_eicCodes.csv" - - # check if there is any cached value of 'accounting_point_eic_name' - cache_key <- "accounting_point_eic_df_key" - if (mh$exists(key = cache_key)) { - # recall res_df values - res_df <- mh$get(key = cache_key, missing = get_eiccodes(f = f)) - cli::cli_alert_info("pulling {f} file from cache") - } else { - # download and import the csv file - cli::cli_alert_info("downloading {f} file ...") - res_df <- get_eiccodes(f = f) - - # cache res_df as cache_key - mh$set(key = cache_key, value = res_df) - } - - res_df + fetch_eic_csv( + csv_file = "Z_eicCodes.csv", + cache_key = "accounting_point_eic_df_key" + ) } @@ -168,7 +135,7 @@ accounting_point_eic <- function() { #' It covers a transmission line that connects different areas #' excluding HVDC interconnectors. #' -#' @returns +#' @return #' A tibble of accordingly filtered EIC codes, which contains such columns as #' `EicCode`, `EicDisplayName`, `EicLongName`, `EicParent`, #' `EicResponsibleParty`, `EicStatus`, `MarketParticipantPostalCode`, @@ -183,25 +150,10 @@ accounting_point_eic <- function() { #' dplyr::glimpse(eic_tie_line) #' tie_line_eic <- function() { - # set the link of the csv file - f <- "T_eicCodes.csv" - - # check if there is any cached value of 'tie_line_eic_name' - cache_key <- "tie_line_eic_df_key" - if (mh$exists(key = cache_key)) { - # recall res_df values - res_df <- mh$get(key = cache_key, missing = get_eiccodes(f = f)) - cli::cli_alert_info("pulling {f} file from cache") - } else { - # download and import the csv file - cli::cli_alert_info("downloading {f} file ...") - res_df <- get_eiccodes(f = f) - - # cache res_df as cache_key - mh$set(key = cache_key, value = res_df) - } - - res_df + fetch_eic_csv( + csv_file = "T_eicCodes.csv", + cache_key = "tie_line_eic_df_key" + ) } @@ -214,7 +166,7 @@ tie_line_eic <- function() { #' https://www.entsoe.eu/data/energy-identification-codes-eic/eic-approved-codes #' It covers an endpoint, or an IT-system. #' -#' @returns +#' @return #' A tibble of accordingly filtered EIC codes, which contains such columns as #' `EicCode`, `EicDisplayName`, `EicLongName`, `EicParent`, #' `EicResponsibleParty`, `EicStatus`, `MarketParticipantPostalCode`, @@ -229,25 +181,10 @@ tie_line_eic <- function() { #' dplyr::glimpse(eic_location) #' location_eic <- function() { - # set the link of the csv file - f <- "V_eicCodes.csv" - - # check if there is any cached value of 'location_eic_name' - cache_key <- "location_eic_df_key" - if (mh$exists(key = cache_key)) { - # recall res_df values - res_df <- mh$get(key = cache_key, missing = get_eiccodes(f = f)) - cli::cli_alert_info("pulling {f} file from cache") - } else { - # download and import the csv file - cli::cli_alert_info("downloading {f} file ...") - res_df <- get_eiccodes(f = f) - - # cache res_df as cache_key - mh$set(key = cache_key, value = res_df) - } - - res_df + fetch_eic_csv( + csv_file = "V_eicCodes.csv", + cache_key = "location_eic_df_key" + ) } @@ -261,7 +198,7 @@ location_eic <- function() { #' A resource that can either produce or consume energy #' and that is reported in a schedule. #' -#' @returns +#' @return #' A tibble of accordingly filtered EIC codes, which contains such columns as #' `EicCode`, `EicDisplayName`, `EicLongName`, `EicParent`, #' `EicResponsibleParty`, `EicStatus`, `MarketParticipantPostalCode`, @@ -276,25 +213,10 @@ location_eic <- function() { #' dplyr::glimpse(eic_resource_object) #' resource_object_eic <- function() { - # set the link of the csv file - f <- "W_eicCodes.csv" - - # check if there is any cached value of 'resource_object_eic_name' - cache_key <- "resource_object_eic_df_key" - if (mh$exists(key = cache_key)) { - # recall res_df values - res_df <- mh$get(key = cache_key, missing = get_eiccodes(f = f)) - cli::cli_alert_info("pulling {f} file from cache") - } else { - # download and import the csv file - cli::cli_alert_info("downloading {f} file ...") - res_df <- get_eiccodes(f = f) - - # cache res_df as cache_key - mh$set(key = cache_key, value = res_df) - } - - res_df + fetch_eic_csv( + csv_file = "W_eicCodes.csv", + cache_key = "resource_object_eic_df_key" + ) } @@ -313,7 +235,7 @@ resource_object_eic <- function() { #' They can be classified as normal outside substation, #' armoured substation and underground substation. #' -#' @returns +#' @return #' A tibble of accordingly filtered EIC codes, which contains such columns as #' `EicCode`, `EicDisplayName`, `EicLongName`, `EicParent`, #' `EicResponsibleParty`, `EicStatus`, `MarketParticipantPostalCode`, @@ -328,25 +250,10 @@ resource_object_eic <- function() { #' dplyr::glimpse(eic_substation) #' substation_eic <- function() { - # set the link of the csv file - f <- "A_eicCodes.csv" - - # check if there is any cached value of 'substation_eic_name' - cache_key <- "substation_eic_df_key" - if (mh$exists(key = cache_key)) { - # recall res_df values - res_df <- mh$get(key = cache_key, missing = get_eiccodes(f = f)) - cli::cli_alert_info("pulling {f} file from cache") - } else { - # download and import the csv file - cli::cli_alert_info("downloading {f} file ...") - res_df <- get_eiccodes(f = f) - - # cache res_df as cache_key - mh$set(key = cache_key, value = res_df) - } - - res_df + fetch_eic_csv( + csv_file = "A_eicCodes.csv", + cache_key = "substation_eic_df_key" + ) } @@ -360,7 +267,7 @@ substation_eic <- function() { #' Further details are under: #' https://www.entsoe.eu/data/energy-identification-codes-eic/#eic-documentation #' -#' @returns +#' @return #' A tibble of accordingly filtered EIC codes, which contains such columns as #' `EicCode`, `EicDisplayName`, `EicLongName`, `EicParent`, #' `EicResponsibleParty`, `EicStatus`, `MarketParticipantPostalCode`, @@ -384,7 +291,7 @@ all_approved_eic <- function() { resource_object_eic(), substation_eic() ) |> - data.table::rbindlist(use.names = TRUE, fill = TRUE) |> + dplyr::bind_rows() |> unique() |> tibble::as_tibble() } @@ -403,7 +310,7 @@ all_approved_eic <- function() { #' Further details are under: #' https://www.entsoe.eu/data/energy-identification-codes-eic/ #' -#' @returns +#' @return #' A tibble of all allocated EIC codes, which contains such columns as #' `doc_status`, `doc_status_value`, `revision_number`, `created_date_time`, #' `eic_code`, `instance_component_attribute`, `long_name`, `display_name`, @@ -416,21 +323,9 @@ all_approved_eic <- function() { #' #' @noRd all_allocated_eic <- function() { - cache_key <- "all_allocated_eic_df_key" - - # check if there is any cached value of 'all_allocated_eic' - if (mh$exists(key = cache_key)) { - # recall res_df values - res_df <- mh$get(key = cache_key, missing = get_all_allocated_eic()) - cli::cli_alert_info("pulling all_allocated_eic table from cache") - } else { - # download and import the csv file - cli::cli_alert_info("downloading all_allocated_eic table ...") - res_df <- get_all_allocated_eic() - - # cache res_df as cache_key - mh$set(key = cache_key, value = res_df) - } - - res_df + cache_get_or_compute( # nolint: object_usage_linter + key = "all_allocated_eic_df_key", + label = "all_allocated_eic table", + compute_fn = get_all_allocated_eic + ) } diff --git a/R/en_outages.R b/R/en_outages.R index be4a6d74..0ff25cd5 100644 --- a/R/en_outages.R +++ b/R/en_outages.R @@ -107,7 +107,7 @@ outages_both <- function( # append the results and return list(tbl_gu, tbl_pu) |> purrr::compact() |> - data.table::rbindlist(use.names = TRUE, fill = TRUE) + dplyr::bind_rows() } diff --git a/R/utils.R b/R/utils.R index 56a388d3..6fbacc60 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,18 +1,10 @@ -#' @title -#' instantiate a memory cache store for maximum 1 hour -#' -#' @importFrom cachem cache_mem -#' -#' @noRd -m <- cachem::cache_mem(max_age = 3600) - - utils::globalVariables( c( "allocation_mode_types", "analog_types", "api_req_safe", "area_eic", + "cache_get_or_compute", "asset_types", "auction_types", "business_types", @@ -58,19 +50,45 @@ utils::globalVariables( "unit_multiplier", "unit_of_measure_types", "unit_symbol_types", - "url_posixct_format" + "url_posixct_format", + ".api_scheme", + ".api_domain", + ".api_name", + ".req_timeout", + ".max_age", + "possible_eic_chars" ) ) #' @title -#' Character-to-integer lookup table for EIC checksum validation +#' instantiate a memory cache store for maximum 1 hour +#' +#' @importFrom cachem cache_mem #' #' @noRd -possible_eic_chars <- rlang::set_names( - x = 0L:36L, - nm = c(as.character(0:9), LETTERS, "-") -) +m <- cachem::cache_mem(max_age = .max_age) + + +#' @title +#' Retrieve a cached value or compute, cache, and return it +#' +#' @param key Character scalar. The cache key. +#' @param compute_fn A zero-argument function that produces the value. +#' @param label Character scalar. A human-readable label for CLI messages. +#' +#' @noRd +cache_get_or_compute <- function(key, compute_fn, label) { + if (m$exists(key = key)) { + cli::cli_alert_info("pulling {label} from cache") + m$get(key = key) + } else { + cli::cli_alert_info("downloading {label} ...") + val <- compute_fn() + m$set(key = key, value = val) + val + } +} #' @title @@ -157,20 +175,20 @@ grouping_by_common_strings <- function(vector_list) { } # Union-Find with path compression - parent <- 1L:n + parent <- list2env(x = list(data = 1L:n), parent = emptyenv()) find_root <- function(i) { - if (parent[i] != i) { - parent[i] <<- find_root(parent[i]) + if (parent$data[i] != i) { + parent$data[i] <- find_root(i = parent$data[i]) } - parent[i] + parent$data[i] } union_sets <- function(i, j) { root_i <- find_root(i) root_j <- find_root(j) if (root_i != root_j) { - parent[root_j] <<- root_i + parent$data[root_j] <- root_i } } @@ -186,11 +204,11 @@ grouping_by_common_strings <- function(vector_list) { # Normalize all parents for (i in 1L:n) { - parent[i] <- find_root(i) + parent$data[i] <- find_root(i) } # Group indices by their root parent - base::split(x = 1L:n, f = parent) |> + base::split(x = 1L:n, f = parent$data) |> unname() } @@ -205,13 +223,7 @@ grouping_by_common_strings <- function(vector_list) { #' #' @noRd number_of_children <- function(nodeset) { - have_no_child <- purrr::map_lgl( - xml2::xml_children(nodeset), - ~ xml2::xml_children(.x) |> - unlist(recursive = FALSE) |> - is.null() - ) - sum(have_no_child == FALSE) + sum(xml2::xml_length(xml2::xml_children(nodeset)) > 0L) } @@ -220,7 +232,7 @@ number_of_children <- function(nodeset) { #' #' @description #' extract the content of the provided XML nodesets, -#' and compose a list of data.tables from them +#' and compose a list of tibbles from them #' #' @noRd extract_nodesets <- function(nodesets, prefix = NULL) { @@ -247,14 +259,20 @@ extract_nodesets <- function(nodesets, prefix = NULL) { unique_names <- names(named_vect) |> unique() - # compose a table from the elements and - # adjust column names accordingly - purrr::map( - unique_names, - ~ named_vect[names(named_vect) == .x] - ) |> - data.table::as.data.table() |> - stats::setNames(nm = unique_names) + # compose a table from the elements + vals <- split(named_vect, names(named_vect))[unique_names] + max_len <- max(lengths(vals)) + non_conformable <- vals[ + lengths(vals) != max_len & max_len %% lengths(vals) != 0L + ] + if (length(non_conformable) > 0L) { + cli::cli_warn( + "XML column lengths are not exact multiples of the \\ + maximum ({max_len}); recycling with truncation." + ) + } + purrr::map(vals, ~ rep_len(.x, length.out = max_len)) |> + tibble::as_tibble() } ) } @@ -275,7 +293,7 @@ extract_leaf_twig_branch <- function(nodesets) { # compose a sub table from first level data first_level_tbl <- nodesets[children_of_nodes == 0L] |> extract_nodesets() |> - data.table::as.data.table() + dplyr::bind_cols() second_level_tbl <- nodesets[children_of_nodes > 0L] |> purrr::map( @@ -300,7 +318,7 @@ extract_leaf_twig_branch <- function(nodesets) { nodesets = child_nodesets[ch_children_of_nodes == 0L], prefix = xml2::xml_name(scnd_ns) ) |> - data.table::as.data.table() + dplyr::bind_cols() # convert the grandchild nodes into a table nodeset_tbls <- extract_nodesets( @@ -311,12 +329,12 @@ extract_leaf_twig_branch <- function(nodesets) { grouping_by_common_strings() if (length(nodeset_groups) == 1L) { compound_tbls[[2L]] <- nodeset_tbls |> - data.table::rbindlist(use.names = TRUE, fill = TRUE) + dplyr::bind_rows() } else { compound_tbls[[2L]] <- seq_along(nodeset_groups) |> purrr::map( ~ nodeset_tbls[nodeset_groups[[.x]]] |> - data.table::rbindlist(use.names = TRUE, fill = TRUE) + dplyr::bind_rows() ) |> dplyr::bind_cols() } @@ -329,7 +347,7 @@ extract_leaf_twig_branch <- function(nodesets) { compound_tbl } ) |> - data.table::rbindlist(use.names = TRUE, fill = TRUE) + dplyr::bind_rows() list(first_level_tbl, second_level_tbl) |> purrr::compact() |> @@ -411,17 +429,17 @@ tidy_or_not <- function(tbl, tidy_output = FALSE) { # the 'ts_point_dt_start' values tbl <- tbl |> dplyr::mutate( - by = data.table::fcase( - ts_resolution == "PT4S", "4 sec", - ts_resolution == "PT1M", "1 min", - ts_resolution == "PT15M", "15 mins", - ts_resolution == "PT30M", "30 mins", - ts_resolution == "PT60M", "1 hour", - ts_resolution == "P1D", "1 DSTday", - ts_resolution == "P7D", "7 DSTdays", - ts_resolution == "P1M", "1 month", - ts_resolution == "P1Y", "1 year", - default = "n/a" + by = dplyr::case_when( + ts_resolution == "PT4S" ~ "4 sec", + ts_resolution == "PT1M" ~ "1 min", + ts_resolution == "PT15M" ~ "15 mins", + ts_resolution == "PT30M" ~ "30 mins", + ts_resolution == "PT60M" ~ "1 hour", + ts_resolution == "P1D" ~ "1 DSTday", + ts_resolution == "P7D" ~ "7 DSTdays", + ts_resolution == "P1M" ~ "1 month", + ts_resolution == "P1Y" ~ "1 year", + .default = "n/a" ) ) @@ -435,7 +453,7 @@ tidy_or_not <- function(tbl, tidy_output = FALSE) { # calculate 'ts_resolution_requ_length', 'ts_resolution_real_length' # and 'ts_resolution_ok' values tbl <- tbl |> - dplyr::group_by(dplyr::across(tidyselect::all_of(group_cols))) |> + dplyr::group_by(dplyr::across(dplyr::all_of(group_cols))) |> dplyr::mutate( ts_resolution_requ_length = (max(ts_time_interval_end) - min(ts_time_interval_start)) / @@ -477,10 +495,10 @@ tidy_or_not <- function(tbl, tidy_output = FALSE) { ts_mrid = ..5 ) ) |> - data.table::rbindlist(use.names = TRUE, fill = TRUE) + dplyr::bind_rows() # full join the adjusted timeseries data points with the frame table - tbl_adj <- data.table::merge.data.table( + tbl_adj <- dplyr::full_join( x = tbl_adj, y = frame_tbl, by = c( @@ -489,29 +507,23 @@ tidy_or_not <- function(tbl, tidy_output = FALSE) { "ts_point_position", "ts_resolution", "ts_mrid" - ), - all = TRUE - ) |> - data.table::as.data.table() + ) + ) # fill the missing values with the last observation carry forward method group_cols_adj <- c("ts_resolution", "ts_mrid") tbl_adj <- tbl_adj |> - dplyr::group_by(dplyr::across(tidyselect::all_of(group_cols_adj))) |> + dplyr::group_by(dplyr::across(dplyr::all_of(group_cols_adj))) |> tidyr::fill(dplyr::everything()) |> dplyr::ungroup() # append the adjusted timeseries data points to the 'ok' timeseries data - tbl <- list(tbl, tbl_adj) |> - data.table::rbindlist(use.names = TRUE, fill = TRUE) - data.table::setorderv( - x = tbl, - cols = c( - "ts_time_interval_start", - "ts_time_interval_end", - "ts_point_position" + tbl <- dplyr::bind_rows(tbl, tbl_adj) |> + dplyr::arrange( + ts_time_interval_start, + ts_time_interval_end, + ts_point_position ) - ) } } else { # hints: https://eepublicdownloads.entsoe.eu/clean-documents/EDI/ @@ -526,7 +538,7 @@ tidy_or_not <- function(tbl, tidy_output = FALSE) { base::subset( subset = !is.na(ts_time_interval_start) & !is.na(ts_point_position) ) |> - dplyr::group_by(dplyr::across(tidyselect::all_of(group_cols))) |> + dplyr::group_by(dplyr::across(dplyr::all_of(group_cols))) |> dplyr::mutate( ts_point_dt_start = seq.POSIXt( from = min(ts_time_interval_start), @@ -568,7 +580,7 @@ tidy_or_not <- function(tbl, tidy_output = FALSE) { # nest the timeseries data points tbl <- tidyr::nest( tbl, - ts_point = tidyselect::all_of(ts_point_cols) + ts_point = dplyr::all_of(ts_point_cols) ) } @@ -624,8 +636,7 @@ calc_offset_urls <- function(reason, query_string) { } # calculate how many offset round is needed - all_offset_nr <- docs_requested %/% docs_allowed + - ceiling(docs_requested %% docs_allowed / docs_allowed) + all_offset_nr <- ceiling(docs_requested / docs_allowed) all_offset_seq <- (seq(all_offset_nr) - 1L) * docs_allowed # recompose offset URLs @@ -646,7 +657,7 @@ read_zipped_xml <- function(temp_file_path) { unzipped_files <- unzip_safe( zipfile = temp_file_path, overwrite = TRUE, - exdir = fs::path_dir(temp_file_path) + exdir = dirname(temp_file_path) ) # read the xml content from each the decompressed files @@ -668,9 +679,9 @@ read_zipped_xml <- function(temp_file_path) { #' #' @noRd api_req <- function( - api_scheme = "https://", - api_domain = "web-api.tp.entsoe.eu/", - api_name = "api?", + api_scheme = .api_scheme, # nolint: object_usage_linter. + api_domain = .api_domain, # nolint: object_usage_linter. + api_name = .api_name, # nolint: object_usage_linter. query_string = NULL, security_token = NULL ) { @@ -685,13 +696,16 @@ api_req <- function( # retrieve data from the API req <- httr2::request(base_url = paste0(url, security_token)) |> httr2::req_method(method = "GET") |> + httr2::req_user_agent( + string = "entsoeapi (https://krose.github.io/entsoeapi/)" + ) |> httr2::req_verbose( header_req = FALSE, header_resp = TRUE, body_req = FALSE, body_resp = FALSE ) |> - httr2::req_timeout(seconds = 60) + httr2::req_timeout(seconds = .req_timeout) # nolint: object_usage_linter. resp <- req_perform_safe(req = req) if (is.null(x = resp$error)) { @@ -921,36 +935,28 @@ get_eiccodes <- function( ) if (is.null(content$error)) { lns <- content$result |> - stringr::str_replace_all( - pattern = "tutkimustehdas;\\sImatra", - replacement = "tutkimustehdas, Imatra" - ) |> - stringr::str_replace_all( - pattern = "; S\\.L\\.;", - replacement = ", S.L.;" - ) |> - stringr::str_replace_all( - pattern = "\\$amp;", - replacement = "&" - ) + stringr::str_replace_all(c( + "tutkimustehdas;\\sImatra" = "tutkimustehdas, Imatra", + "; S\\.L\\.;" = ", S.L.;", + "\\$amp;" = "&" + )) # reading lines as they would be a csv - eiccodes <- data.table::fread( + eiccodes <- utils::read.table( text = lns, sep = ";", + header = TRUE, na.strings = c("", "n / a", "n/a", "N/A", "-", "-------", "."), - encoding = "UTF-8" + colClasses = "character", + quote = '"', + comment.char = "" ) # trimming character columns eiccodes <- eiccodes |> purrr::map(~ { - if (is.character(.x)) { - utf8::utf8_encode(x = .x) |> - trimws(which = "both") - } else { - .x - } + enc2utf8(x = .x) |> + trimws(which = "both") }) |> tibble::as_tibble() @@ -994,7 +1000,6 @@ get_all_allocated_eic <- function() { max_tries = 3L, backoff = \(resp) 10 ) - resp <- "No response." resp <- req_perform_safe(req = req) if (is.null(resp$error)) { @@ -1016,7 +1021,7 @@ get_all_allocated_eic <- function() { # compose a sub table from the first level data first_level_tbl <- nodesets[children_of_nodes == 0L] |> extract_nodesets() |> - data.table::as.data.table() + dplyr::bind_cols() # remove the not needed columns from the first_level_tbl not_needed_patt <- paste( @@ -1063,11 +1068,11 @@ get_all_allocated_eic <- function() { } } # convert named list to table - data.table::as.data.table(nodeset_list) + tibble::as_tibble(nodeset_list) } ) |> purrr::compact() |> - data.table::rbindlist(use.names = TRUE, fill = TRUE) |> + dplyr::bind_rows() |> dplyr::rename(dplyr::any_of(c( eic_code = "mRID", docStatusValue = "docStatus" @@ -1091,13 +1096,12 @@ get_all_allocated_eic <- function() { names(result_tbl) <- my_snakecase(result_tbl) # add eic_code_doc_status definitions to codes - result_tbl <- data.table::merge.data.table( + result_tbl <- dplyr::left_join( x = result_tbl, y = message_types |> subset(select = c("code", "title")) |> setNames(nm = c("doc_status_value", "doc_status")), - by = "doc_status_value", - all.x = TRUE + by = "doc_status_value" ) |> dplyr::relocate( doc_status, @@ -1112,28 +1116,6 @@ get_all_allocated_eic <- function() { } -#' @title -#' unpack an xml section into a tabular row -#' -#' @noRd -unpack_xml <- function(section, parent_name = NULL) { - result_vector <- xml2::as_list(section) |> - unlist(recursive = TRUE) - if (is.null(result_vector)) { - tbl <- tibble::tibble() - } else { - names(result_vector) <- stringr::str_c(parent_name, - xml2::xml_name(section), - names(result_vector), - sep = "." - ) - tbl <- tibble::as_tibble_row(result_vector) - } - # return - tbl -} - - #' @title #' an own version of snakecase::to_snakecase() function #' @@ -1200,40 +1182,25 @@ my_snakecase <- function(tbl) { #' @title -#' create a specific merge function which adds the needed definitions +#' Merge a lookup table onto a table by key column #' -#' @noRd -def_merge <- function(x, y, code_name, definition_name) { - x <- x |> - data.table::data.table() - y <- y |> - subset(select = c("code", "title")) |> - data.table::data.table() - names(y) <- c(code_name, definition_name) - data.table::merge.data.table( - x = x, - y = y, - by = code_name, - suffixes = c("_x", "_y"), - all.x = TRUE - ) -} - - -#' @title -#' create a specific merge function which adds the EIC names +#' @param x A data.frame to enrich. +#' @param y A lookup data.frame containing source columns. +#' @param from_cols Character vector of length 2: the source column names in `y` +#' (key column first, value column second). +#' @param to_cols Character vector of length 2: the target column names to use +#' after renaming (key column first, value column second). #' #' @noRd -eic_name_merge <- function(x, y, eic_code_name, eic_name_name) { +lookup_merge <- function(x, y, from_cols, to_cols) { y <- y |> - subset(select = c("eic_code", "eic_name")) |> - data.table::data.table() - names(y) <- c(eic_code_name, eic_name_name) - data.table::merge.data.table( + subset(select = from_cols) + names(y) <- to_cols + dplyr::left_join( x = x, y = y, - by = eic_code_name, - all.x = TRUE + by = to_cols[[1L]], + suffix = c("_x", "_y") ) } @@ -1244,127 +1211,90 @@ eic_name_merge <- function(x, y, eic_code_name, eic_name_name) { #' @noRd add_type_names <- function(tbl) { # pre-define some built-in tables to avoid non-standard evaluation issues - # within the current function - asset_types <- entsoeapi::asset_types - business_types <- entsoeapi::business_types - contract_types <- entsoeapi::contract_types - message_types <- entsoeapi::message_types - process_types <- entsoeapi::process_types - role_types <- entsoeapi::role_types - direction_types <- entsoeapi::direction_types - energy_product_types <- entsoeapi::energy_product_types - - # convert tbl to data.table in order to join faster - tbl <- data.table::data.table(tbl) - - # define an empty vector to collect those column names - # which will get definitions by add_type_names() function + asset_types <- asset_types + auction_types <- auction_types + business_types <- business_types + contract_types <- contract_types + direction_types <- direction_types + energy_product_types <- energy_product_types + message_types <- message_types + process_types <- process_types + role_types <- role_types + + # specification: col -> lookup table, definition column name + type_specs <- list( + list( + col = "type", + lookup = message_types, + def = "type_def" + ), + list( + col = "ts_business_type", + lookup = business_types, + def = "ts_business_type_def" + ), + list( + col = "ts_mkt_psr_type", + lookup = asset_types, + def = "ts_mkt_psr_type_def" + ), + list( + col = "ts_asset_psr_type", + lookup = asset_types, + def = "ts_asset_psr_type_def" + ), + list( + col = "ts_production_psr_type", + lookup = asset_types, + def = "ts_production_psr_type_def" + ), + list( + col = "process_type", + lookup = process_types, + def = "process_type_def" + ), + list( + col = "ts_product", + lookup = energy_product_types, + def = "ts_product_def" + ), + list( + col = "ts_contract_market_agreement_type", + lookup = contract_types, + def = "ts_contract_market_agreement_type_def" + ), + list( + col = "ts_auction_type", + lookup = auction_types, + def = "ts_auction_type_def" + ), + list( + col = "subject_market_participant_market_role_type", + lookup = role_types, + def = "subject_market_participant_market_role_type_def" + ), + list( + col = "bid_ts_flow_direction", + lookup = direction_types, + def = "bid_ts_flow_direction_def" + ) + ) + + tbl_names <- names(tbl) affected_cols <- character(0) - # add type definitions to codes - if ("type" %in% names(tbl)) { - affected_cols <- c(affected_cols, "type") - tbl <- def_merge( - x = tbl, - y = message_types, - code_name = "type", - definition_name = "type_def" - ) - } - if ("ts_business_type" %in% names(tbl)) { - affected_cols <- c(affected_cols, "ts_business_type") - tbl <- def_merge( - x = tbl, - y = business_types, - code_name = "ts_business_type", - definition_name = "ts_business_type_def" - ) - } - if ("ts_mkt_psr_type" %in% names(tbl)) { - affected_cols <- c(affected_cols, "ts_mkt_psr_type") - tbl <- def_merge( - x = tbl, - y = asset_types, - code_name = "ts_mkt_psr_type", - definition_name = "ts_mkt_psr_type_def" - ) - } - if ("ts_asset_psr_type" %in% names(tbl)) { - affected_cols <- c(affected_cols, "ts_asset_psr_type") - tbl <- def_merge( - x = tbl, - y = asset_types, - code_name = "ts_asset_psr_type", - definition_name = "ts_asset_psr_type_def" - ) - } - if ("ts_production_psr_type" %in% names(tbl)) { - affected_cols <- c(affected_cols, "ts_production_psr_type") - tbl <- def_merge( - x = tbl, - y = asset_types, - code_name = "ts_production_psr_type", - definition_name = "ts_production_psr_type_def" - ) - } - if ("process_type" %in% names(tbl)) { - affected_cols <- c(affected_cols, "process_type") - tbl <- def_merge( - x = tbl, - y = process_types, - code_name = "process_type", - definition_name = "process_type_def" - ) - } - if ("ts_product" %in% names(tbl)) { - affected_cols <- c(affected_cols, "ts_product") - tbl <- def_merge( - x = tbl, - y = energy_product_types, - code_name = "ts_product", - definition_name = "ts_product_def" - ) - } - if ("ts_contract_market_agreement_type" %in% names(tbl)) { - affected_cols <- c(affected_cols, "ts_contract_market_agreement_type") - tbl <- def_merge( - x = tbl, - y = contract_types, - code_name = "ts_contract_market_agreement_type", - definition_name = "ts_contract_market_agreement_type_def" - ) - } - if ("ts_auction_type" %in% names(tbl)) { - auction_types <- entsoeapi::auction_types - affected_cols <- c(affected_cols, "ts_auction_type") - tbl <- def_merge( - x = tbl, - y = auction_types, - code_name = "ts_auction_type", - definition_name = "ts_auction_type_def" - ) - } - if ("subject_market_participant_market_role_type" %in% names(tbl)) { - affected_cols <- c( - affected_cols, - "subject_market_participant_market_role_type" - ) - tbl <- def_merge( - x = tbl, - y = role_types, - code_name = "subject_market_participant_market_role_type", - definition_name = "subject_market_participant_market_role_type_def" - ) - } - if ("bid_ts_flow_direction" %in% names(tbl)) { - affected_cols <- c(affected_cols, "bid_ts_flow_direction") - tbl <- def_merge( - x = tbl, - y = direction_types, - code_name = "bid_ts_flow_direction", - definition_name = "bid_ts_flow_direction_def" - ) + for (spec in type_specs) { + if (spec$col %in% tbl_names) { + affected_cols <- c(affected_cols, spec$col) + tbl <- lookup_merge( + x = tbl, + y = spec$lookup, + from_cols = c("code", "title"), + to_cols = c(spec$col, spec$def) + ) + } } + if (length(affected_cols) == 0L) { cli::cli_alert_info("No additional type names added!") } @@ -1376,98 +1306,53 @@ add_type_names <- function(tbl) { #' @title #' get & adjust area_eic() table #' -#' @description -#' download area_eic() table & convert to data.table -#' in order to join faster -#' #' @noRd get_area_eic_name <- function() { # define those variables as NULL which are used under non-standard evaluation eic_code <- eic_long_name <- eic_name <- NULL - # compose a local 'download and transform' function - get_data <- function() { - area_eic() |> - subset(select = c("EicCode", "EicLongName")) |> - dplyr::rename_with(snakecase::to_snake_case) |> - dplyr::group_by(eic_code) |> - dplyr::mutate( - eic_name = stringr::str_c( - eic_long_name, - collapse = " - " - ) - ) |> - dplyr::ungroup() |> - dplyr::select(eic_code, eic_name) |> - data.table::data.table() - } - - # check if there is any cached value of 'area_eic_name' - aen_cache_key <- "area_eic_name_key" - if (m$exists(key = aen_cache_key)) { - # recall area_eic_name values - area_eic_name <- m$get( - key = aen_cache_key, - missing = get_data() - ) - } else { - # download area_eic() table & convert to data.table - # in order to join faster - area_eic_name <- get_data() - - # cache aen_dt as aen_cache_key - m$set(key = aen_cache_key, value = area_eic_name) - } - - area_eic_name + cache_get_or_compute( + key = "area_eic_name_key", + label = "area_eic_name table", + compute_fn = function() { + area_eic() |> + subset(select = c("EicCode", "EicLongName")) |> + dplyr::rename_with(snakecase::to_snake_case) |> + dplyr::group_by(eic_code) |> + dplyr::mutate( + eic_name = stringr::str_c( + eic_long_name, + collapse = " - " + ) + ) |> + dplyr::ungroup() |> + dplyr::select(eic_code, eic_name) + } + ) } #' @title #' get & adjust resource_object_eic() table #' -#' @description -#' download resource_object_eic() table & convert to data.table -#' in order to join faster -#' #' @noRd -get_resource_object_eic <- function( - roe_cache_key = "resource_object_eic_name_key" -) { +get_resource_object_eic <- function() { # define those variables as NULL which are used under non-standard evaluation eic_code <- eic_long_name <- NULL - # compose a local 'download and transform' function - get_data <- function() { - resource_object_eic() |> - subset(select = c("EicCode", "EicLongName")) |> - dplyr::rename_with(snakecase::to_snake_case) |> - dplyr::rename( - ts_registered_resource_mrid = eic_code, - ts_registered_resource_name = eic_long_name - ) |> - data.table::data.table() - } - - - # check if there is any cached value of 'area_eic_name' - if (m$exists(key = roe_cache_key)) { - # recall resource_object_eic_name values - resource_object_eic <- m$get( - key = roe_cache_key, - missing = get_data() - ) - } else { - # download resource_object_eic() table & convert to data.table - # in order to join faster - resource_object_eic <- get_data() - - # cache roe_dt as cache_key - m$set(key = roe_cache_key, value = resource_object_eic) - } - - # return - resource_object_eic + cache_get_or_compute( + key = "resource_object_eic_name_key", + label = "resource_object_eic table", + compute_fn = function() { + resource_object_eic() |> + subset(select = c("EicCode", "EicLongName")) |> + dplyr::rename_with(snakecase::to_snake_case) |> + dplyr::rename( + ts_registered_resource_mrid = eic_code, + ts_registered_resource_name = eic_long_name + ) + } + ) } @@ -1476,151 +1361,69 @@ get_resource_object_eic <- function( #' #' @noRd add_eic_names <- function(tbl) { - # convert tbl to data.table in order to join faster - tbl <- data.table::data.table(tbl) + if (is.null(tbl)) return(data.frame()) - # download & convert area_eic() table to data.table - # in order to join faster area_eic_name <- get_area_eic_name() - # define an empty vector to collect those EIC column names - # which will get definitions by add_eic_names() function affected_cols <- c() - # add names to eic codes + # special case: ts_registered_resource_mrid uses a different lookup table if ("ts_registered_resource_mrid" %in% names(tbl)) { - # download & convert resource_object_eic() table to data.table - # in order to join faster resource_object_eic <- get_resource_object_eic() - affected_cols <- c(affected_cols, "ts_registered_resource_mrid") tbl <- tbl |> - dplyr::select(!tidyselect::any_of("ts_registered_resource_name")) |> + dplyr::select(!dplyr::any_of("ts_registered_resource_name")) |> merge( y = resource_object_eic, by = "ts_registered_resource_mrid", all.x = TRUE ) } - if ("ts_bidding_zone_domain_mrid" %in% names(tbl)) { - affected_cols <- c(affected_cols, "ts_bidding_zone_domain_mrid") - tbl <- tbl |> - eic_name_merge( - y = area_eic_name, - eic_code_name = "ts_bidding_zone_domain_mrid", - eic_name_name = "ts_bidding_zone_domain_name" - ) - } - if ("ts_in_bidding_zone_domain_mrid" %in% names(tbl)) { - affected_cols <- c(affected_cols, "ts_in_bidding_zone_domain_mrid") - tbl <- tbl |> - eic_name_merge( - y = area_eic_name, - eic_code_name = "ts_in_bidding_zone_domain_mrid", - eic_name_name = "ts_in_bidding_zone_domain_name" - ) - } - if ("ts_out_bidding_zone_domain_mrid" %in% names(tbl)) { - affected_cols <- c(affected_cols, "ts_out_bidding_zone_domain_mrid") - tbl <- tbl |> - eic_name_merge( - y = area_eic_name, - eic_code_name = "ts_out_bidding_zone_domain_mrid", - eic_name_name = "ts_out_bidding_zone_domain_name" - ) - } - if ("ts_in_domain_mrid" %in% names(tbl)) { - affected_cols <- c(affected_cols, "ts_in_domain_mrid") - tbl <- tbl |> - eic_name_merge( - y = area_eic_name, - eic_code_name = "ts_in_domain_mrid", - eic_name_name = "ts_in_domain_name" - ) - } - if ("ts_out_domain_mrid" %in% names(tbl)) { - affected_cols <- c(affected_cols, "ts_out_domain_mrid") - tbl <- tbl |> - eic_name_merge( - y = area_eic_name, - eic_code_name = "ts_out_domain_mrid", - eic_name_name = "ts_out_domain_name" - ) - } - if ("area_domain_mrid" %in% names(tbl)) { - affected_cols <- c(affected_cols, "area_domain_mrid") - tbl <- tbl |> - eic_name_merge( - y = area_eic_name, - eic_code_name = "area_domain_mrid", - eic_name_name = "area_domain_name" - ) - } - if ("control_area_domain_mrid" %in% names(tbl)) { - affected_cols <- c(affected_cols, "control_area_domain_mrid") - tbl <- tbl |> - eic_name_merge( - y = area_eic_name, - eic_code_name = "control_area_domain_mrid", - eic_name_name = "control_area_domain_name" - ) - } - if ("ts_acquiring_domain_mrid" %in% names(tbl)) { - affected_cols <- c(affected_cols, "ts_acquiring_domain_mrid") - tbl <- tbl |> - eic_name_merge( - y = area_eic_name, - eic_code_name = "ts_acquiring_domain_mrid", - eic_name_name = "ts_acquiring_domain_name" - ) - } - if ("ts_connecting_domain_mrid" %in% names(tbl)) { - affected_cols <- c(affected_cols, "ts_connecting_domain_mrid") - tbl <- tbl |> - eic_name_merge( - y = area_eic_name, - eic_code_name = "ts_connecting_domain_mrid", - eic_name_name = "ts_connecting_domain_name" - ) - } - if ("bid_ts_acquiring_domain_mrid" %in% names(tbl)) { - affected_cols <- c(affected_cols, "bid_ts_acquiring_domain_mrid") - tbl <- tbl |> - eic_name_merge( - y = area_eic_name, - eic_code_name = "bid_ts_acquiring_domain_mrid", - eic_name_name = "bid_ts_acquiring_domain_name" - ) - } - if ("bid_ts_connecting_domain_mrid" %in% names(tbl)) { - affected_cols <- c(affected_cols, "bid_ts_connecting_domain_mrid") - tbl <- tbl |> - eic_name_merge( - y = area_eic_name, - eic_code_name = "bid_ts_connecting_domain_mrid", - eic_name_name = "bid_ts_connecting_domain_name" - ) - } - if ("domain_mrid" %in% names(tbl)) { - affected_cols <- c(affected_cols, "domain_mrid") - tbl <- tbl |> - eic_name_merge( - y = area_eic_name, - eic_code_name = "domain_mrid", - eic_name_name = "domain_name" - ) - } - if ("constraint_ts_monitored_ptdf_domain_mrid" %in% names(tbl)) { - affected_cols <- c( - affected_cols, "constraint_ts_monitored_ptdf_domain_mrid" - ) - tbl <- tbl |> - eic_name_merge( + + # specification: eic_code column -> eic_name column + eic_specs <- list( + c("ts_bidding_zone_domain_mrid", + "ts_bidding_zone_domain_name"), + c("ts_in_bidding_zone_domain_mrid", + "ts_in_bidding_zone_domain_name"), + c("ts_out_bidding_zone_domain_mrid", + "ts_out_bidding_zone_domain_name"), + c("ts_in_domain_mrid", + "ts_in_domain_name"), + c("ts_out_domain_mrid", + "ts_out_domain_name"), + c("area_domain_mrid", + "area_domain_name"), + c("control_area_domain_mrid", + "control_area_domain_name"), + c("ts_acquiring_domain_mrid", + "ts_acquiring_domain_name"), + c("ts_connecting_domain_mrid", + "ts_connecting_domain_name"), + c("bid_ts_acquiring_domain_mrid", + "bid_ts_acquiring_domain_name"), + c("bid_ts_connecting_domain_mrid", + "bid_ts_connecting_domain_name"), + c("domain_mrid", + "domain_name"), + c("constraint_ts_monitored_ptdf_domain_mrid", + "constraint_ts_monitored_ptdf_domain_name") + ) + + tbl_names <- names(tbl) + + for (spec in eic_specs) { + if (spec[[1L]] %in% tbl_names) { + affected_cols <- c(affected_cols, spec[[1L]]) + tbl <- lookup_merge( + x = tbl, y = area_eic_name, - eic_code_name = "constraint_ts_monitored_ptdf_domain_mrid", - eic_name_name = "constraint_ts_monitored_ptdf_domain_name" + from_cols = c("eic_code", "eic_name"), + to_cols = spec ) + } } + if (length(affected_cols) == 0L) { cli::cli_alert_info("No additional eic names added!") } @@ -1634,59 +1437,66 @@ add_eic_names <- function(tbl) { #' #' @noRd add_definitions <- function(tbl) { - # convert tbl to data.table in order to join faster - tbl <- data.table::data.table(tbl) + if (is.null(tbl)) return(data.frame()) + + # pre-define lookup tables + category_types <- category_types + direction_types <- direction_types + message_types <- message_types + object_aggregation_types <- object_aggregation_types + + # specification for simple definition merges (order matters for column order) + def_specs <- list( + list( + col = "doc_status_value", + lookup = message_types, + def = "doc_status" + ), + list( + col = "ts_auction_category", + lookup = category_types, + def = "ts_auction_category_def" + ), + list( + col = "ts_flow_direction", + lookup = direction_types, + def = "ts_flow_direction_def" + ) + ) - # define an empty vector to collect those column names - # which will get definitions by add_definitions() function + tbl_names <- names(tbl) affected_cols <- c() - # add definitions to codes - if ("doc_status_value" %in% names(tbl)) { - affected_cols <- c(affected_cols, "doc_status_value") - tbl <- def_merge( - x = tbl, - y = message_types, - code_name = "doc_status_value", - definition_name = "doc_status" - ) - } - if ("ts_auction_category" %in% names(tbl)) { - category_types <- entsoeapi::category_types - affected_cols <- c(affected_cols, "ts_auction_category") - tbl <- def_merge( - x = tbl, - y = category_types, - code_name = "ts_auction_category", - definition_name = "ts_auction_category_def" - ) - } - if ("ts_flow_direction" %in% names(tbl)) { - affected_cols <- c(affected_cols, "ts_flow_direction") - tbl <- def_merge( - x = tbl, - y = direction_types, - code_name = "ts_flow_direction", - definition_name = "ts_flow_direction_def" - ) + for (spec in def_specs) { + if (spec$col %in% tbl_names) { + affected_cols <- c(affected_cols, spec$col) + tbl <- lookup_merge( + x = tbl, + y = spec$lookup, + from_cols = c("code", "title"), + to_cols = c(spec$col, spec$def) + ) + } } + + # complex blocks: reason_code* and ts_reason_code* with dynamic columns rc_cols <- stringr::str_subset( string = names(tbl), pattern = "^reason_code(|_[0-9])" ) if (length(rc_cols) > 0) { - reason_code_types <- entsoeapi::reason_code_types + reason_code_types <- reason_code_types for (rc_col in rc_cols) { affected_cols <- c(affected_cols, rc_col) - tbl <- def_merge( + tbl <- lookup_merge( x = tbl, y = reason_code_types, - code_name = rc_col, - definition_name = stringr::str_replace( + from_cols = c("code", "title"), + to_cols = c(rc_col, stringr::str_replace( string = rc_col, pattern = "_code", replacement = "_text" - ) + )) ) } rt_cols <- stringr::str_subset( @@ -1708,8 +1518,7 @@ add_definitions <- function(tbl) { sep = " - ", remove = TRUE, na.rm = TRUE - ) |> - data.table::data.table() + ) } } trc_cols <- stringr::str_subset( @@ -1717,18 +1526,18 @@ add_definitions <- function(tbl) { pattern = "^ts_reason_code(|_[0-9])" ) if (length(trc_cols) > 0) { - reason_code_types <- entsoeapi::reason_code_types + reason_code_types <- reason_code_types for (trc_col in trc_cols) { affected_cols <- c(affected_cols, trc_col) - tbl <- def_merge( + tbl <- lookup_merge( x = tbl, y = reason_code_types, - code_name = trc_col, - definition_name = stringr::str_replace( + from_cols = c("code", "title"), + to_cols = c(trc_col, stringr::str_replace( string = trc_col, pattern = "_code", replacement = "_text" - ) + )) ) } trt_cols <- stringr::str_subset( @@ -1750,20 +1559,19 @@ add_definitions <- function(tbl) { sep = " - ", remove = TRUE, na.rm = TRUE - ) |> - data.table::data.table() + ) } } if ("ts_object_aggregation" %in% names(tbl)) { - object_aggregation_types <- entsoeapi::object_aggregation_types affected_cols <- c(affected_cols, "ts_object_aggregation") - tbl <- def_merge( + tbl <- lookup_merge( x = tbl, y = object_aggregation_types, - code_name = "ts_object_aggregation", - definition_name = "ts_object_aggregation_def" + from_cols = c("code", "title"), + to_cols = c("ts_object_aggregation", "ts_object_aggregation_def") ) } + if (length(affected_cols) == 0L) { cli::cli_alert_info("No additional definitions added!") } @@ -1809,7 +1617,7 @@ xml_to_table <- function(xml_content, tidy_output = FALSE) { sep = "T" ) result_tbl <- result_tbl |> - dplyr::select(!tidyselect::all_of(c(date_col, time_col))) + dplyr::select(!dplyr::all_of(c(date_col, time_col))) } } @@ -1817,7 +1625,7 @@ xml_to_table <- function(xml_content, tidy_output = FALSE) { result_tbl <- result_tbl |> dplyr::mutate( dplyr::across( - tidyselect::matches("[t|T]ime$|start$|end$"), + dplyr::matches("[t|T]ime$|start$|end$"), ~ as.POSIXct( x = .x, tryFormats = c( @@ -1829,7 +1637,7 @@ xml_to_table <- function(xml_content, tidy_output = FALSE) { ) |> dplyr::mutate( dplyr::across( - tidyselect::matches( + dplyr::matches( match = "number$|position$|quantity$|nominalP$|amount$", ignore.case = TRUE ), @@ -1976,7 +1784,7 @@ xml_to_table <- function(xml_content, tidy_output = FALSE) { if (length(needed_cols)) { # filter on the needed columns result_tbl <- result_tbl |> - dplyr::select(tidyselect::all_of(needed_cols)) + dplyr::select(dplyr::all_of(needed_cols)) # reorder the rows sort_cols <- base::intersect( @@ -1988,11 +1796,10 @@ xml_to_table <- function(xml_content, tidy_output = FALSE) { ), y = names(result_tbl) ) - result_dtbl <- data.table::as.data.table(result_tbl) - data.table::setkeyv(x = result_dtbl, cols = sort_cols) - - # convert the result to tibble - result_tbl <- tibble::as_tibble(result_dtbl) + result_tbl <- dplyr::arrange( + result_tbl, + dplyr::across(dplyr::all_of(sort_cols)) + ) # return result_tbl @@ -2050,10 +1857,7 @@ extract_response <- function(content, tidy_output = TRUE) { tidy_output = tidy_output ) |> purrr::compact() |> - data.table::rbindlist( - use.names = TRUE, - fill = TRUE - ) + dplyr::bind_rows() } else { NULL } @@ -2067,7 +1871,7 @@ extract_response <- function(content, tidy_output = TRUE) { } ) |> purrr::compact() |> - data.table::rbindlist(use.names = TRUE, fill = TRUE) |> + dplyr::bind_rows() |> tibble::as_tibble() } else { # convert XML to table @@ -2105,28 +1909,21 @@ extract_response <- function(content, tidy_output = TRUE) { #' @return A single logical value. #' #' @examples -#' \donttest{ -#' there_is_provider() -#' } +#' there_is_provider() #' #' @export there_is_provider <- function( - api_scheme = "https://", - api_domain = "web-api.tp.entsoe.eu/", - api_name = "api?" + api_scheme = .api_scheme, # nolint: object_usage_linter. + api_domain = .api_domain, # nolint: object_usage_linter. + api_name = .api_name # nolint: object_usage_linter. ) { - if (curl::has_internet()) { - req <- paste0( - api_scheme, api_domain, api_name, "foo=bar&securityToken=baz" - ) |> - httr2::request() |> - httr2::req_method(method = "GET") |> - httr2::req_retry(max_tries = 1L) - resp <- req_perform_safe(req) - if (!is.null(resp$error$resp) && - httr2::resp_status(resp$error$resp) == 401L) TRUE else FALSE - } else { - FALSE - } - + req <- paste0( + api_scheme, api_domain, api_name, "foo=bar&securityToken=baz" + ) |> + httr2::request() |> + httr2::req_method(method = "GET") |> + httr2::req_timeout(seconds = 5L) |> + httr2::req_retry(max_tries = 1L) + resp <- req_perform_safe(req) + !is.null(resp$error$resp) && httr2::resp_status(resp$error$resp) == 401L } diff --git a/README.Rmd b/README.Rmd index c97e1c51..9a03b898 100644 --- a/README.Rmd +++ b/README.Rmd @@ -193,4 +193,6 @@ entsoeapi::gen_per_prod_type( ## Code of Conduct -Please note that the entsoeapi project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/1/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms. +## Code of Conduct + +Please note that the entsoeapi project is released with a [Contributor Code of Conduct](https://krose.github.io/entsoeapi/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms. diff --git a/README.md b/README.md index d3637805..ace1937a 100644 --- a/README.md +++ b/README.md @@ -491,7 +491,7 @@ entsoeapi::load_actual_total( #> ── API call ──────────────────────────────────────────────────────────────────── #> → https://web-api.tp.entsoe.eu/api?documentType=A65&processType=A16&outBiddingZone_Domain=10Y1001A1001A83F&periodStart=201912312300&periodEnd=202001012300&securityToken=<...> #> <- HTTP/2 200 -#> <- date: Thu, 12 Mar 2026 11:09:36 GMT +#> <- date: Mon, 16 Mar 2026 21:35:56 GMT #> <- content-type: text/xml #> <- content-disposition: inline; filename="Actual Total Load_201912312300-202001012300.xml" #> <- x-content-type-options: nosniff @@ -501,6 +501,7 @@ entsoeapi::load_actual_total( #> <- strict-transport-security: max-age=15724800; includeSubDomains #> <- #> ✔ response has arrived +#> ℹ downloading area_eic_name table ... #> ℹ pulling Y_eicCodes.csv file from cache #> Rows: 96 #> Columns: 21 @@ -514,7 +515,7 @@ entsoeapi::load_actual_total( #> $ ts_object_aggregation_def "Area", "Area", "Area", "Area", "Area"… #> $ ts_business_type "A04", "A04", "A04", "A04", "A04", "A0… #> $ ts_business_type_def "Consumption", "Consumption", "Consump… -#> $ created_date_time 2026-03-12 11:09:36, 2026-03-12 11:09… +#> $ created_date_time 2026-03-16 21:35:56, 2026-03-16 21:35… #> $ revision_number 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,… #> $ time_period_time_interval_start 2019-12-31 23:00:00, 2019-12-31 23:00… #> $ time_period_time_interval_end 2020-01-01 23:00:00, 2020-01-01 23:00… @@ -544,7 +545,7 @@ entsoeapi::gen_per_prod_type( #> ── API call ──────────────────────────────────────────────────────────────────── #> → https://web-api.tp.entsoe.eu/api?documentType=A75&processType=A16&in_Domain=10Y1001A1001A83F&periodStart=201912312300&periodEnd=202001012300&securityToken=<...> #> <- HTTP/2 200 -#> <- date: Thu, 12 Mar 2026 11:09:40 GMT +#> <- date: Mon, 16 Mar 2026 21:36:01 GMT #> <- content-type: text/xml #> <- content-disposition: inline; filename="Aggregated Generation per Type_201912312300-202001012300.xml" #> <- x-content-type-options: nosniff @@ -554,6 +555,7 @@ entsoeapi::gen_per_prod_type( #> <- strict-transport-security: max-age=15724800; includeSubDomains #> <- #> ✔ response has arrived +#> ℹ pulling area_eic_name table from cache #> Rows: 1,632 #> Columns: 25 #> $ ts_in_bidding_zone_domain_mrid NA, NA, NA, NA, NA, NA, NA, NA, NA, NA… @@ -570,7 +572,7 @@ entsoeapi::gen_per_prod_type( #> $ ts_business_type_def "Production", "Production", "Productio… #> $ ts_mkt_psr_type "B10", "B10", "B10", "B10", "B10", "B1… #> $ ts_mkt_psr_type_def "Hydro-electric pure pumped storage he… -#> $ created_date_time 2026-03-12 11:09:40, 2026-03-12 11:09… +#> $ created_date_time 2026-03-16 21:36:01, 2026-03-16 21:36… #> $ revision_number 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,… #> $ time_period_time_interval_start 2019-12-31 23:00:00, 2019-12-31 23:00… #> $ time_period_time_interval_end 2020-01-01 23:00:00, 2020-01-01 23:00… @@ -585,7 +587,9 @@ entsoeapi::gen_per_prod_type( ## Code of Conduct +## Code of Conduct + Please note that the entsoeapi project is released with a [Contributor Code of -Conduct](https://contributor-covenant.org/version/2/1/CODE_OF_CONDUCT.html). -By contributing to this project, you agree to abide by its terms. +Conduct](https://krose.github.io/entsoeapi/CODE_OF_CONDUCT.html). By +contributing to this project, you agree to abide by its terms. diff --git a/RELEASE_CHECKLIST.md b/RELEASE_CHECKLIST.md index 8471fe42..ef35cd0e 100644 --- a/RELEASE_CHECKLIST.md +++ b/RELEASE_CHECKLIST.md @@ -2,6 +2,7 @@ ## 1. Prepare +- [ ] The package name is valid and available `pak::pkg_name_check("entsoeapi")` - [ ] All planned changes merged into `devel` - [ ] `NEWS.md` updated — new version header, all changes documented - [ ] Version bumped in `DESCRIPTION` (follow semver: major.minor.patch) diff --git a/data-raw/code_lists_creator.R b/data-raw/code_lists_creator.R index a35c2b96..e069f1a8 100644 --- a/data-raw/code_lists_creator.R +++ b/data-raw/code_lists_creator.R @@ -6,13 +6,13 @@ converts them to tables and places those in the data/ folder. # set the latest code list URL (use AI for search) url <- c( - "https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.7z", + "https://www.entsoe.eu/Documents/EDI/Library/CodelistV93.7z", "https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip" )[[-1L]] # set the working files and folders -tmp <- tempfile(fileext = ".zip") -out_main_dir <- fs::path_wd("data-raw") +tmp <- base::tempfile(fileext = ".zip") +out_main_dir <- base::normalizePath("data-raw") # ── 1. Download and extract the archive ────────────────────────────────────── # Build and perform the request @@ -21,21 +21,16 @@ httr2::request(base_url = url) |> httr2::req_perform(path = tmp) # streams directly to disk # Extract the archive -archive::archive_extract(archive = tmp, dir = out_main_dir) +decomp_files <- archive::archive_extract(archive = tmp, dir = out_main_dir) - -out_dir <- fs::dir_ls( - path = out_main_dir, - type = "directory", - glob = "*Codelist*" -) +out_dir <- paste(out_main_dir, decomp_files[[1L]], sep = "/") # ── 2. Locate the XSD file ─────────────────────────────────────────────────── -xsd_path <- fs::dir_ls( - path = out_main_dir, - recurse = TRUE, - type = "file", - regexp = "codelists\\.xsd$" +xsd_path <- list.files( + path = out_dir, + recursive = TRUE, + full.names = TRUE, + pattern = "codelists\\.xsd$" ) |> purrr::pluck(-1L) message("Using: ", xsd_path) @@ -65,7 +60,7 @@ parse_simple_type <- function(node) { return(NULL) } - data.table::data.table( + tibble::tibble( list_name = xml2::xml_attr(x = node, attr = "name") |> stringr::str_remove( pattern = "Standard" @@ -124,11 +119,12 @@ parse_simple_type <- function(node) { code_lists_combined <- simple_types |> purrr::map(parse_simple_type) |> purrr::compact() |> - data.table::rbindlist(use.names = TRUE, fill = TRUE) + dplyr::bind_rows() # ── 6. Split into a named list of individual tables ────────────────────────── code_lists <- code_lists_combined |> - split(by = "list_name", keep.by = FALSE) + base::split(f = code_lists_combined$list_name) |> + purrr::map(~base::subset(x = .x, select = c(code, title, description))) # ── 7. Inspect ─────────────────────────────────────────────────────────────── # number of code list tables diff --git a/data-raw/transmission_pair_eic_dict.R b/data-raw/transmission_pair_eic_dict.R index 823b06f9..e385ecbe 100644 --- a/data-raw/transmission_pair_eic_dict.R +++ b/data-raw/transmission_pair_eic_dict.R @@ -3,9 +3,10 @@ transmission_pair_eic_dict <- fs::path("data-raw", "transmission_pair_eic_dict", ext = "tsv" ) |> - data.table::fread(encoding = "UTF-8", fill = TRUE) |> + utils::read.delim(encoding = "UTF-8", fill = TRUE) |> purrr::modify_if(is.character, trimws, which = "both") |> - purrr::discard(~ is.na(.x) |> all()) + purrr::discard(~ all(is.na(.x))) |> + tibble::as_tibble() # save the package data in the correct format usethis::use_data(transmission_pair_eic_dict, overwrite = TRUE) diff --git a/data/allocation_mode_types.rda b/data/allocation_mode_types.rda index c6839ebf..567641ad 100644 Binary files a/data/allocation_mode_types.rda and b/data/allocation_mode_types.rda differ diff --git a/data/analog_types.rda b/data/analog_types.rda index 07ebf390..ad4c3536 100644 Binary files a/data/analog_types.rda and b/data/analog_types.rda differ diff --git a/data/area_types.rda b/data/area_types.rda index 012eaf26..1e6b80a9 100644 Binary files a/data/area_types.rda and b/data/area_types.rda differ diff --git a/data/asset_types.rda b/data/asset_types.rda index 1657c9f3..8069a814 100644 Binary files a/data/asset_types.rda and b/data/asset_types.rda differ diff --git a/data/auction_types.rda b/data/auction_types.rda index 72b315bb..f02381ab 100644 Binary files a/data/auction_types.rda and b/data/auction_types.rda differ diff --git a/data/business_types.rda b/data/business_types.rda index e46d3441..867812f9 100644 Binary files a/data/business_types.rda and b/data/business_types.rda differ diff --git a/data/category_types.rda b/data/category_types.rda index 299216be..7dce6361 100644 Binary files a/data/category_types.rda and b/data/category_types.rda differ diff --git a/data/classification_types.rda b/data/classification_types.rda index c07cbe0b..e3049a72 100644 Binary files a/data/classification_types.rda and b/data/classification_types.rda differ diff --git a/data/coding_scheme_types.rda b/data/coding_scheme_types.rda index e237b611..4fa145a1 100644 Binary files a/data/coding_scheme_types.rda and b/data/coding_scheme_types.rda differ diff --git a/data/connection_category_types.rda b/data/connection_category_types.rda index fef2ed72..a62d9c9f 100644 Binary files a/data/connection_category_types.rda and b/data/connection_category_types.rda differ diff --git a/data/contract_types.rda b/data/contract_types.rda index fbefdef9..052d14f1 100644 Binary files a/data/contract_types.rda and b/data/contract_types.rda differ diff --git a/data/coordinate_system_types.rda b/data/coordinate_system_types.rda index 180ec145..7b94cb3a 100644 Binary files a/data/coordinate_system_types.rda and b/data/coordinate_system_types.rda differ diff --git a/data/currency_types.rda b/data/currency_types.rda index 15a9d10b..d4ebd296 100644 Binary files a/data/currency_types.rda and b/data/currency_types.rda differ diff --git a/data/curve_types.rda b/data/curve_types.rda index 07a01873..cad4b41f 100644 Binary files a/data/curve_types.rda and b/data/curve_types.rda differ diff --git a/data/customer_types.rda b/data/customer_types.rda index 9222fc77..04f810b6 100644 Binary files a/data/customer_types.rda and b/data/customer_types.rda differ diff --git a/data/direction_types.rda b/data/direction_types.rda index 63abef82..b652dc5b 100644 Binary files a/data/direction_types.rda and b/data/direction_types.rda differ diff --git a/data/document_types.rda b/data/document_types.rda index 3a6b9757..f694c1c5 100644 Binary files a/data/document_types.rda and b/data/document_types.rda differ diff --git a/data/eic_types.rda b/data/eic_types.rda index 568c226a..a32986b2 100644 Binary files a/data/eic_types.rda and b/data/eic_types.rda differ diff --git a/data/energy_product_types.rda b/data/energy_product_types.rda index bd9f3afe..38901163 100644 Binary files a/data/energy_product_types.rda and b/data/energy_product_types.rda differ diff --git a/data/flow_commodity_option_types.rda b/data/flow_commodity_option_types.rda index a9af99ae..d474a396 100644 Binary files a/data/flow_commodity_option_types.rda and b/data/flow_commodity_option_types.rda differ diff --git a/data/fuel_types.rda b/data/fuel_types.rda index 2f4d8e34..0bddf847 100644 Binary files a/data/fuel_types.rda and b/data/fuel_types.rda differ diff --git a/data/grid_agreement_types.rda b/data/grid_agreement_types.rda index 2a054444..a8493052 100644 Binary files a/data/grid_agreement_types.rda and b/data/grid_agreement_types.rda differ diff --git a/data/hvdc_mode_types.rda b/data/hvdc_mode_types.rda index ece58aec..e8cf7377 100644 Binary files a/data/hvdc_mode_types.rda and b/data/hvdc_mode_types.rda differ diff --git a/data/indicator_types.rda b/data/indicator_types.rda index eb0d31b6..a52bdcfd 100644 Binary files a/data/indicator_types.rda and b/data/indicator_types.rda differ diff --git a/data/market_product_types.rda b/data/market_product_types.rda index 132be891..32bea0c2 100644 Binary files a/data/market_product_types.rda and b/data/market_product_types.rda differ diff --git a/data/message_types.rda b/data/message_types.rda index 3219af99..44d317c3 100644 Binary files a/data/message_types.rda and b/data/message_types.rda differ diff --git a/data/object_aggregation_types.rda b/data/object_aggregation_types.rda index 2d137b92..90d30a17 100644 Binary files a/data/object_aggregation_types.rda and b/data/object_aggregation_types.rda differ diff --git a/data/payment_terms_types.rda b/data/payment_terms_types.rda index 16668b4c..412bb394 100644 Binary files a/data/payment_terms_types.rda and b/data/payment_terms_types.rda differ diff --git a/data/price_category_types.rda b/data/price_category_types.rda index 3c932b6a..284697d1 100644 Binary files a/data/price_category_types.rda and b/data/price_category_types.rda differ diff --git a/data/price_component_types.rda b/data/price_component_types.rda index 32c39254..3163ff83 100644 Binary files a/data/price_component_types.rda and b/data/price_component_types.rda differ diff --git a/data/price_direction_types.rda b/data/price_direction_types.rda index 2e98fe7d..4c612753 100644 Binary files a/data/price_direction_types.rda and b/data/price_direction_types.rda differ diff --git a/data/process_types.rda b/data/process_types.rda index 8fee8560..98794b61 100644 Binary files a/data/process_types.rda and b/data/process_types.rda differ diff --git a/data/quality_types.rda b/data/quality_types.rda index bc8c6b95..2d8ca937 100644 Binary files a/data/quality_types.rda and b/data/quality_types.rda differ diff --git a/data/reason_code_types.rda b/data/reason_code_types.rda index b3c592a2..bec9f438 100644 Binary files a/data/reason_code_types.rda and b/data/reason_code_types.rda differ diff --git a/data/rights_types.rda b/data/rights_types.rda index 6f061022..148c4455 100644 Binary files a/data/rights_types.rda and b/data/rights_types.rda differ diff --git a/data/role_types.rda b/data/role_types.rda index 619a56c1..fd195231 100644 Binary files a/data/role_types.rda and b/data/role_types.rda differ diff --git a/data/settlement_method_types.rda b/data/settlement_method_types.rda index 45ec0a47..931c789b 100644 Binary files a/data/settlement_method_types.rda and b/data/settlement_method_types.rda differ diff --git a/data/status_types.rda b/data/status_types.rda index a190e09b..a264d336 100644 Binary files a/data/status_types.rda and b/data/status_types.rda differ diff --git a/data/sub_area_types.rda b/data/sub_area_types.rda index c5ae6aa5..3b35303f 100644 Binary files a/data/sub_area_types.rda and b/data/sub_area_types.rda differ diff --git a/data/tariff_types.rda b/data/tariff_types.rda index 5df59ce5..a5a4da92 100644 Binary files a/data/tariff_types.rda and b/data/tariff_types.rda differ diff --git a/data/timeframe_types.rda b/data/timeframe_types.rda index e507f4d1..60a32281 100644 Binary files a/data/timeframe_types.rda and b/data/timeframe_types.rda differ diff --git a/data/transmission_pair_eic_dict.rda b/data/transmission_pair_eic_dict.rda index 849b5c9c..c38f3cc2 100644 Binary files a/data/transmission_pair_eic_dict.rda and b/data/transmission_pair_eic_dict.rda differ diff --git a/data/unit_multiplier.rda b/data/unit_multiplier.rda index 71bd6328..8e106127 100644 Binary files a/data/unit_multiplier.rda and b/data/unit_multiplier.rda differ diff --git a/data/unit_of_measure_types.rda b/data/unit_of_measure_types.rda index 9a0fc19d..24fc541c 100644 Binary files a/data/unit_of_measure_types.rda and b/data/unit_of_measure_types.rda differ diff --git a/data/unit_symbol_types.rda b/data/unit_symbol_types.rda index 3ad2d91c..667d4f66 100644 Binary files a/data/unit_symbol_types.rda and b/data/unit_symbol_types.rda differ diff --git a/man/allocation_mode_types.Rd b/man/allocation_mode_types.Rd index 2d74e2c3..01165462 100644 --- a/man/allocation_mode_types.Rd +++ b/man/allocation_mode_types.Rd @@ -6,7 +6,7 @@ \title{List allocation mode types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 4 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 4 rows and 3 columns. } \usage{ allocation_mode_types diff --git a/man/analog_types.Rd b/man/analog_types.Rd index e72fbade..11768fe9 100644 --- a/man/analog_types.Rd +++ b/man/analog_types.Rd @@ -6,7 +6,7 @@ \title{List analog types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 42 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 42 rows and 3 columns. } \usage{ analog_types diff --git a/man/area_types.Rd b/man/area_types.Rd index 84cab603..e9d5edf7 100644 --- a/man/area_types.Rd +++ b/man/area_types.Rd @@ -6,7 +6,7 @@ \title{List area types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 2 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 2 rows and 3 columns. } \usage{ area_types diff --git a/man/asset_types.Rd b/man/asset_types.Rd index d8d094d6..42a9dce9 100644 --- a/man/asset_types.Rd +++ b/man/asset_types.Rd @@ -6,7 +6,7 @@ \title{List asset types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 90 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 90 rows and 3 columns. } \usage{ asset_types diff --git a/man/auction_types.Rd b/man/auction_types.Rd index 26a3f643..f96e091d 100644 --- a/man/auction_types.Rd +++ b/man/auction_types.Rd @@ -6,7 +6,7 @@ \title{List auction types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 8 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 8 rows and 3 columns. } \usage{ auction_types diff --git a/man/business_types.Rd b/man/business_types.Rd index b0bfdbe9..8234ef60 100644 --- a/man/business_types.Rd +++ b/man/business_types.Rd @@ -6,7 +6,7 @@ \title{List business types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 293 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 293 rows and 3 columns. } \usage{ business_types diff --git a/man/category_types.Rd b/man/category_types.Rd index f6009750..0a926cce 100644 --- a/man/category_types.Rd +++ b/man/category_types.Rd @@ -6,7 +6,7 @@ \title{List category types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 4 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 4 rows and 3 columns. } \usage{ category_types diff --git a/man/classification_types.Rd b/man/classification_types.Rd index 24e26a20..29d6a318 100644 --- a/man/classification_types.Rd +++ b/man/classification_types.Rd @@ -6,7 +6,7 @@ \title{List classification types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 2 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 2 rows and 3 columns. } \usage{ classification_types diff --git a/man/coding_scheme_types.Rd b/man/coding_scheme_types.Rd index ee393d16..23463f36 100644 --- a/man/coding_scheme_types.Rd +++ b/man/coding_scheme_types.Rd @@ -6,7 +6,7 @@ \title{List coding scheme types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 51 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 51 rows and 3 columns. } \usage{ coding_scheme_types diff --git a/man/connection_category_types.Rd b/man/connection_category_types.Rd index 77c9e5b1..ca7cc1bd 100644 --- a/man/connection_category_types.Rd +++ b/man/connection_category_types.Rd @@ -6,7 +6,7 @@ \title{List connection category types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 10 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 10 rows and 3 columns. } \usage{ connection_category_types diff --git a/man/contract_types.Rd b/man/contract_types.Rd index 1cab8def..689e89b2 100644 --- a/man/contract_types.Rd +++ b/man/contract_types.Rd @@ -6,7 +6,7 @@ \title{List contract types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 16 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 16 rows and 3 columns. } \usage{ contract_types diff --git a/man/coordinate_system_types.Rd b/man/coordinate_system_types.Rd index c7d29d5d..dfeceb1c 100644 --- a/man/coordinate_system_types.Rd +++ b/man/coordinate_system_types.Rd @@ -6,7 +6,7 @@ \title{List coordinate system types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 4 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 4 rows and 3 columns. } \usage{ coordinate_system_types diff --git a/man/currency_types.Rd b/man/currency_types.Rd index 2ebffea4..94df188a 100644 --- a/man/currency_types.Rd +++ b/man/currency_types.Rd @@ -6,7 +6,7 @@ \title{List currency types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 23 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 23 rows and 3 columns. } \usage{ currency_types diff --git a/man/curve_types.Rd b/man/curve_types.Rd index 75ab210e..fedbf446 100644 --- a/man/curve_types.Rd +++ b/man/curve_types.Rd @@ -6,7 +6,7 @@ \title{List curve types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 5 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 5 rows and 3 columns. } \usage{ curve_types diff --git a/man/customer_types.Rd b/man/customer_types.Rd index 5bcc7007..f1360fcd 100644 --- a/man/customer_types.Rd +++ b/man/customer_types.Rd @@ -6,7 +6,7 @@ \title{List customer types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 4 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 4 rows and 3 columns. } \usage{ customer_types diff --git a/man/direction_types.Rd b/man/direction_types.Rd index deece958..ea43ec1a 100644 --- a/man/direction_types.Rd +++ b/man/direction_types.Rd @@ -6,7 +6,7 @@ \title{List direction types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 4 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 4 rows and 3 columns. } \usage{ direction_types diff --git a/man/document_types.Rd b/man/document_types.Rd index 640ec84e..7b451762 100644 --- a/man/document_types.Rd +++ b/man/document_types.Rd @@ -6,7 +6,7 @@ \title{List document types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 103 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 103 rows and 3 columns. } \usage{ document_types diff --git a/man/eic_types.Rd b/man/eic_types.Rd index 3144c161..b64b8fc2 100644 --- a/man/eic_types.Rd +++ b/man/eic_types.Rd @@ -6,7 +6,7 @@ \title{List EIC types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 7 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 7 rows and 3 columns. } \usage{ eic_types diff --git a/man/energy_product_types.Rd b/man/energy_product_types.Rd index 418991fe..55e0bfb7 100644 --- a/man/energy_product_types.Rd +++ b/man/energy_product_types.Rd @@ -6,7 +6,7 @@ \title{List energy product types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 9 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 9 rows and 3 columns. } \usage{ energy_product_types diff --git a/man/flow_commodity_option_types.Rd b/man/flow_commodity_option_types.Rd index 88b63b54..769bd64c 100644 --- a/man/flow_commodity_option_types.Rd +++ b/man/flow_commodity_option_types.Rd @@ -6,7 +6,7 @@ \title{List flow commodity types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 4 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 4 rows and 3 columns. } \usage{ flow_commodity_option_types diff --git a/man/fuel_types.Rd b/man/fuel_types.Rd index 122081cb..21751692 100644 --- a/man/fuel_types.Rd +++ b/man/fuel_types.Rd @@ -6,7 +6,7 @@ \title{List fuel types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 55 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 55 rows and 3 columns. } \usage{ fuel_types diff --git a/man/grid_agreement_types.Rd b/man/grid_agreement_types.Rd index 82c19072..071185dd 100644 --- a/man/grid_agreement_types.Rd +++ b/man/grid_agreement_types.Rd @@ -6,7 +6,7 @@ \title{List grid agreement types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 4 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 4 rows and 3 columns. } \usage{ grid_agreement_types diff --git a/man/hvdc_mode_types.Rd b/man/hvdc_mode_types.Rd index 81c306b7..70b2d671 100644 --- a/man/hvdc_mode_types.Rd +++ b/man/hvdc_mode_types.Rd @@ -6,7 +6,7 @@ \title{List HVDC mode types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 3 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 3 rows and 3 columns. } \usage{ hvdc_mode_types diff --git a/man/indicator_types.Rd b/man/indicator_types.Rd index 0239fe93..d7002b5d 100644 --- a/man/indicator_types.Rd +++ b/man/indicator_types.Rd @@ -6,7 +6,7 @@ \title{List indicator types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 2 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 2 rows and 3 columns. } \usage{ indicator_types diff --git a/man/market_product_types.Rd b/man/market_product_types.Rd index bb27efcd..324c8087 100644 --- a/man/market_product_types.Rd +++ b/man/market_product_types.Rd @@ -6,7 +6,7 @@ \title{List market product types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 14 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 14 rows and 3 columns. } \usage{ market_product_types diff --git a/man/message_types.Rd b/man/message_types.Rd index a131a0b2..96244ca1 100644 --- a/man/message_types.Rd +++ b/man/message_types.Rd @@ -6,7 +6,7 @@ \title{List message types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 150 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 150 rows and 3 columns. } \usage{ message_types diff --git a/man/object_aggregation_types.Rd b/man/object_aggregation_types.Rd index 7a90da58..abe35134 100644 --- a/man/object_aggregation_types.Rd +++ b/man/object_aggregation_types.Rd @@ -6,7 +6,7 @@ \title{List object aggregation types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 16 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 16 rows and 3 columns. } \usage{ object_aggregation_types diff --git a/man/payment_terms_types.Rd b/man/payment_terms_types.Rd index 523b4d7a..b8c0ecc5 100644 --- a/man/payment_terms_types.Rd +++ b/man/payment_terms_types.Rd @@ -6,7 +6,7 @@ \title{List payment terms types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 3 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 3 rows and 3 columns. } \usage{ payment_terms_types diff --git a/man/price_category_types.Rd b/man/price_category_types.Rd index 8ef7c885..08efa441 100644 --- a/man/price_category_types.Rd +++ b/man/price_category_types.Rd @@ -6,7 +6,7 @@ \title{List price category types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 8 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 8 rows and 3 columns. } \usage{ price_category_types diff --git a/man/price_component_types.Rd b/man/price_component_types.Rd index cc78f7e8..acaf6a83 100644 --- a/man/price_component_types.Rd +++ b/man/price_component_types.Rd @@ -6,7 +6,7 @@ \title{List price component types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 3 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 3 rows and 3 columns. } \usage{ price_component_types diff --git a/man/price_direction_types.Rd b/man/price_direction_types.Rd index 4c2f5fd3..695d1929 100644 --- a/man/price_direction_types.Rd +++ b/man/price_direction_types.Rd @@ -6,7 +6,7 @@ \title{List price direction types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 2 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 2 rows and 3 columns. } \usage{ price_direction_types diff --git a/man/process_types.Rd b/man/process_types.Rd index a2d15921..0e24c089 100644 --- a/man/process_types.Rd +++ b/man/process_types.Rd @@ -6,7 +6,7 @@ \title{List process types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 75 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 75 rows and 3 columns. } \usage{ process_types diff --git a/man/quality_types.Rd b/man/quality_types.Rd index 1e271398..9e60633e 100644 --- a/man/quality_types.Rd +++ b/man/quality_types.Rd @@ -6,7 +6,7 @@ \title{List quality types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 7 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 7 rows and 3 columns. } \usage{ quality_types diff --git a/man/reason_code_types.Rd b/man/reason_code_types.Rd index 8141eb65..1c1fd348 100644 --- a/man/reason_code_types.Rd +++ b/man/reason_code_types.Rd @@ -6,7 +6,7 @@ \title{List reason code types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 166 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 166 rows and 3 columns. } \usage{ reason_code_types diff --git a/man/rights_types.Rd b/man/rights_types.Rd index 634023ca..1294826f 100644 --- a/man/rights_types.Rd +++ b/man/rights_types.Rd @@ -6,7 +6,7 @@ \title{List rights types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 6 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 6 rows and 3 columns. } \usage{ rights_types diff --git a/man/role_types.Rd b/man/role_types.Rd index deea3f4f..e73a9c8e 100644 --- a/man/role_types.Rd +++ b/man/role_types.Rd @@ -6,7 +6,7 @@ \title{List role types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 59 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 59 rows and 3 columns. } \usage{ role_types diff --git a/man/settlement_method_types.Rd b/man/settlement_method_types.Rd index 5cbd6e54..156eff77 100644 --- a/man/settlement_method_types.Rd +++ b/man/settlement_method_types.Rd @@ -6,7 +6,7 @@ \title{List settlement method types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 2 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 2 rows and 3 columns. } \usage{ settlement_method_types diff --git a/man/status_types.Rd b/man/status_types.Rd index 93a36450..520dd864 100644 --- a/man/status_types.Rd +++ b/man/status_types.Rd @@ -6,7 +6,7 @@ \title{List status types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 76 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 76 rows and 3 columns. } \usage{ status_types diff --git a/man/sub_area_types.Rd b/man/sub_area_types.Rd index 46d379d3..2fa6176b 100644 --- a/man/sub_area_types.Rd +++ b/man/sub_area_types.Rd @@ -6,7 +6,7 @@ \title{List sub-area types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 7 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 7 rows and 3 columns. } \usage{ sub_area_types diff --git a/man/tariff_types.Rd b/man/tariff_types.Rd index d0615fcc..e49653f6 100644 --- a/man/tariff_types.Rd +++ b/man/tariff_types.Rd @@ -6,7 +6,7 @@ \title{List tariff types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 7 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 7 rows and 3 columns. } \usage{ tariff_types diff --git a/man/there_is_provider.Rd b/man/there_is_provider.Rd index 0f072438..4d833283 100644 --- a/man/there_is_provider.Rd +++ b/man/there_is_provider.Rd @@ -5,9 +5,9 @@ \title{Check if the ENTSO-E API provider is reachable} \usage{ there_is_provider( - api_scheme = "https://", - api_domain = "web-api.tp.entsoe.eu/", - api_name = "api?" + api_scheme = .api_scheme, + api_domain = .api_domain, + api_name = .api_name ) } \arguments{ @@ -28,8 +28,6 @@ is no internet connection or when the server is unreachable. Primarily intended as an \verb{@examplesIf} guard in package documentation. } \examples{ -\donttest{ - there_is_provider() -} +there_is_provider() } diff --git a/man/timeframe_types.Rd b/man/timeframe_types.Rd index b5912f5f..b47bce52 100644 --- a/man/timeframe_types.Rd +++ b/man/timeframe_types.Rd @@ -6,7 +6,7 @@ \title{List timeframe types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 46 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 46 rows and 3 columns. } \usage{ timeframe_types diff --git a/man/transmission_pair_eic_dict.Rd b/man/transmission_pair_eic_dict.Rd index 35f630e0..f6cc0eb9 100644 --- a/man/transmission_pair_eic_dict.Rd +++ b/man/transmission_pair_eic_dict.Rd @@ -5,7 +5,7 @@ \alias{transmission_pair_eic_dict} \title{List transmission pair EIC Dictionary} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 114 rows and 8 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 114 rows and 8 columns. } \usage{ transmission_pair_eic_dict diff --git a/man/unit_multiplier.Rd b/man/unit_multiplier.Rd index b7f26377..f157e88b 100644 --- a/man/unit_multiplier.Rd +++ b/man/unit_multiplier.Rd @@ -6,7 +6,7 @@ \title{List unit multiplier based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 1 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 1 rows and 3 columns. } \usage{ unit_multiplier diff --git a/man/unit_of_measure_types.Rd b/man/unit_of_measure_types.Rd index 6444c6a2..db86372b 100644 --- a/man/unit_of_measure_types.Rd +++ b/man/unit_of_measure_types.Rd @@ -6,7 +6,7 @@ \title{List unit of measure types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 33 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 33 rows and 3 columns. } \usage{ unit_of_measure_types diff --git a/man/unit_symbol_types.Rd b/man/unit_symbol_types.Rd index 7681c289..e59703db 100644 --- a/man/unit_symbol_types.Rd +++ b/man/unit_symbol_types.Rd @@ -6,7 +6,7 @@ \title{List unit symbol types based on 'https://www.entsoe.eu/Documents/EDI/Library/CodelistV94.zip'} \format{ -An object of class \code{data.table} (inherits from \code{data.frame}) with 11 rows and 3 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 11 rows and 3 columns. } \usage{ unit_symbol_types diff --git a/tests/testthat/test-en_balancing.R b/tests/testthat/test-en_balancing.R index 18dc29b4..6f2f5762 100644 --- a/tests/testthat/test-en_balancing.R +++ b/tests/testthat/test-en_balancing.R @@ -1,53 +1,6 @@ testthat::test_that( - desc = "elastic_demands() works", + desc = "elastic_demands() validates inputs", code = { - testthat::skip_if_not( - condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, - message = "No ENTSOE_PAT environment variable set" - ) - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) - testthat::expect_no_error( - object = result_full <- elastic_demands( - eic = "10YCZ-CEPS-----N", - period_start = lubridate::ymd( - x = "2024-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-12-01", - tz = "CET" - ), - process_type = "A47", - tidy_output = TRUE - ), - message = "uses offsetting" - ) - testthat::expect_contains( - object = names(result_full), - expected = c( - "bid_ts_mrid", - "bid_ts_auction_mrid", - "bid_ts_flow_direction" - ) - ) - testthat::expect_no_error( - object = elastic_demands( - eic = "10YCZ-CEPS-----N", - process_type = "A47", - period_start = lubridate::ymd( - x = "2024-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-01-02", - tz = "CET" - ), - tidy_output = TRUE - ) - ) testthat::expect_error( object = elastic_demands( eic = NULL, @@ -60,7 +13,8 @@ testthat::test_that( x = "2020-03-01", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "One control area EIC should be provided!" ) @@ -76,7 +30,8 @@ testthat::test_that( x = "2020-03-01", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "This wrapper only supports one control area EIC per request!" ) @@ -92,7 +47,8 @@ testthat::test_that( x = "2021-03-01", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "One year range limit should be applied!" ) @@ -125,7 +81,8 @@ testthat::test_that( x = "2020-03-01", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), regexp = paste0( "Assertion on 'process_type' failed: ", @@ -144,7 +101,8 @@ testthat::test_that( x = "2020-03-01", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), regexp = paste0( "Assertion on 'process_type' failed: ", @@ -156,7 +114,7 @@ testthat::test_that( testthat::test_that( - desc = "netted_volumes() works", + desc = "elastic_demands() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -167,22 +125,33 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = netted_volumes( + object = result_full <- elastic_demands( eic = "10YCZ-CEPS-----N", period_start = lubridate::ymd( x = "2024-01-01", tz = "CET" ), period_end = lubridate::ymd( - x = "2024-01-02", + x = "2024-12-01", tz = "CET" ), + process_type = "A47", tidy_output = TRUE - ) + ), + message = "uses offsetting" ) testthat::expect_contains( - object = netted_volumes( - eic = "10YDE-VE-------2", + object = names(result_full), + expected = c( + "bid_ts_mrid", + "bid_ts_auction_mrid", + "bid_ts_flow_direction" + ) + ) + testthat::expect_no_error( + object = elastic_demands( + eic = "10YCZ-CEPS-----N", + process_type = "A47", period_start = lubridate::ymd( x = "2024-01-01", tz = "CET" @@ -192,14 +161,15 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ) |> - names(), - expected = c( - "ts_connecting_domain_mrid", - "ts_acquiring_domain_mrid", - "ts_point_quantity" ) ) + } +) + + +testthat::test_that( + desc = "netted_volumes() validates inputs", + code = { testthat::expect_error( object = netted_volumes( eic = NULL, @@ -211,7 +181,8 @@ testthat::test_that( x = "2020-02-02", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "One control area EIC should be provided!" ) @@ -226,7 +197,8 @@ testthat::test_that( x = "2020-02-02", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "This wrapper only supports one control area EIC per request!" ) @@ -241,7 +213,8 @@ testthat::test_that( x = "2021-03-01", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "One day range limit should be applied!" ) @@ -266,7 +239,7 @@ testthat::test_that( testthat::test_that( - desc = "exchanged_volumes() works", + desc = "netted_volumes() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -276,24 +249,9 @@ testthat::test_that( condition = there_is_provider(), message = "The Entso-e API cannot be reached" ) - testthat::expect_error( - object = exchanged_volumes( - eic = "10YCZ-CEPS-----N", - period_start = lubridate::ymd( - x = "2024-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-01-02", - tz = "CET" - ), - tidy_output = TRUE - ) - ) - testthat::expect_error( - object = exchanged_volumes( + testthat::expect_no_error( + object = netted_volumes( eic = "10YCZ-CEPS-----N", - process_type = "A264537254", period_start = lubridate::ymd( x = "2024-01-01", tz = "CET" @@ -305,10 +263,9 @@ testthat::test_that( tidy_output = TRUE ) ) - testthat::expect_no_error( - object = exchanged_volumes( - eic = "10YCZ-CEPS-----N", - process_type = "A51", + testthat::expect_contains( + object = netted_volumes( + eic = "10YDE-VE-------2", period_start = lubridate::ymd( x = "2024-01-01", tz = "CET" @@ -318,12 +275,24 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE + ) |> + names(), + expected = c( + "ts_connecting_domain_mrid", + "ts_acquiring_domain_mrid", + "ts_point_quantity" ) ) - testthat::expect_no_error( + } +) + + +testthat::test_that( + desc = "exchanged_volumes() validates inputs", + code = { + testthat::expect_error( object = exchanged_volumes( eic = "10YCZ-CEPS-----N", - process_type = "A60", period_start = lubridate::ymd( x = "2024-01-01", tz = "CET" @@ -332,13 +301,14 @@ testthat::test_that( x = "2024-01-02", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) - testthat::expect_contains( + testthat::expect_error( object = exchanged_volumes( eic = "10YCZ-CEPS-----N", - process_type = "A60", + process_type = "A264537254", period_start = lubridate::ymd( x = "2024-01-01", tz = "CET" @@ -347,13 +317,8 @@ testthat::test_that( x = "2024-01-02", tz = "CET" ), - tidy_output = TRUE - ) |> - names(), - expected = c( - "ts_connecting_domain_mrid", - "ts_acquiring_domain_mrid", - "ts_point_quantity" + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -368,7 +333,8 @@ testthat::test_that( x = "2020-02-02", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "One control area EIC should be provided!" ) @@ -384,7 +350,8 @@ testthat::test_that( x = "2020-02-02", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "This wrapper only supports one control area EIC per request!" ) @@ -400,7 +367,8 @@ testthat::test_that( x = "2021-03-01", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "One day range limit should be applied!" ) @@ -426,7 +394,7 @@ testthat::test_that( testthat::test_that( - desc = "balancing_border_cap_limit() works", + desc = "exchanged_volumes() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -436,29 +404,10 @@ testthat::test_that( condition = there_is_provider(), message = "The Entso-e API cannot be reached" ) - for (pt in c("A47", "A51", "A63")) { - testthat::expect_no_error( - object = balancing_border_cap_limit( - eic_in = "10YDE-RWENET---I", - eic_out = "10YBE----------2", - process_type = "A51", - period_start = lubridate::ymd( - x = "2024-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-01-02", - tz = "CET" - ), - tidy_output = TRUE - ) - ) - } - testthat::expect_error( - object = balancing_border_cap_limit( - eic_in = "10YDE-RWENET---I", - eic_out = "10YBE----------2", - process_type = "A264537254", + testthat::expect_no_error( + object = exchanged_volumes( + eic = "10YCZ-CEPS-----N", + process_type = "A51", period_start = lubridate::ymd( x = "2024-01-01", tz = "CET" @@ -471,10 +420,9 @@ testthat::test_that( ) ) testthat::expect_no_error( - object = balancing_border_cap_limit( - eic_in = "10YDE-RWENET---I", - eic_out = "10YBE----------2", - process_type = "A47", + object = exchanged_volumes( + eic = "10YCZ-CEPS-----N", + process_type = "A60", period_start = lubridate::ymd( x = "2024-01-01", tz = "CET" @@ -486,11 +434,10 @@ testthat::test_that( tidy_output = TRUE ) ) - testthat::expect_no_error( - object = balancing_border_cap_limit( - eic_in = "10YDE-RWENET---I", - eic_out = "10YBE----------2", - process_type = "A51", + testthat::expect_contains( + object = exchanged_volumes( + eic = "10YCZ-CEPS-----N", + process_type = "A60", period_start = lubridate::ymd( x = "2024-01-01", tz = "CET" @@ -500,13 +447,26 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE + ) |> + names(), + expected = c( + "ts_connecting_domain_mrid", + "ts_acquiring_domain_mrid", + "ts_point_quantity" ) ) - testthat::expect_contains( + } +) + + +testthat::test_that( + desc = "balancing_border_cap_limit() validates inputs", + code = { + testthat::expect_error( object = balancing_border_cap_limit( eic_in = "10YDE-RWENET---I", eic_out = "10YBE----------2", - process_type = "A51", + process_type = "A264537254", period_start = lubridate::ymd( x = "2024-01-01", tz = "CET" @@ -515,13 +475,8 @@ testthat::test_that( x = "2024-01-02", tz = "CET" ), - tidy_output = TRUE - ) |> - names(), - expected = c( - "ts_in_domain_mrid", - "ts_out_domain_mrid", - "ts_point_quantity" + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -537,7 +492,8 @@ testthat::test_that( x = "2020-02-02", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "This wrapper only supports one in and one out EIC per request." ) @@ -554,7 +510,8 @@ testthat::test_that( x = "2020-02-02", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "This wrapper only supports one in and one out EIC per request." ) @@ -572,7 +529,8 @@ testthat::test_that( x = "2024-01-02", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = paste( "None or one Transmission Asset (eic_interconnector)", @@ -610,7 +568,8 @@ testthat::test_that( x = "2025-12-02", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "One year range limit should be applied!" ) @@ -621,7 +580,8 @@ testthat::test_that( process_type = "A51", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), regexp = paste0( "Assertion on 'eic_in' failed: ", @@ -635,7 +595,8 @@ testthat::test_that( process_type = "A51", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), regexp = paste0( "Assertion on 'eic_out' failed: ", @@ -647,7 +608,7 @@ testthat::test_that( testthat::test_that( - desc = "exchanged_volumes_per_border() works", + desc = "balancing_border_cap_limit() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -657,24 +618,94 @@ testthat::test_that( condition = there_is_provider(), message = "The Entso-e API cannot be reached" ) - testthat::expect_no_error( - object = exchanged_volumes_per_border( - acquiring_eic = "10YCZ-CEPS-----N", - connecting_eic = "10YSK-SEPS-----K", - process_type = "A51", - period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE - ) - ) - testthat::expect_error( + for (pt in c("A47", "A51", "A63")) { + testthat::expect_no_error( + object = balancing_border_cap_limit( + eic_in = "10YDE-RWENET---I", + eic_out = "10YBE----------2", + process_type = "A51", + period_start = lubridate::ymd( + x = "2024-01-01", + tz = "CET" + ), + period_end = lubridate::ymd( + x = "2024-01-02", + tz = "CET" + ), + tidy_output = TRUE + ) + ) + } + testthat::expect_no_error( + object = balancing_border_cap_limit( + eic_in = "10YDE-RWENET---I", + eic_out = "10YBE----------2", + process_type = "A47", + period_start = lubridate::ymd( + x = "2024-01-01", + tz = "CET" + ), + period_end = lubridate::ymd( + x = "2024-01-02", + tz = "CET" + ), + tidy_output = TRUE + ) + ) + testthat::expect_no_error( + object = balancing_border_cap_limit( + eic_in = "10YDE-RWENET---I", + eic_out = "10YBE----------2", + process_type = "A51", + period_start = lubridate::ymd( + x = "2024-01-01", + tz = "CET" + ), + period_end = lubridate::ymd( + x = "2024-01-02", + tz = "CET" + ), + tidy_output = TRUE + ) + ) + testthat::expect_contains( + object = balancing_border_cap_limit( + eic_in = "10YDE-RWENET---I", + eic_out = "10YBE----------2", + process_type = "A51", + period_start = lubridate::ymd( + x = "2024-01-01", + tz = "CET" + ), + period_end = lubridate::ymd( + x = "2024-01-02", + tz = "CET" + ), + tidy_output = TRUE + ) |> + names(), + expected = c( + "ts_in_domain_mrid", + "ts_out_domain_mrid", + "ts_point_quantity" + ) + ) + } +) + + +testthat::test_that( + desc = "exchanged_volumes_per_border() validates inputs", + code = { + testthat::expect_error( object = exchanged_volumes_per_border( acquiring_eic = NULL, connecting_eic = "10YSK-SEPS-----K", process_type = "A51", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), regexp = paste0( "Assertion on 'acquiring_eic' failed: ", @@ -688,7 +719,8 @@ testthat::test_that( process_type = "A51", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), regexp = "Assertion on 'acquiring_eic' failed: Must have length 1" ) @@ -699,7 +731,8 @@ testthat::test_that( process_type = "INVALID", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "The 'process_type' should be 'A51', 'A60' or 'A61'." ) @@ -710,7 +743,8 @@ testthat::test_that( process_type = "A51", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-05", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), regexp = "One day range limit should be applied" ) @@ -733,7 +767,8 @@ testthat::test_that( process_type = "A51", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), regexp = paste( "Assertion on 'connecting_eic' failed:", @@ -747,7 +782,8 @@ testthat::test_that( process_type = "A51", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), regexp = "Assertion on 'connecting_eic' failed: Must have length 1" ) @@ -756,7 +792,7 @@ testthat::test_that( testthat::test_that( - desc = "hvdc_link_constrains() works", + desc = "exchanged_volumes_per_border() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -767,21 +803,30 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = hvdc_link_constrains( - eic_in = "10YDK-1--------W", - eic_out = "10YNL----------L", - period_start = lubridate::ymd(x = "2021-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2021-01-02", tz = "CET"), + object = exchanged_volumes_per_border( + acquiring_eic = "10YCZ-CEPS-----N", + connecting_eic = "10YSK-SEPS-----K", + process_type = "A51", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE ) ) + } +) + + +testthat::test_that( + desc = "hvdc_link_constrains() validates inputs", + code = { testthat::expect_error( object = hvdc_link_constrains( eic_in = NULL, eic_out = "10YDE-RWENET---I", period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), regexp = paste0( "Assertion on 'eic_in' failed: ", @@ -794,7 +839,8 @@ testthat::test_that( eic_out = NULL, period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), regexp = paste0( "Assertion on 'eic_out' failed: ", @@ -807,7 +853,8 @@ testthat::test_that( eic_out = "10YDE-RWENET---I", period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), regexp = "Assertion on 'eic_in' failed: Must have length 1" ) @@ -817,7 +864,8 @@ testthat::test_that( eic_out = "10YDE-RWENET---I", period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2023-05-01", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), regexp = "One year range limit should be applied" ) @@ -843,7 +891,8 @@ testthat::test_that( eic_ic = c("AAAA", "BBBB"), period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), regexp = "Assertion on 'eic_ic' failed: Must have length 1." ) @@ -854,7 +903,8 @@ testthat::test_that( process_type = "INVALID", period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), regexp = paste( "Assertion on 'process_type' failed:", @@ -866,7 +916,7 @@ testthat::test_that( testthat::test_that( - desc = "changes_to_bid_availability() works", + desc = "hvdc_link_constrains() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -876,32 +926,29 @@ testthat::test_that( condition = there_is_provider(), message = "The Entso-e API cannot be reached" ) - for (bt in paste0("C", 40L:46L)) { - testthat::expect_no_error( - object = changes_to_bid_availability( - eic = "10YCZ-CEPS-----N", - business_type = bt, - period_start = lubridate::ymd(x = "2023-09-24", tz = "CET"), - period_end = lubridate::ymd(x = "2023-09-25", tz = "CET"), - tidy_output = TRUE - ), - message = bt - ) - } testthat::expect_no_error( - object = changes_to_bid_availability( - eic = "10YCZ-CEPS-----N", - period_start = lubridate::ymd(x = "2023-09-24", tz = "CET"), - period_end = lubridate::ymd(x = "2023-09-25", tz = "CET"), + object = hvdc_link_constrains( + eic_in = "10YDK-1--------W", + eic_out = "10YNL----------L", + period_start = lubridate::ymd(x = "2021-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2021-01-02", tz = "CET"), tidy_output = TRUE ) ) + } +) + + +testthat::test_that( + desc = "changes_to_bid_availability() validates inputs", + code = { testthat::expect_error( object = changes_to_bid_availability( eic = NULL, period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) @@ -910,7 +957,8 @@ testthat::test_that( eic = c("10YCZ-CEPS-----N", "10YDE-VE-------2"), period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), regexp = "Assertion on 'eic' failed: Must have length 1" ) @@ -920,7 +968,8 @@ testthat::test_that( business_type = "INVALID", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), regexp = paste( "Assertion on 'business_type' failed: Must be element of set", @@ -946,7 +995,8 @@ testthat::test_that( eic = "10YCZ-CEPS-----N", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2025-05-01", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), regexp = "One year range limit should be applied" ) @@ -955,7 +1005,7 @@ testthat::test_that( testthat::test_that( - desc = "current_balancing_state() works", + desc = "changes_to_bid_availability() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -965,20 +1015,40 @@ testthat::test_that( condition = there_is_provider(), message = "The Entso-e API cannot be reached" ) + for (bt in paste0("C", 40L:46L)) { + testthat::expect_no_error( + object = changes_to_bid_availability( + eic = "10YCZ-CEPS-----N", + business_type = bt, + period_start = lubridate::ymd(x = "2023-09-24", tz = "CET"), + period_end = lubridate::ymd(x = "2023-09-25", tz = "CET"), + tidy_output = TRUE + ), + message = bt + ) + } testthat::expect_no_error( - object = current_balancing_state( + object = changes_to_bid_availability( eic = "10YCZ-CEPS-----N", - period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + period_start = lubridate::ymd(x = "2023-09-24", tz = "CET"), + period_end = lubridate::ymd(x = "2023-09-25", tz = "CET"), tidy_output = TRUE ) ) + } +) + + +testthat::test_that( + desc = "current_balancing_state() validates inputs", + code = { testthat::expect_error( object = current_balancing_state( eic = NULL, period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "One control area EIC should be provided." ) @@ -987,7 +1057,8 @@ testthat::test_that( eic = c("10YCZ-CEPS-----N", "10YDE-VE-------2"), period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "This wrapper only supports one control area EIC per request." ) @@ -996,7 +1067,8 @@ testthat::test_that( eic = "10YCZ-CEPS-----N", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-06-01", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "100 day range limit should be applied!" ) @@ -1015,7 +1087,7 @@ testthat::test_that( testthat::test_that( - desc = "balancing_energy_bids() works", + desc = "current_balancing_state() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -1026,19 +1098,27 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = balancing_energy_bids( + object = current_balancing_state( eic = "10YCZ-CEPS-----N", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2025-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE ) ) + } +) + + +testthat::test_that( + desc = "balancing_energy_bids() validates inputs", + code = { testthat::expect_error( object = balancing_energy_bids( eic = NULL, period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "One connecting domain EIC should be provided." ) @@ -1047,7 +1127,8 @@ testthat::test_that( eic = c("10YCZ-CEPS-----N", "10YDE-VE-------2"), period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "This wrapper only supports one connecting domain EIC per request." ) @@ -1066,7 +1147,7 @@ testthat::test_that( testthat::test_that( - desc = "aggregated_balancing_energy_bids() works", + desc = "balancing_energy_bids() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -1077,21 +1158,28 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = aggregated_balancing_energy_bids( + object = balancing_energy_bids( eic = "10YCZ-CEPS-----N", - process_type = "A51", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + period_end = lubridate::ymd(x = "2025-01-01", tz = "CET"), tidy_output = TRUE ) ) + } +) + + +testthat::test_that( + desc = "aggregated_balancing_energy_bids() validates inputs", + code = { testthat::expect_error( object = aggregated_balancing_energy_bids( eic = NULL, process_type = "A51", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "One control area EIC should be provided." ) @@ -1101,7 +1189,8 @@ testthat::test_that( process_type = "A51", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "This wrapper only supports one control area EIC per request." ) @@ -1111,7 +1200,8 @@ testthat::test_that( process_type = "INVALID", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "The 'process_type' should be 'A51', 'A46', 'A47', 'A60' or 'A61'." ) @@ -1121,7 +1211,8 @@ testthat::test_that( process_type = "A51", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2025-05-01", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "One year range limit should be applied!" ) @@ -1141,7 +1232,7 @@ testthat::test_that( testthat::test_that( - desc = "procured_balancing_capacity() works", + desc = "aggregated_balancing_energy_bids() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -1152,7 +1243,7 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = procured_balancing_capacity( + object = aggregated_balancing_energy_bids( eic = "10YCZ-CEPS-----N", process_type = "A51", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), @@ -1160,13 +1251,21 @@ testthat::test_that( tidy_output = TRUE ) ) + } +) + + +testthat::test_that( + desc = "procured_balancing_capacity() validates inputs", + code = { testthat::expect_error( object = procured_balancing_capacity( eic = NULL, process_type = "A51", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "One control area EIC should be provided." ) @@ -1176,7 +1275,8 @@ testthat::test_that( process_type = "A51", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "This wrapper only supports one control area EIC per request." ) @@ -1186,7 +1286,8 @@ testthat::test_that( process_type = "INVALID", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "The 'process_type' should be 'A51', 'A52' or 'A47'." ) @@ -1197,7 +1298,8 @@ testthat::test_that( type_market_agreement = c("A01", "A13"), period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "None or one 'type_market_agreement' should be provided." ) @@ -1212,22 +1314,12 @@ testthat::test_that( ), info = "Valid security token should be provided." ) - testthat::expect_no_error( - object = procured_balancing_capacity( - eic = "10YCZ-CEPS-----N", - process_type = "A51", - type_market_agreement = "A01", - period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE - ) - ) } ) testthat::test_that( - desc = "allocation_of_cross_zonal_balancing_cap() works", + desc = "procured_balancing_capacity() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -1238,21 +1330,39 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = allocation_of_cross_zonal_balancing_cap( - eic_acquiring = "10YAT-APG------L", - eic_connecting = "10YCH-SWISSGRIDZ", + object = procured_balancing_capacity( + eic = "10YCZ-CEPS-----N", + process_type = "A51", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + tidy_output = TRUE + ) + ) + testthat::expect_no_error( + object = procured_balancing_capacity( + eic = "10YCZ-CEPS-----N", + process_type = "A51", + type_market_agreement = "A01", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE ) ) + } +) + + +testthat::test_that( + desc = "allocation_of_cross_zonal_balancing_cap() validates inputs", + code = { testthat::expect_error( object = allocation_of_cross_zonal_balancing_cap( eic_acquiring = NULL, eic_connecting = "10YCH-SWISSGRIDZ", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "One acquiring domain EIC should be provided." ) @@ -1262,7 +1372,8 @@ testthat::test_that( eic_connecting = NULL, period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "One connecting domain EIC should be provided." ) @@ -1272,7 +1383,8 @@ testthat::test_that( eic_connecting = "10YCH-SWISSGRIDZ", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = paste( "This wrapper only supports one acquiring and", @@ -1286,7 +1398,8 @@ testthat::test_that( type_market_agreement = c("A01", "A13"), period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "None or one 'type_market_agreement' should be provided." ) @@ -1301,22 +1414,12 @@ testthat::test_that( ), info = "Valid security token should be provided." ) - testthat::expect_no_error( - object = allocation_of_cross_zonal_balancing_cap( - eic_acquiring = "10YAT-APG------L", - eic_connecting = "10YCH-SWISSGRIDZ", - type_market_agreement = "A01", - period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE - ) - ) } ) testthat::test_that( - desc = "contracted_reserves() works", + desc = "allocation_of_cross_zonal_balancing_cap() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -1327,21 +1430,39 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = contracted_reserves( - eic = "10YCZ-CEPS-----N", - type_market_agreement = "A13", - period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), + object = allocation_of_cross_zonal_balancing_cap( + eic_acquiring = "10YAT-APG------L", + eic_connecting = "10YCH-SWISSGRIDZ", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + tidy_output = TRUE + ) + ) + testthat::expect_no_error( + object = allocation_of_cross_zonal_balancing_cap( + eic_acquiring = "10YAT-APG------L", + eic_connecting = "10YCH-SWISSGRIDZ", + type_market_agreement = "A01", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE ) ) + } +) + + +testthat::test_that( + desc = "contracted_reserves() validates inputs", + code = { testthat::expect_error( object = contracted_reserves( eic = NULL, type_market_agreement = "A13", period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "One control area EIC should be provided." ) @@ -1351,7 +1472,8 @@ testthat::test_that( type_market_agreement = "A13", period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "This wrapper only supports one control area EIC per request." ) @@ -1361,7 +1483,8 @@ testthat::test_that( type_market_agreement = NULL, period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "A 'type_market_agreement' value should be provided." ) @@ -1371,7 +1494,8 @@ testthat::test_that( type_market_agreement = c("A01", "A13"), period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "Only one 'type_market_agreement' value should be provided." ) @@ -1386,6 +1510,30 @@ testthat::test_that( ), info = "Valid security token should be provided." ) + } +) + + +testthat::test_that( + desc = "contracted_reserves() works", + code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) + testthat::expect_no_error( + object = contracted_reserves( + eic = "10YCZ-CEPS-----N", + type_market_agreement = "A13", + period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), + tidy_output = TRUE + ) + ) testthat::expect_no_error( object = contracted_reserves( eic = "10YCZ-CEPS-----N", @@ -1411,30 +1559,15 @@ testthat::test_that( testthat::test_that( - desc = "activated_balancing_prices() works", + desc = "activated_balancing_prices() validates inputs", code = { - testthat::skip_if_not( - condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, - message = "No ENTSOE_PAT environment variable set" - ) - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) - testthat::expect_no_error( - object = activated_balancing_prices( - eic = "10YCZ-CEPS-----N", - period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE - ) - ) testthat::expect_error( object = activated_balancing_prices( eic = NULL, period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "One control area EIC should be provided." ) @@ -1443,7 +1576,8 @@ testthat::test_that( eic = c("10YCZ-CEPS-----N", "10YDE-VE-------2"), period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "This wrapper only supports one control area EIC per request." ) @@ -1452,7 +1586,8 @@ testthat::test_that( eic = "10YCZ-CEPS-----N", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2025-05-01", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "One year range limit should be applied!" ) @@ -1471,7 +1606,7 @@ testthat::test_that( testthat::test_that( - desc = "activated_balancing_prices() covers business_type branch with mock", + desc = "activated_balancing_prices() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -1481,6 +1616,21 @@ testthat::test_that( condition = there_is_provider(), message = "The Entso-e API cannot be reached" ) + testthat::expect_no_error( + object = activated_balancing_prices( + eic = "10YCZ-CEPS-----N", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + tidy_output = TRUE + ) + ) + } +) + + +testthat::test_that( + desc = "activated_balancing_prices() covers business_type branch with mock", + code = { httr2::local_mocked_responses( mock = function(req) { httr2::response( @@ -1511,30 +1661,15 @@ testthat::test_that( testthat::test_that( - desc = "imbalance_prices() works", + desc = "imbalance_prices() validates inputs", code = { - testthat::skip_if_not( - condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, - message = "No ENTSOE_PAT environment variable set" - ) - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) - testthat::expect_no_error( - object = imbalance_prices( - eic = "10YCZ-CEPS-----N", - period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE - ) - ) testthat::expect_error( object = imbalance_prices( eic = NULL, period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "One control area EIC should be provided." ) @@ -1543,7 +1678,8 @@ testthat::test_that( eic = c("10YCZ-CEPS-----N", "10YDE-VE-------2"), period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "This wrapper only supports one control area EIC per request." ) @@ -1552,7 +1688,8 @@ testthat::test_that( eic = "10YCZ-CEPS-----N", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2025-05-01", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "One year range limit should be applied!" ) @@ -1571,7 +1708,7 @@ testthat::test_that( testthat::test_that( - desc = "imbalance_volumes() works", + desc = "imbalance_prices() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -1582,19 +1719,27 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = imbalance_volumes( + object = imbalance_prices( eic = "10YCZ-CEPS-----N", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE ) ) + } +) + + +testthat::test_that( + desc = "imbalance_volumes() validates inputs", + code = { testthat::expect_error( object = imbalance_volumes( eic = NULL, period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "One control area EIC should be provided." ) @@ -1603,7 +1748,8 @@ testthat::test_that( eic = c("10YCZ-CEPS-----N", "10YDE-VE-------2"), period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "This wrapper only supports one control area EIC per request." ) @@ -1612,7 +1758,8 @@ testthat::test_that( eic = "10YCZ-CEPS-----N", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2025-05-01", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "One year range limit should be applied!" ) @@ -1631,7 +1778,7 @@ testthat::test_that( testthat::test_that( - desc = "financial_expenses_and_income_for_balancing() works", + desc = "imbalance_volumes() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -1642,19 +1789,27 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = financial_expenses_and_income_for_balancing( + object = imbalance_volumes( eic = "10YCZ-CEPS-----N", - period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE ) ) + } +) + + +testthat::test_that( + desc = "financial_expenses_and_income_for_balancing() validates inputs", + code = { testthat::expect_error( object = financial_expenses_and_income_for_balancing( eic = NULL, period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "One control area EIC should be provided." ) @@ -1663,7 +1818,8 @@ testthat::test_that( eic = c("10YCZ-CEPS-----N", "10YDE-VE-------2"), period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "This wrapper only supports one control area EIC per request." ) @@ -1672,7 +1828,8 @@ testthat::test_that( eic = "10YCZ-CEPS-----N", period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2023-05-01", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "One year range limit should be applied!" ) @@ -1691,7 +1848,7 @@ testthat::test_that( testthat::test_that( - desc = "fcr_total_capacity() works", + desc = "financial_expenses_and_income_for_balancing() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -1702,19 +1859,27 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = fcr_total_capacity( - eic = "10YEU-CONT-SYNC0", - period_start = lubridate::ymd(x = "2023-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2024-01-01", tz = "CET"), + object = financial_expenses_and_income_for_balancing( + eic = "10YCZ-CEPS-----N", + period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), tidy_output = TRUE ) ) + } +) + + +testthat::test_that( + desc = "fcr_total_capacity() validates inputs", + code = { testthat::expect_error( object = fcr_total_capacity( eic = NULL, period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) @@ -1723,7 +1888,8 @@ testthat::test_that( eic = c("10YEU-CONT-SYNC0", "10YDE-VE-------2"), period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), regexp = "Assertion on 'eic' failed: Must have length 1" ) @@ -1732,7 +1898,8 @@ testthat::test_that( eic = "10YEU-CONT-SYNC0", period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2023-05-01", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), regexp = "One year range limit should be applied" ) @@ -1755,7 +1922,7 @@ testthat::test_that( testthat::test_that( - desc = "shares_of_fcr_capacity() works", + desc = "fcr_total_capacity() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -1766,21 +1933,28 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = shares_of_fcr_capacity( - eic = "10YDE-VE-------2", - business_type = "C23", - period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2023-01-01", tz = "CET"), + object = fcr_total_capacity( + eic = "10YEU-CONT-SYNC0", + period_start = lubridate::ymd(x = "2023-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-01", tz = "CET"), tidy_output = TRUE ) ) + } +) + + +testthat::test_that( + desc = "shares_of_fcr_capacity() validates inputs", + code = { testthat::expect_error( object = shares_of_fcr_capacity( eic = NULL, business_type = "C23", period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "One area EIC should be provided." ) @@ -1790,7 +1964,8 @@ testthat::test_that( business_type = "C23", period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "This wrapper only supports one area EIC per request." ) @@ -1800,7 +1975,8 @@ testthat::test_that( business_type = "INVALID", period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "The 'business_type' should be 'C23' or 'B95'." ) @@ -1810,7 +1986,8 @@ testthat::test_that( business_type = "C23", period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2023-05-01", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "One year range limit should be applied!" ) @@ -1830,7 +2007,7 @@ testthat::test_that( testthat::test_that( - desc = "rr_and_frr_actual_capacity() works", + desc = "shares_of_fcr_capacity() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -1841,21 +2018,29 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = rr_and_frr_actual_capacity( - eic = "10YAT-APG------L", - process_type = "A56", + object = shares_of_fcr_capacity( + eic = "10YDE-VE-------2", + business_type = "C23", period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2022-04-01", tz = "CET"), + period_end = lubridate::ymd(x = "2023-01-01", tz = "CET"), tidy_output = TRUE ) ) + } +) + + +testthat::test_that( + desc = "rr_and_frr_actual_capacity() validates inputs", + code = { testthat::expect_error( object = rr_and_frr_actual_capacity( eic = NULL, process_type = "A56", period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-04-01", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "One area EIC should be provided." ) @@ -1865,7 +2050,8 @@ testthat::test_that( process_type = "A56", period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-04-01", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "This wrapper only supports one area EIC per request." ) @@ -1875,7 +2061,8 @@ testthat::test_that( process_type = "INVALID", period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-04-01", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "The 'process_type' should be 'A56' (FRR) or 'A46' (RR)." ) @@ -1897,7 +2084,8 @@ testthat::test_that( business_type = "INVALID", period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-04-01", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), regexp = paste0( "Assertion on 'business_type' failed: ", @@ -1909,7 +2097,7 @@ testthat::test_that( testthat::test_that( - desc = "rr_actual_capacity() works", + desc = "rr_and_frr_actual_capacity() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -1920,19 +2108,28 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = rr_actual_capacity( - eic = "10YCZ-CEPS-----N", + object = rr_and_frr_actual_capacity( + eic = "10YAT-APG------L", + process_type = "A56", period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-04-01", tz = "CET"), tidy_output = TRUE ) ) + } +) + + +testthat::test_that( + desc = "rr_actual_capacity() validates inputs", + code = { testthat::expect_error( object = rr_actual_capacity( eic = NULL, period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-04-01", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "One area EIC should be provided." ) @@ -1941,7 +2138,8 @@ testthat::test_that( eic = c("10YAT-APG------L", "10YDE-VE-------2"), period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-04-01", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "This wrapper only supports one area EIC per request." ) @@ -1960,7 +2158,7 @@ testthat::test_that( testthat::test_that( - desc = "sharing_of_frr_capacity() works", + desc = "rr_actual_capacity() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -1970,6 +2168,21 @@ testthat::test_that( condition = there_is_provider(), message = "The Entso-e API cannot be reached" ) + testthat::expect_no_error( + object = rr_actual_capacity( + eic = "10YCZ-CEPS-----N", + period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2022-04-01", tz = "CET"), + tidy_output = TRUE + ) + ) + } +) + + +testthat::test_that( + desc = "sharing_of_frr_capacity() validates inputs", + code = { # Note: [A26, A56, C22] combination is not available via the public API. # The happy path for sharing_of_frr_capacity() cannot be exercised # without a mock. @@ -1980,7 +2193,8 @@ testthat::test_that( process_type = "A56", period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "One acquiring domain EIC should be provided." ) @@ -1991,7 +2205,8 @@ testthat::test_that( process_type = "A56", period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "One connecting domain EIC should be provided." ) @@ -2002,7 +2217,8 @@ testthat::test_that( process_type = "A56", period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = paste( "This wrapper only supports one acquiring and", @@ -2016,7 +2232,8 @@ testthat::test_that( process_type = "INVALID", period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "The 'process_type' should be 'A56' (FRR) or 'A46' (RR)." ) @@ -2027,7 +2244,8 @@ testthat::test_that( process_type = "A56", period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2023-05-01", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ), info = "One year range limit should be applied!" ) @@ -2048,7 +2266,7 @@ testthat::test_that( testthat::test_that( - desc = "sharing_of_frr_capacity() covers happy path with mock", + desc = "sharing_of_frr_capacity() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -2058,6 +2276,13 @@ testthat::test_that( condition = there_is_provider(), message = "The Entso-e API cannot be reached" ) + } +) + + +testthat::test_that( + desc = "sharing_of_frr_capacity() covers happy path with mock", + code = { httr2::local_mocked_responses( mock = function(req) { httr2::response( @@ -2086,3 +2311,622 @@ testthat::test_that( ) } ) + + +testthat::test_that( + desc = "elastic_demands() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = elastic_demands( + eic = "10YCZ-CEPS-----N", + process_type = "A47", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "netted_volumes() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = netted_volumes( + eic = "10YCZ-CEPS-----N", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "exchanged_volumes() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = exchanged_volumes( + eic = "10YCZ-CEPS-----N", + process_type = "A51", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "balancing_border_cap_limit() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = balancing_border_cap_limit( + eic_in = "10YDE-RWENET---I", + eic_out = "10YBE----------2", + process_type = "A51", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "exchanged_volumes_per_border() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = exchanged_volumes_per_border( + acquiring_eic = "10YBE----------2", + connecting_eic = "10YFR-RTE------C", + process_type = "A60", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "hvdc_link_constrains() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = hvdc_link_constrains( + eic_in = "10YAT-APG------L", + eic_out = "10YDE-RWENET---I", + process_type = "A63", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "changes_to_bid_availability() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = changes_to_bid_availability( + eic = "10YCZ-CEPS-----N", + business_type = "C46", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "current_balancing_state() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = current_balancing_state( + eic = "10YCZ-CEPS-----N", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "balancing_energy_bids() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = balancing_energy_bids( + eic = "10YCZ-CEPS-----N", + process_type = "A47", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "aggregated_balancing_energy_bids() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = aggregated_balancing_energy_bids( + eic = "10YCZ-CEPS-----N", + process_type = "A47", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "procured_balancing_capacity() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = procured_balancing_capacity( + eic = "10YCZ-CEPS-----N", + process_type = "A51", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "allocation_of_cross_zonal_balancing_cap covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = allocation_of_cross_zonal_balancing_cap( + eic_acquiring = "10YCB-GERMANY--8", + eic_connecting = "10YAT-APG------L", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "contracted_reserves() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = contracted_reserves( + eic = "10YCZ-CEPS-----N", + type_market_agreement = "A01", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "imbalance_prices() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = imbalance_prices( + eic = "10YCZ-CEPS-----N", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "imbalance_volumes() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = imbalance_volumes( + eic = "10YCZ-CEPS-----N", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = paste( + "financial_expenses_and_income_for_balancing()", + "covers happy path with mock" + ), + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = financial_expenses_and_income_for_balancing( + eic = "10YCZ-CEPS-----N", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "fcr_total_capacity() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = fcr_total_capacity( + eic = "10YCZ-CEPS-----N", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "shares_of_fcr_capacity() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = shares_of_fcr_capacity( + eic = "10YCZ-CEPS-----N", + business_type = "C23", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "rr_and_frr_actual_capacity() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = rr_and_frr_actual_capacity( + eic = "10YCZ-CEPS-----N", + process_type = "A56", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "rr_actual_capacity() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = rr_actual_capacity( + eic = "10YCZ-CEPS-----N", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) diff --git a/tests/testthat/test-en_generation.R b/tests/testthat/test-en_generation.R index 37c015d1..1e878b20 100644 --- a/tests/testthat/test-en_generation.R +++ b/tests/testthat/test-en_generation.R @@ -1,40 +1,20 @@ testthat::test_that( - desc = "gen_installed_capacity_per_pt() works", + desc = "gen_installed_capacity_per_pt() validates inputs", code = { - testthat::skip_if_not( - condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, - message = "No ENTSOE_PAT environment variable set" - ) - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) - testthat::expect_no_error( - object = gen_installed_capacity_per_pt( - eic = "10YFR-RTE------C", - year = lubridate::year(x = Sys.Date()), - psr_type = NULL - ) - ) - testthat::expect_no_error( - object = gen_installed_capacity_per_pt( - eic = "10YFR-RTE------C", - year = lubridate::year(x = Sys.Date()), - psr_type = "B01" - ) - ) testthat::expect_error( object = gen_installed_capacity_per_pt( eic = "10YFR-RTE------C", year = lubridate::year(x = Sys.Date()) - 3.4, - psr_type = NULL + psr_type = NULL, + security_token = "dummy_token" ) ) testthat::expect_error( object = gen_installed_capacity_per_pt( eic = NULL, year = lubridate::year(x = Sys.Date()), - psr_type = NULL + psr_type = NULL, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -48,7 +28,8 @@ testthat::test_that( object = gen_installed_capacity_per_pt( eic = c("10YFR-RTE------C", "10YDE-VE-------2"), year = lubridate::year(x = Sys.Date()), - psr_type = NULL + psr_type = NULL, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -58,7 +39,8 @@ testthat::test_that( lubridate::year(x = Sys.Date()), lubridate::year(x = Sys.Date()) - 1L ), - psr_type = NULL + psr_type = NULL, + security_token = "dummy_token" ) ) } @@ -66,7 +48,7 @@ testthat::test_that( testthat::test_that( - desc = "gen_installed_capacity_per_pu() works", + desc = "gen_installed_capacity_per_pt() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -77,24 +59,32 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = gen_installed_capacity_per_pu( + object = gen_installed_capacity_per_pt( eic = "10YFR-RTE------C", year = lubridate::year(x = Sys.Date()), psr_type = NULL ) ) testthat::expect_no_error( - object = gen_installed_capacity_per_pu( + object = gen_installed_capacity_per_pt( eic = "10YFR-RTE------C", - year = lubridate::year(x = Sys.Date()) + 3L, - psr_type = NULL + year = lubridate::year(x = Sys.Date()), + psr_type = "B01" ) ) + } +) + + +testthat::test_that( + desc = "gen_installed_capacity_per_pu() validates inputs", + code = { testthat::expect_error( object = gen_installed_capacity_per_pu( eic = "10YFR-RTE------C", year = lubridate::year(x = Sys.Date()) + 1.4, - psr_type = NULL + psr_type = NULL, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -104,20 +94,74 @@ testthat::test_that( lubridate::year(x = Sys.Date()), lubridate::year(x = Sys.Date()) - 1L ), + psr_type = NULL, + security_token = "dummy_token" + ) + ) + testthat::expect_error( + object = gen_installed_capacity_per_pu( + eic = "10YFR-RTE------C", + year = lubridate::year(x = Sys.Date()) + 4L, + psr_type = NULL, + security_token = "dummy_token" + ) + ) + testthat::expect_error( + object = gen_installed_capacity_per_pu( + eic = NULL, + year = lubridate::year(x = Sys.Date()), + psr_type = NULL, + security_token = "dummy_token" + ) + ) + testthat::expect_error( + object = gen_installed_capacity_per_pu( + eic = "10YFR-RTE------C", + year = lubridate::year(x = Sys.Date()), + security_token = "" + ) + ) + testthat::expect_error( + object = gen_installed_capacity_per_pu( + eic = c("10YFR-RTE------C", "10YDE-VE-------2"), + year = lubridate::year(x = Sys.Date()), + psr_type = NULL, + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "gen_installed_capacity_per_pu() works", + code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) + testthat::expect_no_error( + object = gen_installed_capacity_per_pu( + eic = "10YFR-RTE------C", + year = lubridate::year(x = Sys.Date()), psr_type = NULL ) ) testthat::expect_no_error( object = gen_installed_capacity_per_pu( eic = "10YFR-RTE------C", - year = 1492, + year = lubridate::year(x = Sys.Date()) + 3L, psr_type = NULL ) ) - testthat::expect_error( + testthat::expect_no_error( object = gen_installed_capacity_per_pu( eic = "10YFR-RTE------C", - year = lubridate::year(x = Sys.Date()) + 4L, + year = 1492, psr_type = NULL ) ) @@ -128,25 +172,70 @@ testthat::test_that( psr_type = "B01" ) ) + } +) + + +testthat::test_that( + desc = "gen_storage_mean_filling_rate() validates inputs", + code = { testthat::expect_error( - object = gen_installed_capacity_per_pu( + object = gen_storage_mean_filling_rate( + eic = c("10YFR-RTE------C", "10YDE-VE-------2"), + period_start = lubridate::ymd( + x = "2020-02-01", + tz = "CET" + ), + period_end = lubridate::ymd( + x = "2020-03-01", + tz = "CET" + ), + tidy_output = TRUE, + security_token = "dummy_token" + ) + ) + testthat::expect_error( + object = gen_storage_mean_filling_rate( eic = NULL, - year = lubridate::year(x = Sys.Date()), - psr_type = NULL + period_start = lubridate::ymd( + x = "2020-02-01", + tz = "CET" + ), + period_end = lubridate::ymd( + x = "2020-03-01", + tz = "CET" + ), + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( - object = gen_installed_capacity_per_pu( + object = gen_storage_mean_filling_rate( eic = "10YFR-RTE------C", - year = lubridate::year(x = Sys.Date()), + period_start = lubridate::ymd( + x = "2020-02-01", + tz = "CET" + ), + period_end = lubridate::ymd( + x = "2020-03-01", + tz = "CET" + ), security_token = "" ) ) testthat::expect_error( - object = gen_installed_capacity_per_pu( - eic = c("10YFR-RTE------C", "10YDE-VE-------2"), - year = lubridate::year(x = Sys.Date()), - psr_type = NULL + object = gen_storage_mean_filling_rate( + eic = "10YFR-RTE------C", + period_start = lubridate::ymd( + x = "2020-02-01", + tz = "CET" + ), + period_end = lubridate::ymd( + x = "2022-03-01", + tz = "CET" + ), + tidy_output = TRUE, + security_token = "dummy_token" ) ) } @@ -206,8 +295,15 @@ testthat::test_that( tidy_output = FALSE ) ) + } +) + + +testthat::test_that( + desc = "gen_per_prod_type() validates inputs", + code = { testthat::expect_error( - object = gen_storage_mean_filling_rate( + object = gen_per_prod_type( eic = c("10YFR-RTE------C", "10YDE-VE-------2"), period_start = lubridate::ymd( x = "2020-02-01", @@ -217,11 +313,13 @@ testthat::test_that( x = "2020-03-01", tz = "CET" ), - tidy_output = TRUE + gen_type = NULL, + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( - object = gen_storage_mean_filling_rate( + object = gen_per_prod_type( eic = NULL, period_start = lubridate::ymd( x = "2020-02-01", @@ -231,11 +329,13 @@ testthat::test_that( x = "2020-03-01", tz = "CET" ), - tidy_output = TRUE + gen_type = NULL, + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( - object = gen_storage_mean_filling_rate( + object = gen_per_prod_type( eic = "10YFR-RTE------C", period_start = lubridate::ymd( x = "2020-02-01", @@ -249,7 +349,7 @@ testthat::test_that( ) ) testthat::expect_error( - object = gen_storage_mean_filling_rate( + object = gen_per_prod_type( eic = "10YFR-RTE------C", period_start = lubridate::ymd( x = "2020-02-01", @@ -259,7 +359,9 @@ testthat::test_that( x = "2022-03-01", tz = "CET" ), - tidy_output = TRUE + gen_type = NULL, + tidy_output = TRUE, + security_token = "dummy_token" ) ) } @@ -307,63 +409,75 @@ testthat::test_that( tidy_output = TRUE ) ) + } +) + + +testthat::test_that( + desc = "gen_per_gen_unit() validates inputs", + code = { testthat::expect_error( - object = gen_per_prod_type( - eic = c("10YFR-RTE------C", "10YDE-VE-------2"), + object = gen_per_gen_unit( + eic = "10YDE-VE-------2", period_start = lubridate::ymd( - x = "2020-02-01", + x = "2020-01-31", tz = "CET" ), period_end = lubridate::ymd( - x = "2020-03-01", + x = "2020-02-01", tz = "CET" ), gen_type = NULL, - tidy_output = TRUE + tidy_output = TRUE, + security_token = "" ) ) testthat::expect_error( - object = gen_per_prod_type( + object = gen_per_gen_unit( eic = NULL, period_start = lubridate::ymd( - x = "2020-02-01", + x = "2020-01-31", tz = "CET" ), period_end = lubridate::ymd( - x = "2020-03-01", + x = "2020-02-01", tz = "CET" ), gen_type = NULL, - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( - object = gen_per_prod_type( - eic = "10YFR-RTE------C", + object = gen_per_gen_unit( + eic = c("10YDE-VE-------2", "10YFR-RTE------C"), period_start = lubridate::ymd( - x = "2020-02-01", + x = "2020-01-31", tz = "CET" ), period_end = lubridate::ymd( - x = "2020-03-01", + x = "2020-02-01", tz = "CET" ), - security_token = "" + gen_type = NULL, + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( - object = gen_per_prod_type( - eic = "10YFR-RTE------C", + object = gen_per_gen_unit( + eic = "10YDE-VE-------2", period_start = lubridate::ymd( - x = "2020-02-01", + x = "2020-01-31", tz = "CET" ), period_end = lubridate::ymd( - x = "2022-03-01", + x = "2020-02-01", tz = "CET" ), gen_type = NULL, - tidy_output = TRUE + tidy_output = TRUE, + security_token = NULL ) ) } @@ -441,66 +555,71 @@ testthat::test_that( tidy_output = TRUE ) ) + } +) + + +testthat::test_that( + desc = "gen_day_ahead_forecast() validates inputs", + code = { testthat::expect_error( - object = gen_per_gen_unit( - eic = "10YDE-VE-------2", + object = gen_day_ahead_forecast( + eic = "10YFR-RTE------C", period_start = lubridate::ymd( - x = "2020-01-31", + x = "2020-02-01", tz = "CET" ), period_end = lubridate::ymd( - x = "2020-02-01", + x = "2020-03-01", tz = "CET" ), - gen_type = NULL, tidy_output = TRUE, security_token = "" ) ) testthat::expect_error( - object = gen_per_gen_unit( + object = gen_day_ahead_forecast( eic = NULL, period_start = lubridate::ymd( - x = "2020-01-31", + x = "2020-02-01", tz = "CET" ), period_end = lubridate::ymd( - x = "2020-02-01", + x = "2020-03-01", tz = "CET" ), - gen_type = NULL, - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( - object = gen_per_gen_unit( - eic = c("10YDE-VE-------2", "10YFR-RTE------C"), + object = gen_day_ahead_forecast( + eic = c("10YFR-RTE------C", "10YDE-VE-------2"), period_start = lubridate::ymd( - x = "2020-01-31", + x = "2020-02-01", tz = "CET" ), period_end = lubridate::ymd( - x = "2020-02-01", + x = "2020-03-01", tz = "CET" ), - gen_type = NULL, - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( - object = gen_per_gen_unit( - eic = "10YDE-VE-------2", + object = gen_day_ahead_forecast( + eic = "10YFR-RTE------C", period_start = lubridate::ymd( - x = "2020-01-31", + x = "2020-02-01", tz = "CET" ), period_end = lubridate::ymd( - x = "2020-02-01", + x = "2021-03-01", tz = "CET" ), - gen_type = NULL, tidy_output = TRUE, - security_token = NULL + security_token = "dummy_token" ) ) } @@ -532,9 +651,16 @@ testthat::test_that( tidy_output = TRUE ) ) + } +) + + +testthat::test_that( + desc = "gen_wind_solar_forecasts() validates inputs", + code = { testthat::expect_error( - object = gen_day_ahead_forecast( - eic = "10YFR-RTE------C", + object = gen_wind_solar_forecasts( + eic = c("10YFR-RTE------C", "10YDE-VE-------2"), period_start = lubridate::ymd( x = "2020-02-01", tz = "CET" @@ -544,11 +670,11 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE, - security_token = "" + security_token = "dummy_token" ) ) testthat::expect_error( - object = gen_day_ahead_forecast( + object = gen_wind_solar_forecasts( eic = NULL, period_start = lubridate::ymd( x = "2020-02-01", @@ -558,12 +684,13 @@ testthat::test_that( x = "2020-03-01", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( - object = gen_day_ahead_forecast( - eic = c("10YFR-RTE------C", "10YDE-VE-------2"), + object = gen_wind_solar_forecasts( + eic = "10YFR-RTE------C", period_start = lubridate::ymd( x = "2020-02-01", tz = "CET" @@ -572,11 +699,12 @@ testthat::test_that( x = "2020-03-01", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "" ) ) testthat::expect_error( - object = gen_day_ahead_forecast( + object = gen_wind_solar_forecasts( eic = "10YFR-RTE------C", period_start = lubridate::ymd( x = "2020-02-01", @@ -586,7 +714,8 @@ testthat::test_that( x = "2021-03-01", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) } @@ -618,61 +747,217 @@ testthat::test_that( tidy_output = TRUE ) ) + } +) + + +testthat::test_that( + desc = "gen_installed_capacity_per_pt() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) testthat::expect_error( - object = gen_wind_solar_forecasts( - eic = c("10YFR-RTE------C", "10YDE-VE-------2"), - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), - tidy_output = TRUE + object = gen_installed_capacity_per_pt( + eic = "10YFR-RTE------C", + year = 2020L, + security_token = "dummy_token" ) ) + } +) + + +testthat::test_that( + desc = "gen_installed_capacity_per_pu() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) testthat::expect_error( - object = gen_wind_solar_forecasts( - eic = NULL, - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), - tidy_output = TRUE + object = gen_installed_capacity_per_pu( + eic = "10YDE-VE-------2", + year = 2020L, + security_token = "dummy_token" ) ) + } +) + + +testthat::test_that( + desc = "gen_per_prod_type() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) testthat::expect_error( - object = gen_wind_solar_forecasts( + object = gen_per_prod_type( eic = "10YFR-RTE------C", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "" + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "gen_storage_mean_filling_rate() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = gen_storage_mean_filling_rate( + eic = "10YFR-RTE------C", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + tidy_output = TRUE, + security_token = "dummy_token" ) ) + } +) + + +testthat::test_that( + desc = "gen_per_gen_unit() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = gen_per_gen_unit( + eic = "10YDE-VE-------2", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + tidy_output = TRUE, + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "gen_day_ahead_forecast() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = gen_day_ahead_forecast( + eic = "10YFR-RTE------C", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + tidy_output = TRUE, + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "gen_wind_solar_forecasts() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) testthat::expect_error( object = gen_wind_solar_forecasts( eic = "10YFR-RTE------C", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2021-03-01", - tz = "CET" - ), - tidy_output = TRUE + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + tidy_output = TRUE, + security_token = "dummy_token" ) ) } diff --git a/tests/testthat/test-en_helpers.R b/tests/testthat/test-en_helpers.R index 14016b84..32e42c11 100644 --- a/tests/testthat/test-en_helpers.R +++ b/tests/testthat/test-en_helpers.R @@ -1,3 +1,14 @@ +testthat::test_that( + desc = "all_approved_eic() validates inputs", + code = { + testthat::expect_error( + object = all_approved_eic("foo"), + regexp = 'unused argument \\("foo"\\)' + ) + } +) + + testthat::test_that( desc = "all_approved_eic() works", code = { @@ -21,8 +32,15 @@ testthat::test_that( object = names(tbl), expected = c("EicCode", "EicLongName") ) + } +) + + +testthat::test_that( + desc = "party_eic() validates inputs", + code = { testthat::expect_error( - object = all_approved_eic("foo"), + object = party_eic("foo"), regexp = 'unused argument \\("foo"\\)' ) } @@ -55,8 +73,15 @@ testthat::test_that( testthat::expect_true( object = all(tbl$type == "X") ) + } +) + + +testthat::test_that( + desc = "area_eic() validates inputs", + code = { testthat::expect_error( - object = party_eic("foo"), + object = area_eic("foo"), regexp = 'unused argument \\("foo"\\)' ) } @@ -89,8 +114,15 @@ testthat::test_that( testthat::expect_true( object = all(tbl$type == "Y") ) + } +) + + +testthat::test_that( + desc = "accounting_point_eic() validates inputs", + code = { testthat::expect_error( - object = area_eic("foo"), + object = accounting_point_eic("foo"), regexp = 'unused argument \\("foo"\\)' ) } @@ -123,8 +155,15 @@ testthat::test_that( testthat::expect_true( object = all(tbl$type == "Z") ) + } +) + + +testthat::test_that( + desc = "tie_line_eic() validates inputs", + code = { testthat::expect_error( - object = accounting_point_eic("foo"), + object = tie_line_eic("foo"), regexp = 'unused argument \\("foo"\\)' ) } @@ -157,8 +196,15 @@ testthat::test_that( testthat::expect_true( object = all(tbl$type == "T") ) + } +) + + +testthat::test_that( + desc = "location_eic() validates inputs", + code = { testthat::expect_error( - object = tie_line_eic("foo"), + object = location_eic("foo"), regexp = 'unused argument \\("foo"\\)' ) } @@ -191,8 +237,15 @@ testthat::test_that( testthat::expect_true( object = all(tbl$type == "V") ) + } +) + + +testthat::test_that( + desc = "resource_object_eic() validates inputs", + code = { testthat::expect_error( - object = location_eic("foo"), + object = resource_object_eic("foo"), regexp = 'unused argument \\("foo"\\)' ) } @@ -225,8 +278,15 @@ testthat::test_that( testthat::expect_true( object = all(tbl$type == "W") ) + } +) + + +testthat::test_that( + desc = "substation_eic() validates inputs", + code = { testthat::expect_error( - object = resource_object_eic("foo"), + object = substation_eic("foo"), regexp = 'unused argument \\("foo"\\)' ) } @@ -259,8 +319,15 @@ testthat::test_that( testthat::expect_true( object = all(tbl$type == "A") ) + } +) + + +testthat::test_that( + desc = "all_allocated_eic() validates inputs", + code = { testthat::expect_error( - object = substation_eic("foo"), + object = all_allocated_eic("foo"), regexp = 'unused argument \\("foo"\\)' ) } @@ -274,7 +341,7 @@ testthat::test_that( condition = there_is_provider(), message = "The Entso-e API cannot be reached" ) - mh$reset() + m$reset() testthat::expect_no_error( object = tbl <- all_allocated_eic() ) @@ -295,10 +362,6 @@ testthat::test_that( "display_name" ) ) - testthat::expect_error( - object = all_allocated_eic("foo"), - regexp = 'unused argument \\("foo"\\)' - ) } ) @@ -320,7 +383,7 @@ testthat::test_that( httr2::with_mocked_responses( mock = mock_list, code = { - mh$reset() + m$reset() testthat::expect_error( object = all_allocated_eic(), regexp = "Can't retrieve empty body" @@ -334,7 +397,7 @@ testthat::test_that( testthat::test_that( desc = "all_allocated_eic() errors on HTTP error response", code = { - mh$reset() + m$reset() xml_error_body <- paste0( '', "Service Unavailable" @@ -361,7 +424,7 @@ testthat::test_that( testthat::test_that( desc = "all_allocated_eic() parses XML content-type response", code = { - mh$reset() + m$reset() xml_fixture <- readLines( con = testthat::test_path("fixtures", "allocated_eic_min.xml"), encoding = "UTF-8" @@ -407,7 +470,7 @@ testthat::test_that( testthat::test_that( desc = "all_allocated_eic() parses ZIP/octet-stream content-type response", code = { - mh$reset() + m$reset() xml_fixture <- readLines( con = testthat::test_path("fixtures", "allocated_eic_min.xml"), encoding = "UTF-8" @@ -472,7 +535,7 @@ testthat::test_that( httr2::with_mocked_responses( mock = mock_list, code = { - mh$reset() + m$reset() testthat::expect_error( object = all_allocated_eic(), regexp = "The XML document has an unexpected tree structure" @@ -486,7 +549,7 @@ testthat::test_that( testthat::test_that( desc = "all_allocated_eic() uses cache on second call", code = { - mh$reset() + m$reset() xml_fixture <- readLines( con = testthat::test_path("fixtures", "get_allocated_eic_min.xml"), encoding = "UTF-8" diff --git a/tests/testthat/test-en_load.R b/tests/testthat/test-en_load.R index ef54058d..237909da 100644 --- a/tests/testthat/test-en_load.R +++ b/tests/testthat/test-en_load.R @@ -1,31 +1,6 @@ testthat::test_that( - desc = "load_actual_total() works and returns valid output structure", + desc = "load_actual_total() validates inputs", code = { - testthat::skip_if_not( - condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, - message = "No ENTSOE_PAT environment variable set" - ) - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) - result <- testthat::expect_no_error( - object = load_actual_total( - eic = "10Y1001A1001A83F", - period_start = lubridate::ymd( - x = Sys.Date() - lubridate::days(x = 30), - tz = "CET" - ), - period_end = lubridate::ymd( - x = Sys.Date(), - tz = "CET" - ), - tidy_output = TRUE - ) - ) - testthat::expect_s3_class(object = result, class = "tbl_df", exact = FALSE) - testthat::expect_gt(object = nrow(result), expected = 0L) - testthat::expect_gt(object = ncol(result), expected = 0L) testthat::expect_error( object = load_actual_total( eic = NULL, @@ -37,7 +12,8 @@ testthat::test_that( x = Sys.Date(), tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -51,7 +27,8 @@ testthat::test_that( x = Sys.Date(), tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -80,7 +57,8 @@ testthat::test_that( x = Sys.Date(), tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) } @@ -88,7 +66,7 @@ testthat::test_that( testthat::test_that( - desc = "load_day_ahead_total_forecast() works", + desc = "load_actual_total() works and returns valid output structure", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -99,7 +77,7 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) result <- testthat::expect_no_error( - object = load_day_ahead_total_forecast( + object = load_actual_total( eic = "10Y1001A1001A83F", period_start = lubridate::ymd( x = Sys.Date() - lubridate::days(x = 30), @@ -115,6 +93,13 @@ testthat::test_that( testthat::expect_s3_class(object = result, class = "tbl_df", exact = FALSE) testthat::expect_gt(object = nrow(result), expected = 0L) testthat::expect_gt(object = ncol(result), expected = 0L) + } +) + + +testthat::test_that( + desc = "load_day_ahead_total_forecast() validates inputs", + code = { testthat::expect_error( object = load_day_ahead_total_forecast( eic = NULL, @@ -126,7 +111,8 @@ testthat::test_that( x = Sys.Date(), tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -140,7 +126,8 @@ testthat::test_that( x = Sys.Date(), tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -169,7 +156,8 @@ testthat::test_that( x = Sys.Date(), tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) } @@ -177,7 +165,7 @@ testthat::test_that( testthat::test_that( - desc = "load_week_ahead_total_forecast() works", + desc = "load_day_ahead_total_forecast() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -188,14 +176,14 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) result <- testthat::expect_no_error( - object = load_week_ahead_total_forecast( + object = load_day_ahead_total_forecast( eic = "10Y1001A1001A83F", period_start = lubridate::ymd( - x = "2019-11-01", + x = Sys.Date() - lubridate::days(x = 30), tz = "CET" ), period_end = lubridate::ymd( - x = "2019-11-30", + x = Sys.Date(), tz = "CET" ), tidy_output = TRUE @@ -204,6 +192,13 @@ testthat::test_that( testthat::expect_s3_class(object = result, class = "tbl_df", exact = FALSE) testthat::expect_gt(object = nrow(result), expected = 0L) testthat::expect_gt(object = ncol(result), expected = 0L) + } +) + + +testthat::test_that( + desc = "load_week_ahead_total_forecast() validates inputs", + code = { testthat::expect_error( object = load_week_ahead_total_forecast( eic = NULL, @@ -215,7 +210,8 @@ testthat::test_that( x = "2019-11-30", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -229,7 +225,8 @@ testthat::test_that( x = "2019-11-30", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -258,7 +255,8 @@ testthat::test_that( x = "2019-11-30", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) } @@ -266,7 +264,7 @@ testthat::test_that( testthat::test_that( - desc = "load_month_ahead_total_forecast() works", + desc = "load_week_ahead_total_forecast() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -277,8 +275,8 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) result <- testthat::expect_no_error( - object = load_month_ahead_total_forecast( - eic = "10Y1001A1001A82H", + object = load_week_ahead_total_forecast( + eic = "10Y1001A1001A83F", period_start = lubridate::ymd( x = "2019-11-01", tz = "CET" @@ -293,6 +291,13 @@ testthat::test_that( testthat::expect_s3_class(object = result, class = "tbl_df", exact = FALSE) testthat::expect_gt(object = nrow(result), expected = 0L) testthat::expect_gt(object = ncol(result), expected = 0L) + } +) + + +testthat::test_that( + desc = "load_month_ahead_total_forecast() validates inputs", + code = { testthat::expect_error( object = load_month_ahead_total_forecast( eic = NULL, @@ -304,7 +309,8 @@ testthat::test_that( x = "2019-11-30", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -318,7 +324,8 @@ testthat::test_that( x = "2019-11-30", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -347,7 +354,8 @@ testthat::test_that( x = "2020-11-30", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) } @@ -355,7 +363,7 @@ testthat::test_that( testthat::test_that( - desc = "load_year_ahead_total_forecast() works", + desc = "load_month_ahead_total_forecast() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -366,14 +374,14 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) result <- testthat::expect_no_error( - object = load_year_ahead_total_forecast( - eic = "10Y1001A1001A83F", + object = load_month_ahead_total_forecast( + eic = "10Y1001A1001A82H", period_start = lubridate::ymd( - x = "2024-11-01", + x = "2019-11-01", tz = "CET" ), period_end = lubridate::ymd( - x = "2024-11-30", + x = "2019-11-30", tz = "CET" ), tidy_output = TRUE @@ -382,6 +390,13 @@ testthat::test_that( testthat::expect_s3_class(object = result, class = "tbl_df", exact = FALSE) testthat::expect_gt(object = nrow(result), expected = 0L) testthat::expect_gt(object = ncol(result), expected = 0L) + } +) + + +testthat::test_that( + desc = "load_year_ahead_total_forecast() validates inputs", + code = { testthat::expect_error( object = load_year_ahead_total_forecast( eic = NULL, @@ -393,7 +408,8 @@ testthat::test_that( x = "2019-11-30", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -407,7 +423,8 @@ testthat::test_that( x = "2019-11-30", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -436,7 +453,8 @@ testthat::test_that( x = "2020-11-30", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) } @@ -444,7 +462,7 @@ testthat::test_that( testthat::test_that( - desc = "load_year_ahead_forecast_margin() works", + desc = "load_year_ahead_total_forecast() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -455,14 +473,14 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) result <- testthat::expect_no_error( - object = load_year_ahead_forecast_margin( + object = load_year_ahead_total_forecast( eic = "10Y1001A1001A83F", period_start = lubridate::ymd( - x = "2019-01-01", + x = "2024-11-01", tz = "CET" ), period_end = lubridate::ymd( - x = "2019-12-31", + x = "2024-11-30", tz = "CET" ), tidy_output = TRUE @@ -471,6 +489,13 @@ testthat::test_that( testthat::expect_s3_class(object = result, class = "tbl_df", exact = FALSE) testthat::expect_gt(object = nrow(result), expected = 0L) testthat::expect_gt(object = ncol(result), expected = 0L) + } +) + + +testthat::test_that( + desc = "load_year_ahead_forecast_margin() validates inputs", + code = { testthat::expect_error( object = load_year_ahead_forecast_margin( eic = NULL, @@ -482,7 +507,8 @@ testthat::test_that( x = "2019-12-31", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -496,7 +522,8 @@ testthat::test_that( x = "2019-12-31", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -525,6 +552,219 @@ testthat::test_that( x = "2020-12-31", tz = "CET" ), + tidy_output = TRUE, + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "load_year_ahead_forecast_margin() works", + code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) + result <- testthat::expect_no_error( + object = load_year_ahead_forecast_margin( + eic = "10Y1001A1001A83F", + period_start = lubridate::ymd( + x = "2019-01-01", + tz = "CET" + ), + period_end = lubridate::ymd( + x = "2019-12-31", + tz = "CET" + ), + tidy_output = TRUE + ) + ) + testthat::expect_s3_class(object = result, class = "tbl_df", exact = FALSE) + testthat::expect_gt(object = nrow(result), expected = 0L) + testthat::expect_gt(object = ncol(result), expected = 0L) + } +) + + +testthat::test_that( + desc = "load_actual_total() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = load_actual_total( + eic = "10Y1001A1001A83F", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + tidy_output = TRUE + ) + ) + } +) + + +testthat::test_that( + desc = "load_day_ahead_total_forecast() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = load_day_ahead_total_forecast( + eic = "10Y1001A1001A83F", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + tidy_output = TRUE + ) + ) + } +) + + +testthat::test_that( + desc = "load_week_ahead_total_forecast() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = load_week_ahead_total_forecast( + eic = "10Y1001A1001A83F", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + tidy_output = TRUE + ) + ) + } +) + + +testthat::test_that( + desc = "load_month_ahead_total_forecast() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = load_month_ahead_total_forecast( + eic = "10Y1001A1001A83F", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + tidy_output = TRUE + ) + ) + } +) + + +testthat::test_that( + desc = "load_year_ahead_total_forecast() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = load_year_ahead_total_forecast( + eic = "10Y1001A1001A83F", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + tidy_output = TRUE + ) + ) + } +) + + +testthat::test_that( + desc = "load_year_ahead_forecast_margin() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = load_year_ahead_forecast_margin( + eic = "10Y1001A1001A83F", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE ) ) diff --git a/tests/testthat/test-en_market.R b/tests/testthat/test-en_market.R index ebe2d725..f56e655c 100644 --- a/tests/testthat/test-en_market.R +++ b/tests/testthat/test-en_market.R @@ -1,28 +1,6 @@ testthat::test_that( - desc = "day_ahead_prices() works", + desc = "day_ahead_prices() validates inputs", code = { - testthat::skip_if_not( - condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, - message = "No ENTSOE_PAT environment variable set" - ) - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) - testthat::expect_no_error( - object = day_ahead_prices( - eic = "10YCZ-CEPS-----N", - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-12-01", - tz = "CET" - ), - tidy_output = FALSE - ) - ) testthat::expect_error( object = day_ahead_prices( eic = NULL, @@ -34,7 +12,8 @@ testthat::test_that( x = "2019-12-01", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -48,7 +27,8 @@ testthat::test_that( x = "2019-12-01", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -77,7 +57,8 @@ testthat::test_that( x = "2020-12-01", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) } @@ -85,7 +66,7 @@ testthat::test_that( testthat::test_that( - desc = "total_nominated_capacity() works", + desc = "day_ahead_prices() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -96,20 +77,26 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = total_nominated_capacity( - eic_in = "10YDE-VE-------2", - eic_out = "10YCZ-CEPS-----N", + object = day_ahead_prices( + eic = "10YCZ-CEPS-----N", period_start = lubridate::ymd( - x = "2019-02-01", + x = "2019-11-01", tz = "CET" ), period_end = lubridate::ymd( - x = "2019-03-01", + x = "2019-12-01", tz = "CET" ), - tidy_output = TRUE + tidy_output = FALSE ) ) + } +) + + +testthat::test_that( + desc = "total_nominated_capacity() validates inputs", + code = { testthat::expect_error( object = total_nominated_capacity( eic_in = "10YDE-VE-------2", @@ -138,7 +125,8 @@ testthat::test_that( x = "2019-03-01", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -153,7 +141,8 @@ testthat::test_that( x = "2019-03-01", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -168,7 +157,8 @@ testthat::test_that( x = "2019-03-01", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -183,7 +173,8 @@ testthat::test_that( x = "2020-03-01", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) } @@ -191,7 +182,7 @@ testthat::test_that( testthat::test_that( - desc = "already_allocated_total_capacity() works", + desc = "total_nominated_capacity() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -202,22 +193,27 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = already_allocated_total_capacity( + object = total_nominated_capacity( eic_in = "10YDE-VE-------2", eic_out = "10YCZ-CEPS-----N", period_start = lubridate::ymd( - x = "2024-02-01", + x = "2019-02-01", tz = "CET" ), period_end = lubridate::ymd( - x = "2024-02-02", + x = "2019-03-01", tz = "CET" ), - auction_category = "A04", - contract_type = "A01", - tidy_output = FALSE + tidy_output = TRUE ) ) + } +) + + +testthat::test_that( + desc = "already_allocated_total_capacity() validates inputs", + code = { testthat::expect_error( object = already_allocated_total_capacity( eic_in = NULL, @@ -232,7 +228,8 @@ testthat::test_that( ), auction_category = "A04", contract_type = "A01", - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -249,7 +246,8 @@ testthat::test_that( ), auction_category = "A04", contract_type = "A01", - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -266,7 +264,8 @@ testthat::test_that( ), auction_category = "A04", contract_type = "A01", - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -301,7 +300,8 @@ testthat::test_that( ), auction_category = "A04", contract_type = "A01", - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) } @@ -309,7 +309,7 @@ testthat::test_that( testthat::test_that( - desc = "implicit_offered_transfer_capacity() works", + desc = "already_allocated_total_capacity() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -320,21 +320,29 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = implicit_offered_transfer_capacity( - eic_in = "10Y1001A1001A82H", - eic_out = "10YDK-1--------W", + object = already_allocated_total_capacity( + eic_in = "10YDE-VE-------2", + eic_out = "10YCZ-CEPS-----N", period_start = lubridate::ymd( - x = "2023-08-16", + x = "2024-02-01", tz = "CET" ), period_end = lubridate::ymd( - x = "2023-08-17", + x = "2024-02-02", tz = "CET" ), + auction_category = "A04", contract_type = "A01", tidy_output = FALSE ) ) + } +) + + +testthat::test_that( + desc = "implicit_offered_transfer_capacity() validates inputs", + code = { testthat::expect_error( object = implicit_offered_transfer_capacity( eic_in = NULL, @@ -347,7 +355,8 @@ testthat::test_that( x = "2023-08-17", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -362,7 +371,8 @@ testthat::test_that( x = "2023-08-17", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -377,7 +387,8 @@ testthat::test_that( x = "2023-08-17", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -393,7 +404,8 @@ testthat::test_that( tz = "CET" ), contract_type = "A99", - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -440,7 +452,8 @@ testthat::test_that( x = "2024-08-17", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) } @@ -448,7 +461,7 @@ testthat::test_that( testthat::test_that( - desc = "explicit_offered_transfer_capacity() works", + desc = "implicit_offered_transfer_capacity() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -459,21 +472,28 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = explicit_offered_transfer_capacity( - eic_in = "10YBE----------2", - eic_out = "10YGB----------A", + object = implicit_offered_transfer_capacity( + eic_in = "10Y1001A1001A82H", + eic_out = "10YDK-1--------W", period_start = lubridate::ymd( x = "2023-08-16", tz = "CET" ), period_end = lubridate::ymd( - x = "2023-08-18", + x = "2023-08-17", tz = "CET" ), contract_type = "A01", tidy_output = FALSE ) ) + } +) + + +testthat::test_that( + desc = "explicit_offered_transfer_capacity() validates inputs", + code = { testthat::expect_error( object = explicit_offered_transfer_capacity( eic_in = NULL, @@ -486,7 +506,8 @@ testthat::test_that( x = "2023-08-17", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -501,7 +522,8 @@ testthat::test_that( x = "2023-08-17", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -516,7 +538,8 @@ testthat::test_that( x = "2023-08-17", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -532,7 +555,8 @@ testthat::test_that( tz = "CET" ), contract_type = "A99", - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -579,7 +603,8 @@ testthat::test_that( x = "2024-08-17", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) } @@ -587,7 +612,7 @@ testthat::test_that( testthat::test_that( - desc = "continuous_offered_transfer_capacity() works", + desc = "explicit_offered_transfer_capacity() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -598,20 +623,28 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = continuous_offered_transfer_capacity( - eic_in = "10YNL----------L", - eic_out = "10YBE----------2", + object = explicit_offered_transfer_capacity( + eic_in = "10YBE----------2", + eic_out = "10YGB----------A", period_start = lubridate::ymd( - x = "2024-05-16", + x = "2023-08-16", tz = "CET" ), period_end = lubridate::ymd( - x = "2024-05-17", + x = "2023-08-18", tz = "CET" ), + contract_type = "A01", tidy_output = FALSE ) ) + } +) + + +testthat::test_that( + desc = "continuous_offered_transfer_capacity() validates inputs", + code = { testthat::expect_error( object = continuous_offered_transfer_capacity( eic_in = NULL, @@ -624,7 +657,8 @@ testthat::test_that( x = "2024-05-17", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -639,7 +673,8 @@ testthat::test_that( x = "2024-05-17", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -654,7 +689,8 @@ testthat::test_that( x = "2024-05-17", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -701,7 +737,8 @@ testthat::test_that( x = "2025-05-17", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) } @@ -709,7 +746,7 @@ testthat::test_that( testthat::test_that( - desc = "flow_based_allocations() works", + desc = "continuous_offered_transfer_capacity() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -720,22 +757,27 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = flow_based_allocations( - eic = "10YDOM-REGION-1V", + object = continuous_offered_transfer_capacity( + eic_in = "10YNL----------L", + eic_out = "10YBE----------2", period_start = lubridate::ymd( - x = "2018-12-31", + x = "2024-05-16", tz = "CET" ), period_end = lubridate::ymd( - x = "2019-01-01", + x = "2024-05-17", tz = "CET" ), - process_type = "A32", - archive = TRUE, tidy_output = FALSE ) - ) |> - testthat::expect_warning() + ) + } +) + + +testthat::test_that( + desc = "flow_based_allocations() validates inputs", + code = { testthat::expect_error( object = flow_based_allocations( eic = NULL, @@ -747,7 +789,8 @@ testthat::test_that( x = "2019-01-01", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -761,7 +804,8 @@ testthat::test_that( x = "2019-01-01", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -776,7 +820,8 @@ testthat::test_that( tz = "CET" ), process_type = "A99", - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -791,7 +836,8 @@ testthat::test_that( tz = "CET" ), archive = "yes", - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -829,7 +875,7 @@ testthat::test_that( testthat::test_that( - desc = "auction_revenue() works", + desc = "flow_based_allocations() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -840,21 +886,29 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = auction_revenue( - eic_in = "10YBA-JPCC-----D", - eic_out = "10YHR-HEP------M", + object = flow_based_allocations( + eic = "10YDOM-REGION-1V", period_start = lubridate::ymd( - x = "2023-08-25", + x = "2018-12-31", tz = "CET" ), period_end = lubridate::ymd( - x = "2023-08-26", + x = "2019-01-01", tz = "CET" ), - contract_type = "A01", + process_type = "A32", + archive = TRUE, tidy_output = FALSE ) - ) + ) |> + testthat::expect_warning() + } +) + + +testthat::test_that( + desc = "auction_revenue() validates inputs", + code = { testthat::expect_error( object = auction_revenue( eic_in = NULL, @@ -867,7 +921,8 @@ testthat::test_that( x = "2023-08-26", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -882,7 +937,8 @@ testthat::test_that( x = "2023-08-26", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -897,7 +953,8 @@ testthat::test_that( x = "2023-08-26", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -913,7 +970,8 @@ testthat::test_that( tz = "CET" ), contract_type = "A99", - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -960,7 +1018,8 @@ testthat::test_that( x = "2024-08-26", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) } @@ -968,7 +1027,7 @@ testthat::test_that( testthat::test_that( - desc = "net_positions() works", + desc = "auction_revenue() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -979,20 +1038,28 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = net_positions( - eic = "10YCZ-CEPS-----N", + object = auction_revenue( + eic_in = "10YBA-JPCC-----D", + eic_out = "10YHR-HEP------M", period_start = lubridate::ymd( - x = "2015-12-31", + x = "2023-08-25", tz = "CET" ), period_end = lubridate::ymd( - x = "2016-01-01", + x = "2023-08-26", tz = "CET" ), contract_type = "A01", tidy_output = FALSE ) ) + } +) + + +testthat::test_that( + desc = "net_positions() validates inputs", + code = { testthat::expect_error( object = net_positions( eic = NULL, @@ -1004,7 +1071,8 @@ testthat::test_that( x = "2016-01-01", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -1018,7 +1086,8 @@ testthat::test_that( x = "2016-01-01", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -1033,7 +1102,8 @@ testthat::test_that( tz = "CET" ), contract_type = "A99", - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -1077,7 +1147,8 @@ testthat::test_that( x = "2016-12-31", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) } @@ -1085,7 +1156,7 @@ testthat::test_that( testthat::test_that( - desc = "congestion_income() works", + desc = "net_positions() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -1096,20 +1167,27 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = congestion_income( - eic = "10YDOM-1001A083J", + object = net_positions( + eic = "10YCZ-CEPS-----N", period_start = lubridate::ymd( - x = "2016-01-01", + x = "2015-12-31", tz = "CET" ), period_end = lubridate::ymd( - x = "2016-01-02", + x = "2016-01-01", tz = "CET" ), contract_type = "A01", tidy_output = FALSE ) ) + } +) + + +testthat::test_that( + desc = "congestion_income() validates inputs", + code = { testthat::expect_error( object = congestion_income( eic = "10YDOM-1001A083J", @@ -1122,7 +1200,8 @@ testthat::test_that( tz = "CET" ), contract_type = "A01", - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ), regexp = "One year range limit should be applied" ) @@ -1137,7 +1216,8 @@ testthat::test_that( x = "2016-01-02", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -1151,7 +1231,8 @@ testthat::test_that( x = "2016-01-02", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -1166,7 +1247,8 @@ testthat::test_that( tz = "CET" ), contract_type = "A99", - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -1205,7 +1287,7 @@ testthat::test_that( testthat::test_that( - desc = "allocated_transfer_capacities_3rd_countries() works", + desc = "congestion_income() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -1215,69 +1297,28 @@ testthat::test_that( condition = there_is_provider(), message = "The Entso-e API cannot be reached" ) - df <- allocated_transfer_capacities_3rd_countries( - eic_in = "10YSK-SEPS-----K", - eic_out = "10YUA-WEPS-----0", - period_start = lubridate::ymd( - x = "2016-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2016-01-01", - tz = "CET" - ), - contract_type = "A01", - auction_category = "A04", - position = 2L, - tidy_output = FALSE - ) - cts <- c("A01", "A02", "A03", "A04", "A06", "A07", "A08") - ats <- c("A01", "A02", "A03", "A04") - for (ct in cts) { - for (at in ats) { - testthat::expect_no_error( - object = allocated_transfer_capacities_3rd_countries( - eic_in = "10YSK-SEPS-----K", - eic_out = "10YUA-WEPS-----0", - period_start = lubridate::ymd( - x = "2016-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2016-01-01", - tz = "CET" - ), - contract_type = ct, - auction_category = at, - position = 1L, - tidy_output = FALSE - ) - ) - } - } - testthat::expect_match( - object = df$reason_code, - regexp = "999" - ) - testthat::expect_error( - object = allocated_transfer_capacities_3rd_countries( - eic_in = "10YSK-SEPS-----K", - eic_out = "10YUA-WEPS-----0", + testthat::expect_no_error( + object = congestion_income( + eic = "10YDOM-1001A083J", period_start = lubridate::ymd( - x = "2015-01-01", + x = "2016-01-01", tz = "CET" ), period_end = lubridate::ymd( - x = "2015-05-01", + x = "2016-01-02", tz = "CET" ), contract_type = "A01", - auction_category = "A04", - position = 1L, tidy_output = FALSE - ), - regexp = "exceeds the allowed maximum \\(100\\) for data item" + ) ) + } +) + + +testthat::test_that( + desc = "allocated_transfer_capacities_3rd_countries() validates inputs", + code = { testthat::expect_error( object = allocated_transfer_capacities_3rd_countries( eic_in = NULL, @@ -1290,7 +1331,8 @@ testthat::test_that( x = "2016-01-02", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ), regexp = paste0( "Assertion on 'eic_in' failed: ", @@ -1309,7 +1351,8 @@ testthat::test_that( x = "2016-01-02", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ), regexp = paste( "Assertion on 'eic_out' failed:", @@ -1328,7 +1371,8 @@ testthat::test_that( x = "2016-01-02", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ), regexp = "Assertion on 'eic_in' failed: Must have length 1." ) @@ -1345,7 +1389,8 @@ testthat::test_that( tz = "CET" ), contract_type = "A99", - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ), regexp = paste( "Assertion on 'contract_type' failed:", @@ -1366,7 +1411,8 @@ testthat::test_that( tz = "CET" ), auction_category = "A99", - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ), regexp = paste( "Assertion on 'auction_category'", @@ -1387,7 +1433,8 @@ testthat::test_that( tz = "CET" ), position = 0L, - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ), regexp = "Assertion on 'position' failed: Must be >= 1" ) @@ -1431,3 +1478,422 @@ testthat::test_that( ) } ) + + +testthat::test_that( + desc = "allocated_transfer_capacities_3rd_countries() works", + code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) + df <- allocated_transfer_capacities_3rd_countries( + eic_in = "10YSK-SEPS-----K", + eic_out = "10YUA-WEPS-----0", + period_start = lubridate::ymd( + x = "2016-01-01", + tz = "CET" + ), + period_end = lubridate::ymd( + x = "2016-01-01", + tz = "CET" + ), + contract_type = "A01", + auction_category = "A04", + position = 2L, + tidy_output = FALSE + ) + cts <- c("A01", "A02", "A03", "A04", "A06", "A07", "A08") + ats <- c("A01", "A02", "A03", "A04") + for (ct in cts) { + for (at in ats) { + testthat::expect_no_error( + object = allocated_transfer_capacities_3rd_countries( + eic_in = "10YSK-SEPS-----K", + eic_out = "10YUA-WEPS-----0", + period_start = lubridate::ymd( + x = "2016-01-01", + tz = "CET" + ), + period_end = lubridate::ymd( + x = "2016-01-01", + tz = "CET" + ), + contract_type = ct, + auction_category = at, + position = 1L, + tidy_output = FALSE + ) + ) + } + } + testthat::expect_match( + object = df$reason_code, + regexp = "999" + ) + testthat::expect_error( + object = allocated_transfer_capacities_3rd_countries( + eic_in = "10YSK-SEPS-----K", + eic_out = "10YUA-WEPS-----0", + period_start = lubridate::ymd( + x = "2015-01-01", + tz = "CET" + ), + period_end = lubridate::ymd( + x = "2015-05-01", + tz = "CET" + ), + contract_type = "A01", + auction_category = "A04", + position = 1L, + tidy_output = FALSE + ), + regexp = "exceeds the allowed maximum \\(100\\) for data item" + ) + } +) + + +testthat::test_that( + desc = "implicit_offered_transfer_capacity() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = implicit_offered_transfer_capacity( + eic_in = "10YDE-VE-------2", + eic_out = "10YCZ-CEPS-----N", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "explicit_offered_transfer_capacity() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = explicit_offered_transfer_capacity( + eic_in = "10YDE-VE-------2", + eic_out = "10YCZ-CEPS-----N", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "continuous_offered_transfer_capacity() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = continuous_offered_transfer_capacity( + eic_in = "10YNL----------L", + eic_out = "10YBE----------2", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "flow_based_allocations() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = flow_based_allocations( + eic = "10Y1001A1001A91G", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + process_type = "A43", + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "auction_revenue() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = auction_revenue( + eic_in = "10YBA-JPCC-----D", + eic_out = "10YHR-HEP------M", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "total_nominated_capacity() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = total_nominated_capacity( + eic_in = "10YDE-VE-------2", + eic_out = "10YCZ-CEPS-----N", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "already_allocated_total_capacity() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = already_allocated_total_capacity( + eic_in = "10YDE-VE-------2", + eic_out = "10YCZ-CEPS-----N", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "day_ahead_prices() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = day_ahead_prices( + eic = "10YCZ-CEPS-----N", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "net_positions() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = net_positions( + eic = "10YCZ-CEPS-----N", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "congestion_income() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = congestion_income( + eic = "10YDOM-1001A083J", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = paste( + "allocated_transfer_capacities_3rd_countries()", + "covers happy path with mock" + ), + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = allocated_transfer_capacities_3rd_countries( + eic_in = "10YSK-SEPS-----K", + eic_out = "10YUA-WEPS-----0", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) diff --git a/tests/testthat/test-en_outages.R b/tests/testthat/test-en_outages.R index a456fb15..b4d70262 100644 --- a/tests/testthat/test-en_outages.R +++ b/tests/testthat/test-en_outages.R @@ -1,42 +1,6 @@ testthat::test_that( - desc = "outages_both() works", + desc = "outages_both() validates inputs", code = { - testthat::skip_if_not( - condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, - message = "No ENTSOE_PAT environment variable set" - ) - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) - testthat::expect_no_error( - object = outages_both( - eic = "10YFR-RTE------C", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-24", - tz = "CET" - ), - tidy_output = FALSE - ) - ) - testthat::expect_no_error( - object = outages_both( - eic = "ABCDEFGHIJKLMNOP", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-24", - tz = "CET" - ), - tidy_output = TRUE - ) - ) testthat::expect_error( object = outages_both( eic = "10YFR-RTE------C", @@ -48,7 +12,8 @@ testthat::test_that( x = "2025-11-24", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) |> testthat::expect_error() @@ -57,7 +22,7 @@ testthat::test_that( testthat::test_that( - desc = "outages_gen_units() works", + desc = "outages_both() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -68,42 +33,45 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = outages_gen_units( + object = outages_both( eic = "10YFR-RTE------C", - doc_status = "A05", - event_nature = "A54", period_start = lubridate::ymd( x = "2024-10-23", tz = "CET" ), period_end = lubridate::ymd( - x = "2024-10-30", + x = "2024-10-24", tz = "CET" ), - tidy_output = TRUE + tidy_output = FALSE ) ) - testthat::expect_error( - object = outages_gen_units( - eic = "10YFR-RTE------C", - doc_status = "ABC", - event_nature = "A54", + testthat::expect_no_error( + object = outages_both( + eic = "ABCDEFGHIJKLMNOP", period_start = lubridate::ymd( x = "2024-10-23", tz = "CET" ), period_end = lubridate::ymd( - x = "2024-10-30", + x = "2024-10-24", tz = "CET" ), tidy_output = TRUE ) ) + } +) + + +testthat::test_that( + desc = "outages_gen_units() validates inputs", + code = { testthat::expect_error( object = outages_gen_units( eic = "10YFR-RTE------C", - doc_status = "A05", - event_nature = "A33", + doc_status = "ABC", + event_nature = "A54", period_start = lubridate::ymd( x = "2024-10-23", tz = "CET" @@ -112,14 +80,15 @@ testthat::test_that( x = "2024-10-30", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) - testthat::expect_no_error( + testthat::expect_error( object = outages_gen_units( eic = "10YFR-RTE------C", doc_status = "A05", - event_nature = "A54", + event_nature = "A33", period_start = lubridate::ymd( x = "2024-10-23", tz = "CET" @@ -128,7 +97,8 @@ testthat::test_that( x = "2024-10-30", tz = "CET" ), - tidy_output = FALSE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -159,7 +129,8 @@ testthat::test_that( x = "2025-11-26", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -188,7 +159,8 @@ testthat::test_that( x = "2024-10-24", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -201,7 +173,8 @@ testthat::test_that( x = "2024-10-24", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) } @@ -209,7 +182,7 @@ testthat::test_that( testthat::test_that( - desc = "outages_prod_units() works", + desc = "outages_gen_units() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -220,10 +193,10 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = outages_prod_units( + object = outages_gen_units( eic = "10YFR-RTE------C", - doc_status = "A09", - event_nature = "A53", + doc_status = "A05", + event_nature = "A54", period_start = lubridate::ymd( x = "2024-10-23", tz = "CET" @@ -235,11 +208,11 @@ testthat::test_that( tidy_output = TRUE ) ) - testthat::expect_error( - object = outages_prod_units( + testthat::expect_no_error( + object = outages_gen_units( eic = "10YFR-RTE------C", - doc_status = "ABC", - event_nature = "A53", + doc_status = "A05", + event_nature = "A54", period_start = lubridate::ymd( x = "2024-10-23", tz = "CET" @@ -248,14 +221,21 @@ testthat::test_that( x = "2024-10-30", tz = "CET" ), - tidy_output = TRUE + tidy_output = FALSE ) ) + } +) + + +testthat::test_that( + desc = "outages_prod_units() validates inputs", + code = { testthat::expect_error( object = outages_prod_units( eic = "10YFR-RTE------C", - doc_status = "A09", - event_nature = "ABC", + doc_status = "ABC", + event_nature = "A53", period_start = lubridate::ymd( x = "2024-10-23", tz = "CET" @@ -264,14 +244,15 @@ testthat::test_that( x = "2024-10-30", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) - testthat::expect_no_error( + testthat::expect_error( object = outages_prod_units( eic = "10YFR-RTE------C", doc_status = "A09", - event_nature = "A53", + event_nature = "ABC", period_start = lubridate::ymd( x = "2024-10-23", tz = "CET" @@ -280,7 +261,8 @@ testthat::test_that( x = "2024-10-30", tz = "CET" ), - tidy_output = FALSE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -311,7 +293,8 @@ testthat::test_that( x = "2025-11-26", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -340,7 +323,8 @@ testthat::test_that( x = "2024-10-24", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -353,7 +337,8 @@ testthat::test_that( x = "2024-10-24", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) } @@ -361,7 +346,7 @@ testthat::test_that( testthat::test_that( - desc = "outages_offshore_grid() works", + desc = "outages_prod_units() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -372,9 +357,10 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = outages_offshore_grid( - eic = "10Y1001A1001A82H", - doc_status = "A05", + object = outages_prod_units( + eic = "10YFR-RTE------C", + doc_status = "A09", + event_nature = "A53", period_start = lubridate::ymd( x = "2024-10-23", tz = "CET" @@ -386,10 +372,11 @@ testthat::test_that( tidy_output = TRUE ) ) - testthat::expect_error( - object = outages_offshore_grid( - eic = "10Y1001A1001A82H", - doc_status = "ABC", + testthat::expect_no_error( + object = outages_prod_units( + eic = "10YFR-RTE------C", + doc_status = "A09", + event_nature = "A53", period_start = lubridate::ymd( x = "2024-10-23", tz = "CET" @@ -398,22 +385,30 @@ testthat::test_that( x = "2024-10-30", tz = "CET" ), - tidy_output = TRUE + tidy_output = FALSE ) ) - testthat::expect_no_error( + } +) + + +testthat::test_that( + desc = "outages_offshore_grid() validates inputs", + code = { + testthat::expect_error( object = outages_offshore_grid( eic = "10Y1001A1001A82H", - doc_status = "A05", + doc_status = "ABC", period_start = lubridate::ymd( - x = "2025-01-23", + x = "2024-10-23", tz = "CET" ), period_end = lubridate::ymd( - x = "2025-01-30", + x = "2024-10-30", tz = "CET" ), - tidy_output = FALSE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -443,7 +438,8 @@ testthat::test_that( x = "2025-11-26", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -472,7 +468,8 @@ testthat::test_that( x = "2024-10-24", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -485,7 +482,8 @@ testthat::test_that( x = "2024-10-24", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) } @@ -493,7 +491,7 @@ testthat::test_that( testthat::test_that( - desc = "outages_cons_units() works", + desc = "outages_offshore_grid() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -504,10 +502,9 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = outages_cons_units( - eic = "10YFI-1--------U", - doc_status = "A09", - event_nature = "A53", + object = outages_offshore_grid( + eic = "10Y1001A1001A82H", + doc_status = "A05", period_start = lubridate::ymd( x = "2024-10-23", tz = "CET" @@ -516,46 +513,36 @@ testthat::test_that( x = "2024-10-30", tz = "CET" ), - period_start_update = lubridate::ymd( - x = "2024-10-15", - tz = "CET" - ), - period_end_update = lubridate::ymd( - x = "2024-10-22", - tz = "CET" - ), tidy_output = TRUE ) ) - testthat::expect_error( - object = outages_cons_units( - eic = "10YFI-1--------U", - doc_status = "ABC", - event_nature = "A53", + testthat::expect_no_error( + object = outages_offshore_grid( + eic = "10Y1001A1001A82H", + doc_status = "A05", period_start = lubridate::ymd( - x = "2024-10-23", + x = "2025-01-23", tz = "CET" ), period_end = lubridate::ymd( - x = "2024-10-30", - tz = "CET" - ), - period_start_update = lubridate::ymd( - x = "2024-10-15", - tz = "CET" - ), - period_end_update = lubridate::ymd( - x = "2024-10-22", + x = "2025-01-30", tz = "CET" ), - tidy_output = TRUE + tidy_output = FALSE ) ) + } +) + + +testthat::test_that( + desc = "outages_cons_units() validates inputs", + code = { testthat::expect_error( object = outages_cons_units( eic = "10YFI-1--------U", - doc_status = "A09", - event_nature = "ABC", + doc_status = "ABC", + event_nature = "A53", period_start = lubridate::ymd( x = "2024-10-23", tz = "CET" @@ -572,14 +559,15 @@ testthat::test_that( x = "2024-10-22", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) - testthat::expect_no_error( + testthat::expect_error( object = outages_cons_units( eic = "10YFI-1--------U", doc_status = "A09", - event_nature = "A53", + event_nature = "ABC", period_start = lubridate::ymd( x = "2024-10-23", tz = "CET" @@ -596,7 +584,8 @@ testthat::test_that( x = "2024-10-22", tz = "CET" ), - tidy_output = FALSE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -643,7 +632,8 @@ testthat::test_that( x = "2024-10-22", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -688,7 +678,8 @@ testthat::test_that( x = "2024-10-22", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -709,7 +700,8 @@ testthat::test_that( x = "2024-10-22", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) } @@ -717,7 +709,7 @@ testthat::test_that( testthat::test_that( - desc = "outages_transmission_grid() works", + desc = "outages_cons_units() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -728,9 +720,32 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = outages_transmission_grid( - eic_in = "10YFR-RTE------C", - eic_out = "10Y1001A1001A82H", + object = outages_cons_units( + eic = "10YFI-1--------U", + doc_status = "A09", + event_nature = "A53", + period_start = lubridate::ymd( + x = "2024-10-23", + tz = "CET" + ), + period_end = lubridate::ymd( + x = "2024-10-30", + tz = "CET" + ), + period_start_update = lubridate::ymd( + x = "2024-10-15", + tz = "CET" + ), + period_end_update = lubridate::ymd( + x = "2024-10-22", + tz = "CET" + ), + tidy_output = TRUE + ) + ) + testthat::expect_no_error( + object = outages_cons_units( + eic = "10YFI-1--------U", doc_status = "A09", event_nature = "A53", period_start = lubridate::ymd( @@ -752,6 +767,13 @@ testthat::test_that( tidy_output = FALSE ) ) + } +) + + +testthat::test_that( + desc = "outages_transmission_grid() validates inputs", + code = { testthat::expect_error( object = outages_transmission_grid( eic_in = "10YFR-RTE------C", @@ -774,7 +796,8 @@ testthat::test_that( x = "2024-10-22", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -799,7 +822,8 @@ testthat::test_that( x = "2024-10-22", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -824,7 +848,8 @@ testthat::test_that( x = "2024-10-22", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -849,7 +874,8 @@ testthat::test_that( x = "2024-10-22", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -898,7 +924,8 @@ testthat::test_that( x = "2024-10-22", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -945,7 +972,8 @@ testthat::test_that( x = "2024-10-22", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -968,7 +996,8 @@ testthat::test_that( x = "2024-10-22", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -989,7 +1018,8 @@ testthat::test_that( x = "2024-10-22", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) } @@ -997,7 +1027,7 @@ testthat::test_that( testthat::test_that( - desc = "outages_fallbacks() works", + desc = "outages_transmission_grid() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -1008,10 +1038,11 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = outages_fallbacks( - eic = "10YBE----------2", - process_type = "A63", - event_nature = "C47", + object = outages_transmission_grid( + eic_in = "10YFR-RTE------C", + eic_out = "10Y1001A1001A82H", + doc_status = "A09", + event_nature = "A53", period_start = lubridate::ymd( x = "2024-10-23", tz = "CET" @@ -1020,9 +1051,24 @@ testthat::test_that( x = "2024-10-30", tz = "CET" ), + period_start_update = lubridate::ymd( + x = "2024-10-15", + tz = "CET" + ), + period_end_update = lubridate::ymd( + x = "2024-10-22", + tz = "CET" + ), tidy_output = FALSE ) ) + } +) + + +testthat::test_that( + desc = "outages_fallbacks() validates inputs", + code = { testthat::expect_error( object = outages_fallbacks( eic = "10YBE----------2", @@ -1053,7 +1099,8 @@ testthat::test_that( x = "2024-10-30", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -1069,7 +1116,8 @@ testthat::test_that( x = "2024-10-30", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -1083,7 +1131,8 @@ testthat::test_that( x = "2025-11-26", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -1112,7 +1161,8 @@ testthat::test_that( x = "2024-10-24", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -1125,8 +1175,251 @@ testthat::test_that( x = "2024-10-24", tz = "CET" ), + tidy_output = FALSE, + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "outages_fallbacks() works", + code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) + testthat::expect_no_error( + object = outages_fallbacks( + eic = "10YBE----------2", + process_type = "A63", + event_nature = "C47", + period_start = lubridate::ymd( + x = "2024-10-23", + tz = "CET" + ), + period_end = lubridate::ymd( + x = "2024-10-30", + tz = "CET" + ), tidy_output = FALSE ) ) } ) + + +testthat::test_that( + desc = "outages_gen_units() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = outages_gen_units( + eic = "10YFR-RTE------C", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "outages_prod_units() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = outages_prod_units( + eic = "10YFR-RTE------C", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "outages_both() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_no_error( + object = outages_both( + eic = "10YFR-RTE------C", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "outages_offshore_grid() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = outages_offshore_grid( + eic = "10Y1001A1001A82H", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "outages_cons_units() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = outages_cons_units( + eic = "10YFI-1--------U", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "outages_transmission_grid() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = outages_transmission_grid( + eic_in = "10YFR-RTE------C", + eic_out = "10Y1001A1001A82H", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "outages_fallbacks() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = outages_fallbacks( + eic = "10YBE----------2", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) diff --git a/tests/testthat/test-en_transmission.R b/tests/testthat/test-en_transmission.R index 34ab05f5..17303ffa 100644 --- a/tests/testthat/test-en_transmission.R +++ b/tests/testthat/test-en_transmission.R @@ -1,29 +1,6 @@ testthat::test_that( - desc = "cross_border_physical_flows() works", + desc = "cross_border_physical_flows() validates inputs", code = { - testthat::skip_if_not( - condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, - message = "No ENTSOE_PAT environment variable set" - ) - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) - testthat::expect_no_error( - object = cross_border_physical_flows( - eic_in = "10Y1001A1001A83F", - eic_out = "10YCZ-CEPS-----N", - period_start = lubridate::ymd( - x = "2020-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-01-02", - tz = "CET" - ), - tidy_output = FALSE - ) - ) testthat::expect_error( object = cross_border_physical_flows( eic_in = c("10Y1001A1001A83F", "10YCZ-CEPS-----N"), @@ -36,7 +13,8 @@ testthat::test_that( x = "2020-01-02", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -50,7 +28,8 @@ testthat::test_that( x = "2020-01-02", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -64,7 +43,8 @@ testthat::test_that( x = "2020-01-02", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -111,7 +91,8 @@ testthat::test_that( x = "2021-01-02", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) } @@ -119,7 +100,7 @@ testthat::test_that( testthat::test_that( - desc = "day_ahead_commercial_sched() works", + desc = "cross_border_physical_flows() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -130,20 +111,27 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = day_ahead_commercial_sched( - eic_in = "10YCZ-CEPS-----N", - eic_out = "10YSK-SEPS-----K", + object = cross_border_physical_flows( + eic_in = "10Y1001A1001A83F", + eic_out = "10YCZ-CEPS-----N", period_start = lubridate::ymd( - x = "2019-11-01", + x = "2020-01-01", tz = "CET" ), period_end = lubridate::ymd( - x = "2019-12-01", + x = "2020-01-02", tz = "CET" ), tidy_output = FALSE ) ) + } +) + + +testthat::test_that( + desc = "day_ahead_commercial_sched() validates inputs", + code = { testthat::expect_error( object = day_ahead_commercial_sched( eic_out = "10YSK-SEPS-----K", @@ -155,7 +143,8 @@ testthat::test_that( x = "2019-12-01", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -169,7 +158,8 @@ testthat::test_that( x = "2019-12-01", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -184,7 +174,8 @@ testthat::test_that( x = "2019-12-01", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -231,7 +222,8 @@ testthat::test_that( x = "2020-12-01", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) } @@ -239,7 +231,7 @@ testthat::test_that( testthat::test_that( - desc = "total_commercial_sched() works", + desc = "day_ahead_commercial_sched() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -250,7 +242,7 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = total_commercial_sched( + object = day_ahead_commercial_sched( eic_in = "10YCZ-CEPS-----N", eic_out = "10YSK-SEPS-----K", period_start = lubridate::ymd( @@ -264,6 +256,13 @@ testthat::test_that( tidy_output = FALSE ) ) + } +) + + +testthat::test_that( + desc = "total_commercial_sched() validates inputs", + code = { testthat::expect_error( object = total_commercial_sched( eic_in = "10YCZ-CEPS-----N", @@ -275,7 +274,8 @@ testthat::test_that( x = "2019-12-01", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -289,7 +289,8 @@ testthat::test_that( x = "2019-12-01", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -304,7 +305,8 @@ testthat::test_that( x = "2019-12-01", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -351,7 +353,8 @@ testthat::test_that( x = "2020-12-01", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) } @@ -359,7 +362,7 @@ testthat::test_that( testthat::test_that( - desc = "forecasted_transfer_capacities works", + desc = "total_commercial_sched() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -370,7 +373,7 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = forecasted_transfer_capacities( + object = total_commercial_sched( eic_in = "10YCZ-CEPS-----N", eic_out = "10YSK-SEPS-----K", period_start = lubridate::ymd( @@ -384,6 +387,13 @@ testthat::test_that( tidy_output = FALSE ) ) + } +) + + +testthat::test_that( + desc = "forecasted_transfer_capacities validates inputs", + code = { testthat::expect_error( object = forecasted_transfer_capacities( eic_in = "10YCZ-CEPS-----N", @@ -395,7 +405,8 @@ testthat::test_that( x = "2019-12-01", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -409,7 +420,8 @@ testthat::test_that( x = "2019-12-01", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -424,7 +436,8 @@ testthat::test_that( x = "2019-12-01", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -471,7 +484,8 @@ testthat::test_that( x = "2020-12-01", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) } @@ -479,7 +493,7 @@ testthat::test_that( testthat::test_that( - desc = "redispatching_cross_border() works", + desc = "forecasted_transfer_capacities works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -490,35 +504,27 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = redispatching_cross_border( - eic_in = "10YDE-VE-------2", - eic_out = "10YDE-EON------1", - period_start = lubridate::ymd( - x = "2024-03-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-03-11", - tz = "CET" - ), - tidy_output = TRUE - ) - ) - testthat::expect_no_error( - object = redispatching_cross_border( - eic_in = "10YNL----------L", - eic_out = "10YNO-0--------C", + object = forecasted_transfer_capacities( + eic_in = "10YCZ-CEPS-----N", + eic_out = "10YSK-SEPS-----K", period_start = lubridate::ymd( - x = "2020-02-01", + x = "2019-11-01", tz = "CET" ), period_end = lubridate::ymd( - x = "2020-03-01", + x = "2019-12-01", tz = "CET" ), - tidy_output = TRUE + tidy_output = FALSE ) ) + } +) + + +testthat::test_that( + desc = "redispatching_cross_border() validates inputs", + code = { testthat::expect_error( object = redispatching_cross_border( eic_in = "10YDE-VE-------2", @@ -531,7 +537,8 @@ testthat::test_that( x = "2025-01-01", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -546,7 +553,8 @@ testthat::test_that( x = "2020-03-01", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -561,7 +569,8 @@ testthat::test_that( x = "2020-03-01", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -576,7 +585,8 @@ testthat::test_that( x = "2020-03-01", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -591,7 +601,8 @@ testthat::test_that( x = "2020-03-01", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -615,7 +626,7 @@ testthat::test_that( testthat::test_that( - desc = "redispatching_internal() works", + desc = "redispatching_cross_border() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -626,8 +637,9 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = redispatching_internal( - eic = "10YNO-0--------C", + object = redispatching_cross_border( + eic_in = "10YDE-VE-------2", + eic_out = "10YDE-EON------1", period_start = lubridate::ymd( x = "2024-03-01", tz = "CET" @@ -639,6 +651,28 @@ testthat::test_that( tidy_output = TRUE ) ) + testthat::expect_no_error( + object = redispatching_cross_border( + eic_in = "10YNL----------L", + eic_out = "10YNO-0--------C", + period_start = lubridate::ymd( + x = "2020-02-01", + tz = "CET" + ), + period_end = lubridate::ymd( + x = "2020-03-01", + tz = "CET" + ), + tidy_output = TRUE + ) + ) + } +) + + +testthat::test_that( + desc = "redispatching_internal() validates inputs", + code = { testthat::expect_error( object = redispatching_internal( eic = "10YNO-0--------C", @@ -650,7 +684,8 @@ testthat::test_that( x = "2024-04-01", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -664,7 +699,8 @@ testthat::test_that( x = "2020-03-01", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -678,7 +714,8 @@ testthat::test_that( x = "2020-03-01", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -701,7 +738,7 @@ testthat::test_that( testthat::test_that( - desc = "countertrading() works", + desc = "redispatching_internal() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -712,20 +749,26 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = countertrading( - eic_in = "10YFR-RTE------C", - eic_out = "10YES-REE------0", + object = redispatching_internal( + eic = "10YNO-0--------C", period_start = lubridate::ymd( - x = "2020-02-01", + x = "2024-03-01", tz = "CET" ), period_end = lubridate::ymd( - x = "2020-02-15", + x = "2024-03-11", tz = "CET" ), tidy_output = TRUE ) ) + } +) + + +testthat::test_that( + desc = "countertrading() validates inputs", + code = { testthat::expect_error( object = countertrading( eic_in = "10YFR-RTE------C", @@ -738,7 +781,8 @@ testthat::test_that( x = "2024-08-01", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -753,7 +797,8 @@ testthat::test_that( x = "2020-03-01", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -768,7 +813,8 @@ testthat::test_that( x = "2020-03-01", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -783,7 +829,8 @@ testthat::test_that( x = "2020-03-01", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -798,7 +845,8 @@ testthat::test_that( x = "2020-03-01", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -822,7 +870,7 @@ testthat::test_that( testthat::test_that( - desc = "costs_of_congestion_management() works", + desc = "countertrading() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -833,57 +881,35 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = costs_of_congestion_management( - eic = "10YBE----------2", - period_start = lubridate::ymd(x = "2016-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2016-12-31", tz = "CET"), - tidy_output = TRUE - ) - ) - testthat::expect_no_error( - object = costs_of_congestion_management( - eic = "10YBE----------2", - period_start = lubridate::ymd(x = "2016-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2016-12-31", tz = "CET"), - event_nature = "A46", - tidy_output = TRUE - ) - ) - testthat::expect_error( - object = costs_of_congestion_management( - eic = "10YCZ-CEPS-----N", - period_start = lubridate::ymd(x = "2016-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2017-01-01", tz = "CET"), - event_nature = "B99", - tidy_output = TRUE - ) - ) - testthat::expect_no_error( - object = costs_of_congestion_management( - eic = "10YNO-0--------C", + object = countertrading( + eic_in = "10YFR-RTE------C", + eic_out = "10YES-REE------0", period_start = lubridate::ymd( - x = "2024-03-01", + x = "2020-02-01", tz = "CET" ), period_end = lubridate::ymd( - x = "2024-04-01", + x = "2020-02-15", tz = "CET" ), tidy_output = TRUE ) ) - testthat::expect_no_error( + } +) + + +testthat::test_that( + desc = "costs_of_congestion_management() validates inputs", + code = { + testthat::expect_error( object = costs_of_congestion_management( - eic = "10YNO-0--------C", - period_start = lubridate::ymd( - x = "2024-03-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-04-01", - tz = "CET" - ), - tidy_output = TRUE + eic = "10YCZ-CEPS-----N", + period_start = lubridate::ymd(x = "2016-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2017-01-01", tz = "CET"), + event_nature = "B99", + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -897,7 +923,8 @@ testthat::test_that( x = "2020-03-01", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -911,7 +938,8 @@ testthat::test_that( x = "2020-03-01", tz = "CET" ), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -934,7 +962,8 @@ testthat::test_that( eic = "10YBE----------2", period_start = lubridate::ymd(x = "2016-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2020-01-01", tz = "CET"), - tidy_output = TRUE + tidy_output = TRUE, + security_token = "dummy_token" ) ) } @@ -942,7 +971,7 @@ testthat::test_that( testthat::test_that( - desc = "expansion_and_dismantling_project() works", + desc = "costs_of_congestion_management() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -953,22 +982,57 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = expansion_and_dismantling_project( - eic_in = "10YSK-SEPS-----K", - eic_out = "10YHU-MAVIR----U", + object = costs_of_congestion_management( + eic = "10YBE----------2", + period_start = lubridate::ymd(x = "2016-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2016-12-31", tz = "CET"), + tidy_output = TRUE + ) + ) + testthat::expect_no_error( + object = costs_of_congestion_management( + eic = "10YBE----------2", + period_start = lubridate::ymd(x = "2016-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2016-12-31", tz = "CET"), + event_nature = "A46", + tidy_output = TRUE + ) + ) + testthat::expect_no_error( + object = costs_of_congestion_management( + eic = "10YNO-0--------C", period_start = lubridate::ymd( - x = "2023-01-01", + x = "2024-03-01", tz = "CET" ), period_end = lubridate::ymd( - x = "2023-01-02", + x = "2024-04-01", tz = "CET" ), - business_type = "B01", - doc_status = "A05", - tidy_output = FALSE + tidy_output = TRUE + ) + ) + testthat::expect_no_error( + object = costs_of_congestion_management( + eic = "10YNO-0--------C", + period_start = lubridate::ymd( + x = "2024-03-01", + tz = "CET" + ), + period_end = lubridate::ymd( + x = "2024-04-01", + tz = "CET" + ), + tidy_output = TRUE ) ) + } +) + + +testthat::test_that( + desc = "expansion_and_dismantling_project() validates inputs", + code = { testthat::expect_error( object = expansion_and_dismantling_project( eic_in = NULL, @@ -983,7 +1047,8 @@ testthat::test_that( ), business_type = "B01", doc_status = "A05", - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -1000,7 +1065,8 @@ testthat::test_that( ), business_type = "B01", doc_status = "A05", - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -1017,7 +1083,8 @@ testthat::test_that( ), business_type = "B01", doc_status = "A05", - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -1052,7 +1119,8 @@ testthat::test_that( ), business_type = "B99", doc_status = "A05", - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -1069,7 +1137,8 @@ testthat::test_that( ), business_type = "B01", doc_status = "X99", - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) } @@ -1077,7 +1146,7 @@ testthat::test_that( testthat::test_that( - desc = "intraday_cross_border_transfer_limits() works", + desc = "expansion_and_dismantling_project() works", code = { testthat::skip_if_not( condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, @@ -1088,20 +1157,29 @@ testthat::test_that( message = "The Entso-e API cannot be reached" ) testthat::expect_no_error( - object = intraday_cross_border_transfer_limits( - eic_in = "10YFR-RTE------C", - eic_out = "11Y0-0000-0265-K", + object = expansion_and_dismantling_project( + eic_in = "10YSK-SEPS-----K", + eic_out = "10YHU-MAVIR----U", period_start = lubridate::ymd( - x = "2023-08-16", + x = "2023-01-01", tz = "CET" ), period_end = lubridate::ymd( - x = "2023-08-17", + x = "2023-01-02", tz = "CET" ), + business_type = "B01", + doc_status = "A05", tidy_output = FALSE ) ) + } +) + + +testthat::test_that( + desc = "intraday_cross_border_transfer_limits() validates inputs", + code = { testthat::expect_error( object = intraday_cross_border_transfer_limits( eic_in = NULL, @@ -1114,7 +1192,8 @@ testthat::test_that( x = "2023-08-17", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -1129,7 +1208,8 @@ testthat::test_that( x = "2023-08-17", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -1144,7 +1224,8 @@ testthat::test_that( x = "2023-08-17", tz = "CET" ), - tidy_output = FALSE + tidy_output = FALSE, + security_token = "dummy_token" ) ) testthat::expect_error( @@ -1191,8 +1272,337 @@ testthat::test_that( x = "2024-08-17", tz = "CET" ), + tidy_output = FALSE, + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "intraday_cross_border_transfer_limits() works", + code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) + testthat::expect_no_error( + object = intraday_cross_border_transfer_limits( + eic_in = "10YFR-RTE------C", + eic_out = "11Y0-0000-0265-K", + period_start = lubridate::ymd( + x = "2023-08-16", + tz = "CET" + ), + period_end = lubridate::ymd( + x = "2023-08-17", + tz = "CET" + ), tidy_output = FALSE ) ) } ) + + +testthat::test_that( + desc = "expansion_and_dismantling_project() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = expansion_and_dismantling_project( + eic_in = "10YFR-RTE------C", + eic_out = "10YDE-VE-------2", + period = lubridate::ymd("2020-01-01", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "intraday_cross_border_transfer_limits() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = intraday_cross_border_transfer_limits( + eic_in = "10YFR-RTE------C", + eic_out = "10YDE-VE-------2", + period = lubridate::ymd("2020-01-01", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "forecasted_transfer_capacities() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = forecasted_transfer_capacities( + eic_in = "10YFR-RTE------C", + eic_out = "10YDE-VE-------2", + period = lubridate::ymd("2020-01-01", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "day_ahead_commercial_sched() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = day_ahead_commercial_sched( + eic_in = "10YFR-RTE------C", + eic_out = "10YDE-VE-------2", + period = lubridate::ymd("2020-01-01", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "total_commercial_sched() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = total_commercial_sched( + eic_in = "10YFR-RTE------C", + eic_out = "10YDE-VE-------2", + period = lubridate::ymd("2020-01-01", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "cross_border_physical_flows() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = cross_border_physical_flows( + eic_in = "10YFR-RTE------C", + eic_out = "10YDE-VE-------2", + period = lubridate::ymd("2020-01-01", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "redispatching_cross_border() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = redispatching_cross_border( + eic_in = "10YFR-RTE------C", + eic_out = "10YDE-VE-------2", + period = lubridate::ymd("2020-01-01", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "redispatching_internal() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = redispatching_internal( + eic = "10YFR-RTE------C", + period = lubridate::ymd("2020-01-01", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "countertrading() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = countertrading( + eic_in = "10YFR-RTE------C", + eic_out = "10YDE-VE-------2", + period = lubridate::ymd("2020-01-01", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) + + +testthat::test_that( + desc = "costs_of_congestion_management() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = costs_of_congestion_management( + eic = "10YFR-RTE------C", + period = lubridate::ymd("2020-01-01", tz = "CET"), + security_token = "dummy_token" + ) + ) + } +) diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index d35da58e..6edf1cbe 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -108,6 +108,10 @@ testthat::test_that( result16 <- grouping_by_common_strings(vector_list = input16) result17 <- grouping_by_common_strings(vector_list = input17) |> unlist() + is_in_which <- function(value, list) { + purrr::map_lgl(list, \(x) value %in% x) |> + which() + } testthat::expect_equal( object = grouping_by_common_strings(vector_list = list()), expected = list() @@ -142,11 +146,11 @@ testthat::test_that( n = 2L ) testthat::expect_setequal( - object = result3[[which(sapply(result3, \(g) 1L %in% g))]], + object = result3[[is_in_which(value = 1L, list = result3)]], expected = c(1L, 3L, 5L) ) testthat::expect_setequal( - object = result3[[which(sapply(result3, \(g) 2L %in% g))]], + object = result3[[is_in_which(value = 2L, list = result3)]], expected = c(2L, 4L) ) testthat::expect_length( @@ -162,11 +166,11 @@ testthat::test_that( n = 2L ) testthat::expect_equal( - object = result5[[which(sapply(result5, \(g) 3L %in% g))]], + object = result5[[is_in_which(value = 3L, list = result5)]], expected = 3L ) testthat::expect_setequal( - object = result5[[which(sapply(result5, \(g) 1L %in% g))]], + object = result5[[is_in_which(value = 1L, list = result5)]], expected = c(1L, 2L, 4L) ) testthat::expect_length( @@ -186,7 +190,7 @@ testthat::test_that( n = 3L ) testthat::expect_setequal( - object = result8[[which(sapply(result8, \(g) 1L %in% g))]], + object = result8[[is_in_which(value = 1L, list = result8)]], expected = c(1L, 3L) ) testthat::expect_length( @@ -194,15 +198,15 @@ testthat::test_that( n = 3L ) testthat::expect_setequal( - object = result9[[which(sapply(result9, \(g) 1L %in% g))]], + object = result9[[is_in_which(value = 1L, list = result9)]], expected = c(1L, 3L, 4L, 7L) ) testthat::expect_setequal( - object = result9[[which(sapply(result9, \(g) 2L %in% g))]], + object = result9[[is_in_which(value = 2L, list = result9)]], expected = c(2L, 5L) ) testthat::expect_equal( - object = result9[[which(sapply(result9, \(g) 6L %in% g))]], + object = result9[[is_in_which(value = 6L, list = result9)]], expected = 6L ) testthat::expect_length( @@ -218,7 +222,7 @@ testthat::test_that( n = 2L ) testthat::expect_setequal( - object = result12[[which(sapply(result12, \(g) 1L %in% g))]], + object = result12[[is_in_which(value = 1L, list = result12)]], expected = c(1L, 2L) ) testthat::expect_length( @@ -226,7 +230,7 @@ testthat::test_that( n = 2L ) testthat::expect_setequal( - object = result13[[which(sapply(result13, \(g) 1L %in% g))]], + object = result13[[is_in_which(value = 1L, list = result13)]], expected = c(1L, 2L) ) testthat::expect_length( @@ -234,7 +238,7 @@ testthat::test_that( n = 2L ) testthat::expect_setequal( - object = result14[[which(sapply(result14, \(g) 1L %in% g))]], + object = result14[[is_in_which(value = 1L, list = result14)]], expected = c(1L, 2L) ) testthat::expect_length( @@ -242,7 +246,7 @@ testthat::test_that( n = 2L ) testthat::expect_setequal( - object = result15[[which(sapply(result15, \(g) 1L %in% g))]], + object = result15[[is_in_which(value = 1L, list = result15)]], expected = c(1L, 2L) ) testthat::expect_true( @@ -427,12 +431,16 @@ testthat::test_that( data(mtcars) mtcars$make <- row.names(mtcars) gzip_sample_file <- tempfile(fileext = ".gzip") - data.table::fwrite(x = mtcars, file = gzip_sample_file, compress = "gzip") + gz_conn <- gzfile(description = gzip_sample_file, open = "wb") + utils::write.csv(x = mtcars, file = gz_conn, row.names = FALSE) + close(con = gz_conn) csv_sample_file <- tempfile(fileext = ".csv") zip_sample_file <- tempfile(fileext = ".zip") xml_sample_file <- tempfile(fileext = "xml") zip_xml_sample_file <- tempfile(fileext = ".zip") - data.table::fwrite(x = mtcars, file = csv_sample_file, sep = ";") + utils::write.table( + x = mtcars, file = csv_sample_file, sep = ";", row.names = FALSE + ) zip( zipfile = zip_sample_file, files = c(csv_sample_file) @@ -576,7 +584,7 @@ testthat::test_that( ) testthat::expect_error( object = api_req( - query_string = "https://web-api.tp.entsoe.eu/api", + query_string = paste0(.api_scheme, .api_domain, .api_name), security_token = Sys.getenv("ENTSOE_PAT") ), regexp = "Unable to parse URI. Its format is not valid" @@ -607,7 +615,7 @@ testthat::test_that( ) testthat::expect_error( object = api_req( - query_string = "https://google.com/", + query_string = paste0(.api_scheme, "google.com/"), security_token = Sys.getenv("ENTSOE_PAT") ), regexp = "Unable to parse URI." @@ -826,52 +834,10 @@ testthat::test_that( ) -testthat::test_that( - desc = "unpack_xml() works", - code = { - testthat::expect_equal( - object = xml2::xml2_example(path = "order-schema.xml") |> - xml2::read_xml() |> - unpack_xml(parent_name = "foo") |> - dim(), - expected = c(1L, 4L) - ) - testthat::expect_contains( - object = xml2::xml2_example(path = "order-schema.xml") |> - xml2::read_xml() |> - unpack_xml(parent_name = "foo") |> - names(), - expected = c( - "foo.schema.schema.annotation.documentation", - "foo.schema.schema.complexType.annotation.documentation", - "foo.schema.schema.complexType.annotation.appinfo", - "foo.schema.schema" - ) - ) - testthat::expect_error( - object = xml2::xml2_example(path = "cd_catalog.xml") |> - xml2::read_xml() |> - unpack_xml(parent_name = "foo"), - info = "Names must be unique!" - ) - # NULL result_vector path (empty XML element) - testthat::expect_equal( - object = xml2::read_xml("") |> - xml2::xml_contents() |> - (\(ns) ns[[1L]])() |> - unpack_xml(parent_name = "foo"), - expected = tibble::tibble() - ) - } -) - - testthat::test_that( desc = "tidy_or_not() works", code = { - test_df_1 <- xml2::xml2_example(path = "order-schema.xml") |> - xml2::read_xml() |> - unpack_xml(parent_name = "foo") + test_df_1 <- tibble::tibble(a = "x", b = "y", c = "z", d = "w") test_df_2 <- tibble::tibble( ts_resolution = rep(x = "PT15M", 12L), ts_reason_code = rep(x = "B01", 12L), @@ -1059,28 +1025,26 @@ testthat::test_that( ) ) data(iris) - testthat::expect_true( - object = identical( - x = add_type_names(tbl = df) |> - names(), - y = c( - "ts_auction_type", - "ts_contract_market_agreement_type", - "process_type", - "ts_production_psr_type", - "ts_asset_psr_type", - "ts_mkt_psr_type", - "ts_business_type", - "type", - "type_def", - "ts_business_type_def", - "ts_mkt_psr_type_def", - "ts_asset_psr_type_def", - "ts_production_psr_type_def", - "process_type_def", - "ts_contract_market_agreement_type_def", - "ts_auction_type_def" - ) + testthat::expect_setequal( + object = add_type_names(tbl = df) |> + names(), + expected = c( + "process_type", + "ts_auction_type", + "ts_contract_market_agreement_type", + "ts_production_psr_type", + "ts_asset_psr_type", + "ts_mkt_psr_type", + "ts_business_type", + "type", + "type_def", + "ts_business_type_def", + "ts_mkt_psr_type_def", + "ts_asset_psr_type_def", + "ts_production_psr_type_def", + "process_type_def", + "ts_contract_market_agreement_type_def", + "ts_auction_type_def" ) ) testthat::expect_no_warning( @@ -1182,11 +1146,11 @@ testthat::test_that( ) testthat::expect_s3_class( object = add_eic_names(tbl = iris), - class = "data.table" + class = "data.frame" ) testthat::expect_equal( object = add_eic_names(tbl = NULL), - expected = data.table::data.table() + expected = data.frame() ) } ) @@ -1228,33 +1192,31 @@ testthat::test_that( ) ) data(iris) - testthat::expect_true( - object = identical( - x = add_definitions(tbl = df) |> - names(), - y = c( - "ts_object_aggregation", - "ts_reason_code", - "reason_code", - "ts_flow_direction", - "ts_auction_category", - "doc_status_value", - "doc_status", - "ts_auction_category_def", - "ts_flow_direction_def", - "reason_text", - "ts_reason_text", - "ts_object_aggregation_def" - ) + testthat::expect_setequal( + object = add_definitions(tbl = df) |> + names(), + expected = c( + "doc_status_value", + "ts_auction_category", + "ts_flow_direction", + "reason_code", + "ts_reason_code", + "ts_object_aggregation", + "doc_status", + "ts_auction_category_def", + "ts_flow_direction_def", + "reason_text", + "ts_reason_text", + "ts_object_aggregation_def" ) ) testthat::expect_s3_class( object = add_definitions(tbl = iris), - class = "data.table" + class = "data.frame" ) testthat::expect_equal( object = add_definitions(tbl = NULL), - expected = data.table::data.table() + expected = data.frame() ) } ) @@ -1506,10 +1468,6 @@ testthat::test_that( "with expected columns on valid XML" ), code = { - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) xml_fixture <- readLines( con = testthat::test_path("fixtures", "get_allocated_eic_min.xml"), encoding = "UTF-8" @@ -1556,10 +1514,6 @@ testthat::test_that( desc = "get_all_allocated_eic() joins doc_status from message_types correctly", code = { - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) xml_fixture <- readLines( con = testthat::test_path("fixtures", "get_allocated_eic_min.xml"), encoding = "UTF-8" @@ -1590,10 +1544,6 @@ testthat::test_that( desc = "get_all_allocated_eic() stops with HTTP error message and request URL", code = { - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) httr2::local_mocked_responses( mock = function(req) { httr2::response( @@ -1623,10 +1573,6 @@ testthat::test_that( testthat::test_that( desc = "get_all_allocated_eic() stops on empty response body", code = { - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) httr2::local_mocked_responses( mock = function(req) { httr2::response( @@ -1644,10 +1590,6 @@ testthat::test_that( testthat::test_that( desc = "get_all_allocated_eic() stops on XML with unexpected tree structure", code = { - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) minimal_xml <- charToRaw(x = paste0( '', "", @@ -1676,10 +1618,6 @@ testthat::test_that( desc = "get_all_allocated_eic() returns one row per EICCode_MarketDocument node", code = { - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) multi_eic_xml <- readLines( con = testthat::test_path("fixtures", "get_allocated_eic_min.xml"), encoding = "UTF-8" @@ -1709,10 +1647,6 @@ testthat::test_that( desc = "get_all_allocated_eic() collapses duplicate Function_Names with ' - '", code = { - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) dupl_fn_xml <- readLines( con = testthat::test_path("fixtures", "get_allocated_eic_min.xml"), encoding = "UTF-8" @@ -1747,10 +1681,6 @@ testthat::test_that( "and URL on no internet connection" ), code = { - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) curl_err <- structure( class = c("curl_error", "error", "condition"), list(message = paste( @@ -1805,14 +1735,6 @@ testthat::test_that( "Function_Names elements with ' - '" ), code = { - testthat::skip_if_not( - condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, - message = "No ENTSOE_PAT environment variable set" - ) - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) xml_fixture <- readLines( con = testthat::test_path("fixtures", "get_allocated_eic_dupl.xml"), encoding = "UTF-8" @@ -1848,10 +1770,6 @@ testthat::test_that( "when bind_cols raises an error" ), code = { - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) xml_fixture <- readLines( con = testthat::test_path("fixtures", "get_allocated_eic_min.xml"), encoding = "UTF-8" @@ -2004,14 +1922,6 @@ testthat::test_that( testthat::test_that( desc = "api_req() stops on unknown 200 response content-type", code = { - testthat::skip_if_not( - condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, - message = "No ENTSOE_PAT environment variable set" - ) - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) httr2::local_mocked_responses( mock = function(req) { httr2::response( @@ -2036,14 +1946,6 @@ testthat::test_that( testthat::test_that( desc = "api_req() stops on HTML error response", code = { - testthat::skip_if_not( - condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, - message = "No ENTSOE_PAT environment variable set" - ) - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) httr2::local_mocked_responses( mock = function(req) { httr2::response( @@ -2072,14 +1974,6 @@ testthat::test_that( testthat::test_that( desc = "api_req() stops on XML error with unexpected Reason structure", code = { - testthat::skip_if_not( - condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, - message = "No ENTSOE_PAT environment variable set" - ) - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) xml_body <- paste0( '', "", @@ -2112,14 +2006,6 @@ testthat::test_that( testthat::test_that( desc = "api_req() stops with code:text message on non-999 XML error code", code = { - testthat::skip_if_not( - condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, - message = "No ENTSOE_PAT environment variable set" - ) - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) xml_body <- paste0( '', "", @@ -2155,14 +2041,6 @@ testthat::test_that( testthat::test_that( desc = "api_req() stops with curl error message on no internet connection", code = { - testthat::skip_if_not( - condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, - message = "No ENTSOE_PAT environment variable set" - ) - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) curl_err <- structure( class = c("curl_error", "error", "condition"), list(message = "Could not resolve host: web-api.tp.entsoe.eu") @@ -2199,14 +2077,6 @@ testthat::test_that( testthat::test_that( desc = "api_req() stops with HTTP 503 message on service unavailable", code = { - testthat::skip_if_not( - condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, - message = "No ENTSOE_PAT environment variable set" - ) - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) httr2::local_mocked_responses( mock = function(req) { httr2::response( @@ -2307,9 +2177,9 @@ testthat::test_that( ) testthat::expect_true( object = there_is_provider( - api_scheme = "http://", + api_scheme = .api_scheme, api_domain = "test.example.com/", - api_name = "api?" + api_name = .api_name ) ) testthat::expect_match( @@ -2326,9 +2196,20 @@ testthat::test_that( "there is no internet connection" ), code = { - testthat::local_mocked_bindings( - has_internet = function() FALSE, - .package = "curl" + httr2::local_mocked_responses( + mock = function(req) { + stop(structure( + class = c("httr2_failure", "httr2_error", "error", "condition"), + list( + message = "Failed to perform HTTP request.", + resp = NULL, + parent = structure( + class = c("curl_error", "error", "condition"), + list(message = "Could not connect to web-api.tp.entsoe.eu") + ) + ) + )) + } ) testthat::expect_false(object = there_is_provider()) } diff --git a/vignettes/architecture.Rmd b/vignettes/architecture.Rmd index 6e4ef7cb..ff03fad4 100644 --- a/vignettes/architecture.Rmd +++ b/vignettes/architecture.Rmd @@ -110,14 +110,24 @@ before any network call is made. Common checks: - Categorical parameters (e.g., `business_type`, `process_type`): validated against allowed values via `checkmate::assert_choice()` -**EIC checksum validation — `assert_eic()` and `.eic_chars`** +**`there_is_provider()`** (`R/utils.R`, exported): A lightweight connectivity +check that sends a dummy request to the ENTSO-E API and returns `TRUE` when the +server responds with HTTP 401 (meaning the endpoint is reachable but the token +was rejected as expected). Returns `FALSE` when no internet connection is +available or the server is unreachable. Its primary role is as an +`@examplesIf` guard in package documentation, ensuring examples are only +executed when the API is accessible. + +**EIC checksum validation — `assert_eic()` and `possible_eic_chars`** (`R/utils.R`): The ENTSO-E EIC standard defines a check character at position -16. The lookup table `.eic_chars` maps the 37 allowed characters (`0–9`, `A–Z`, -`-`) to integers 0–36. `assert_eic()` computes a weighted sum of the first 15 -characters (weights 16 down to 2), derives the expected check character via -`(36 - (sum - 1) %% 37) + 1`, and returns `FALSE` if it does not match the -actual 16th character. This function is not exported; it is called internally -immediately after each `checkmate::assert_string()` EIC check. +16. The named integer vector `possible_eic_chars` maps the 37 allowed characters +(`0–9`, `A–Z`, `-`) to integers 0–36. `assert_eic()` computes a weighted sum of +the first 15 characters (weights 16 down to 2), derives the expected check +character via `(36 - (sum - 1) %% 37) + 1`, and aborts with an informative +message if it does not match the actual 16th character. An optional +`null_ok = TRUE` argument allows `NULL` to pass validation (used by functions +that accept an optional EIC parameter). This function is not exported; it is +called internally immediately after each `checkmate::assert_string()` EIC check. **Step 2 — Timestamp conversion.** `url_posixct_format()` (`R/utils.R`) converts the user-supplied `period_start` / `period_end` to the format required @@ -156,10 +166,11 @@ rather than halting execution. This standardised return shape is what The core HTTP function. Steps: -1. **URL construction.** Assembles the full URL from hard-coded constants: - - Scheme: `https://` - - Domain: `web-api.tp.entsoe.eu/` - - Path: `api?` +1. **URL construction.** Assembles the full URL from package-level constants + defined in `R/constants.R`: + - Scheme: `.api_scheme` (`"https://"`) + - Domain: `.api_domain` (`"web-api.tp.entsoe.eu/"`) + - Path: `.api_name` (`"api?"`) - Appends `query_string` and `&securityToken={token}` - Logs the URL to the console with the token replaced by `<...>` to prevent credential leakage. @@ -167,7 +178,7 @@ The core HTTP function. Steps: 2. **Request configuration.** Uses `httr2::request()` with: - Method: GET - Verbose: response headers only (`req_verbose(header_req=FALSE, header_resp=TRUE)`) - - Timeout: 60 seconds + - Timeout: `.req_timeout` seconds (60, defined in `R/constants.R`) 3. **Execution.** Sent via `purrr::safely(httr2::req_perform)` — another safety wrapper so network errors are captured, not thrown. @@ -374,8 +385,9 @@ maximum age: | `m` | `R/utils.R` (top of file) | EIC name lookup tables used during XML enrichment | | `mh` | `R/en_helpers.R` (top of file) | Full EIC code tibbles downloaded by `*_eic()` functions | -Both are `cachem::cache_mem(max_age = 3600)` objects. The max age is -hard-coded and is not user-configurable. +Both are `cachem::cache_mem(max_age = .max_age)` objects, where `.max_age` is +the package-level constant `3600` (defined in `R/constants.R`). The max age is +not user-configurable. ### 3.2 What gets cached @@ -490,12 +502,12 @@ load_actual_total(eic, period_start, period_end, tidy_output = TRUE) | Setting | Value | Location | |---|---|---| -| API base URL | `https://web-api.tp.entsoe.eu/api?` | `api_req()` in `R/utils.R` | +| API base URL | `https://web-api.tp.entsoe.eu/api?` | `.api_scheme`, `.api_domain`, `.api_name` in `R/constants.R` | | HTTP method | GET | `api_req()` in `R/utils.R` | -| HTTP timeout | 60 seconds | `api_req()` in `R/utils.R` | +| HTTP timeout | 60 seconds (`.req_timeout`) | `R/constants.R`, applied in `api_req()` | | Security token env var | `ENTSOE_PAT` | All user-facing functions | | Verbose logging | Response headers only | `api_req()` in `R/utils.R` | -| Cache max age | 3600 seconds (1 hour) | Top of `R/utils.R` and `R/en_helpers.R` | +| Cache max age | 3600 seconds / 1 hour (`.max_age`) | `R/constants.R`, applied in `R/utils.R` and `R/en_helpers.R` | | Pagination trigger phrase | `"exceeds the allowed maximum"` | `api_req()` in `R/utils.R` | | Forbidden offset doc types | A63+A46/A85, A65+A85, B09+archive, A91, A92, A94+A02 | `api_req()` in `R/utils.R` | | XML encoding | UTF-8 | `api_req()` and `xml_to_table()` | @@ -507,7 +519,9 @@ load_actual_total(eic, period_start, period_end, tidy_output = TRUE) | Component | File | Key Symbols | |---|---|---| -| EIC checksum validation | `R/utils.R` | `assert_eic()`, `.eic_chars` | +| Package constants | `R/constants.R` | `.api_scheme`, `.api_domain`, `.api_name`, `.req_timeout`, `.max_age` | +| EIC checksum validation | `R/utils.R` | `assert_eic()`, `possible_eic_chars` | +| Provider check | `R/utils.R` | `there_is_provider()` | | Cache (general) | `R/utils.R` | `m` | | Cache (EIC helpers) | `R/en_helpers.R` | `mh` | | HTTP request | `R/utils.R` | `api_req()`, `api_req_safe()` | @@ -540,4 +554,5 @@ load_actual_total(eic, period_start, period_end, tidy_output = TRUE) | Nested output | One row per time period, with all data points collected into a `ts_point` list-column (`tidy_output = FALSE`) | | Offset pagination | Mechanism by which `api_req()` splits an oversized query into multiple requests using `&offset=N` parameters, transparent to the caller | | `ENTSOE_PAT` | R environment variable holding the user's ENTSO-E security token | +| `there_is_provider()` | Exported helper that returns `TRUE` when the ENTSO-E API endpoint is reachable; used as an `@examplesIf` guard throughout the package | | `cachem` | R package providing in-memory and disk caches with automatic expiry, used by both `m` and `mh` cache objects |