-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[#55] Update testsuite
- Loading branch information
Showing
17 changed files
with
291 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
linters: linters_with_defaults( | ||
line_length_linter(99) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,191 +1,191 @@ | ||
#' @noRd | ||
msg_sfplus_required <- function(var, verb = "Omitting") { | ||
stop(verb, " '", var, "' is reserved for SimFin+ users.", call. = FALSE) | ||
stop(verb, " '", var, "' is reserved for SimFin+ users.", call. = FALSE) | ||
} | ||
|
||
#' @importFrom checkmate assert_string | ||
#' @noRd | ||
check_api_key <- function(api_key) { | ||
checkmate::assert_string(api_key)#, pattern = "^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*$") | ||
checkmate::assert_string(api_key) # , pattern = "^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*$") | ||
} | ||
|
||
#' @importFrom checkmate assert_directory | ||
#' @noRd | ||
check_cache_dir <- function(cache_dir) { | ||
if (!is.null(cache_dir)) { | ||
checkmate::assert_directory(cache_dir, access = "rw") | ||
} | ||
if (!is.null(cache_dir)) { | ||
checkmate::assert_directory(cache_dir, access = "rw") | ||
} | ||
} | ||
|
||
#' @importFrom checkmate assert_logical | ||
#' @noRd | ||
check_sfplus <- function(sfplus) { | ||
checkmate::assert_logical(sfplus, any.missing = FALSE, len = 1L) | ||
checkmate::assert_logical(sfplus, any.missing = FALSE, len = 1L) | ||
} | ||
|
||
#' @importFrom checkmate assert_character | ||
#' @noRd | ||
check_ticker <- function(ticker) { | ||
checkmate::assert_character( | ||
ticker, | ||
pattern = "^[A-Za-z0-9_\\.\\:\\-]+$", | ||
any.missing = FALSE, | ||
null.ok = TRUE | ||
) | ||
checkmate::assert_character( | ||
ticker, | ||
pattern = "^[A-Za-z0-9_\\.\\:\\-]+$", | ||
any.missing = FALSE, | ||
null.ok = TRUE | ||
) | ||
} | ||
|
||
#' @importFrom checkmate assert_integerish | ||
#' @noRd | ||
check_id <- function(id) { | ||
checkmate::assert_integerish( | ||
id, | ||
lower = 1L, | ||
any.missing = FALSE, | ||
null.ok = TRUE | ||
) | ||
checkmate::assert_integerish( | ||
id, | ||
lower = 1L, | ||
any.missing = FALSE, | ||
null.ok = TRUE | ||
) | ||
} | ||
|
||
#' @importFrom checkmate assert_choice | ||
#' @noRd | ||
check_statement <- function(statement, sfplus) { | ||
checkmate::assert_subset( | ||
statement, | ||
c("pl", "bs", "cf", "derived"), | ||
empty.ok = FALSE, | ||
fmatch = TRUE | ||
) | ||
# if (statement == "all" & isFALSE(sfplus)) { | ||
# stop('statement = "all" is reserved for SimFin+ users.', call. = FALSE) | ||
# } | ||
checkmate::assert_subset( | ||
statement, | ||
c("pl", "bs", "cf", "derived"), | ||
empty.ok = FALSE, | ||
fmatch = TRUE | ||
) | ||
# if (statement == "all" & isFALSE(sfplus)) { | ||
# stop('statement = "all" is reserved for SimFin+ users.', call. = FALSE) | ||
# } | ||
} | ||
|
||
#' @importFrom checkmate assert_choice | ||
#' @noRd | ||
check_period <- function(period, sfplus, called_from_get_shares = FALSE) { | ||
checkmate::assert_choice( | ||
period, | ||
c("q1", "q2", "q3", "q4", "fy", "h1", "h2", "9m", "6m", "quarters"), | ||
null.ok = TRUE, | ||
fmatch = TRUE | ||
) | ||
if (isFALSE(called_from_get_shares)) { | ||
if (isFALSE(sfplus)) { | ||
if (period %in% c("6m", "quarters")) { | ||
stop( | ||
'period = "', period, '" is reserved for SimFin+ users.', | ||
call. = FALSE | ||
) | ||
} | ||
checkmate::assert_choice( | ||
period, | ||
c("q1", "q2", "q3", "q4", "fy", "h1", "h2", "9m", "6m", "quarters"), | ||
null.ok = TRUE, | ||
fmatch = TRUE | ||
) | ||
if (isFALSE(called_from_get_shares)) { | ||
if (isFALSE(sfplus)) { | ||
if (period %in% c("6m", "quarters")) { | ||
stop( | ||
'period = "', period, '" is reserved for SimFin+ users.', | ||
call. = FALSE | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
#' @noRd | ||
check_period_get_shares <- function(...) { | ||
check_period(...) | ||
check_period(...) | ||
} | ||
|
||
|
||
#' @importFrom checkmate assert_integerish | ||
#' @noRd | ||
check_fyear <- function(fyear, sfplus) { | ||
if (is.null(fyear) && isFALSE(sfplus)) { | ||
msg_sfplus_required("fyear") | ||
} | ||
checkmate::assert_integerish( | ||
fyear, | ||
lower = 1900L, | ||
upper = data.table::year(Sys.Date()), | ||
null.ok = TRUE | ||
) | ||
if (is.null(fyear) && isFALSE(sfplus)) { | ||
msg_sfplus_required("fyear") | ||
} | ||
checkmate::assert_integerish( | ||
fyear, | ||
lower = 1900L, | ||
upper = data.table::year(Sys.Date()), | ||
null.ok = TRUE | ||
) | ||
} | ||
|
||
#' @noRd | ||
check_fyear_get_shares <- function(..., type) { | ||
if (type %in% c("wa-basic", "wa-diluted")) { | ||
check_fyear(...) | ||
} | ||
if (type %in% c("wa-basic", "wa-diluted")) { | ||
check_fyear(...) | ||
} | ||
} | ||
|
||
#' @importFrom checkmate assert_date | ||
#' @noRd | ||
check_start <- function(start, sfplus) { | ||
if (!is.null(start) && isFALSE(sfplus)) { | ||
msg_sfplus_required("start", "Specifying") | ||
} | ||
checkmate::assert_date( | ||
start, | ||
lower = as.Date("1900-01-01"), | ||
upper = Sys.Date(), | ||
null.ok = TRUE | ||
) | ||
if (!is.null(start) && isFALSE(sfplus)) { | ||
msg_sfplus_required("start", "Specifying") | ||
} | ||
checkmate::assert_date( | ||
start, | ||
lower = as.Date("1900-01-01"), | ||
upper = Sys.Date(), | ||
null.ok = TRUE | ||
) | ||
} | ||
|
||
#' @importFrom checkmate assert_date | ||
#' @noRd | ||
check_end <- function(end, sfplus) { | ||
if (!is.null(end) && isFALSE(sfplus)) { | ||
msg_sfplus_required("end", "Specifying") | ||
} | ||
checkmate::assert_date( | ||
end, | ||
lower = as.Date("1900-01-01"), | ||
upper = Sys.Date(), | ||
null.ok = TRUE | ||
) | ||
if (!is.null(end) && isFALSE(sfplus)) { | ||
msg_sfplus_required("end", "Specifying") | ||
} | ||
checkmate::assert_date( | ||
end, | ||
lower = as.Date("1900-01-01"), | ||
upper = Sys.Date(), | ||
null.ok = TRUE | ||
) | ||
} | ||
|
||
#' @importFrom checkmate assert_logical | ||
#' @noRd | ||
check_ttm <- function(ttm) { | ||
checkmate::assert_logical(ttm, any.missing = FALSE, len = 1L) | ||
checkmate::assert_logical(ttm, any.missing = FALSE, len = 1L) | ||
} | ||
|
||
#' @importFrom checkmate assert_logical | ||
#' @noRd | ||
check_shares <- function(shares, sfplus) { | ||
checkmate::assert_logical(shares, any.missing = FALSE, len = 1L) | ||
|
||
if (isTRUE(shares) && isFALSE(sfplus)) { | ||
stop( | ||
"'shares = TRUE' is reserved to SimFin+ users. As a normal user, please ", | ||
"use 'sfa_get_shares()' with 'type = \"wa-basic\"' or 'type = ", | ||
"\"wa-diluted\".", | ||
call. = FALSE | ||
) | ||
} | ||
checkmate::assert_logical(shares, any.missing = FALSE, len = 1L) | ||
|
||
if (isTRUE(shares) && isFALSE(sfplus)) { | ||
stop( | ||
"'shares = TRUE' is reserved to SimFin+ users. As a normal user, please ", | ||
"use 'sfa_get_shares()' with 'type = \"wa-basic\"' or 'type = ", | ||
"\"wa-diluted\".", | ||
call. = FALSE | ||
) | ||
} | ||
} | ||
|
||
#' @importFrom checkmate assert_logical | ||
#' @noRd | ||
check_ratios <- function(ratios, sfplus) { | ||
if (!is.null(ratios) && isFALSE(sfplus)) { | ||
msg_sfplus_required("ratios", "Specifying") | ||
} | ||
checkmate::assert_logical( | ||
ratios, | ||
any.missing = FALSE, | ||
len = 1L, | ||
null.ok = TRUE | ||
) | ||
if (!is.null(ratios) && isFALSE(sfplus)) { | ||
msg_sfplus_required("ratios", "Specifying") | ||
} | ||
checkmate::assert_logical( | ||
ratios, | ||
any.missing = FALSE, | ||
len = 1L, | ||
null.ok = TRUE | ||
) | ||
} | ||
|
||
#' @importFrom checkmate assert_choice | ||
#' @noRd | ||
check_type <- function(type) { | ||
checkmate::assert_choice( | ||
type, | ||
choices = c("common", "wa-basic", "wa-diluted"), | ||
fmatch = TRUE | ||
) | ||
checkmate::assert_choice( | ||
type, | ||
choices = c("common", "wa-basic", "wa-diluted"), | ||
fmatch = TRUE | ||
) | ||
} | ||
|
||
#' @importFrom checkmate assert_choice | ||
#' @noRd | ||
check_ref_data <- function(ref_data) { | ||
checkmate::assert_choice( | ||
ref_data, | ||
choices = c("industries", "markets"), | ||
fmatch = TRUE | ||
) | ||
checkmate::assert_choice( | ||
ref_data, | ||
choices = c("industries", "markets"), | ||
fmatch = TRUE | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.