diff --git a/R/metadata.R b/R/metadata.R index 08a0812..150ad17 100644 --- a/R/metadata.R +++ b/R/metadata.R @@ -7,7 +7,7 @@ create_meta <- function(...) { } #' @export -create_meta.list <- function(metadata) { +create_meta.list <- function(metadata, ...) { if(is.null(names(metadata)) || any(nchar(names(metadata)) == 0)) { stop("All fields of metadata objects must be named!") } @@ -50,7 +50,7 @@ as.tsmeta <- function(meta, ...) { } #' @export -as.tsmeta.data.table <- function(meta) { +as.tsmeta.data.table <- function(meta, ...) { if(nrow(meta) > 0) { out <- apply(meta[, -"ts_key", with = FALSE], 1, as.list) names(out) <- meta$ts_key @@ -63,7 +63,7 @@ as.tsmeta.data.table <- function(meta) { } #' @export -as.tsmeta.list <- function(meta, check_depth = TRUE) { +as.tsmeta.list <- function(meta, check_depth = TRUE, ...) { if(check_depth && !has_depth_2(meta) && length(meta) > 0) { stop("A meta list must have exactly depth 2!") } @@ -76,13 +76,15 @@ as.tsmeta.list <- function(meta, check_depth = TRUE) { } #' @export -as.tsmeta.data.frame <- function(meta) { +as.tsmeta.data.frame <- function(meta, ...) { as.tsmeta(as.data.table(meta)) } #' @export -as.tsmeta.tsmeta <- identity +as.tsmeta.tsmeta <- function(meta, ...) { + meta +} # printers ---------------------------------------------------------------- diff --git a/R/utils.R b/R/utils.R index fefbc09..46a6222 100644 --- a/R/utils.R +++ b/R/utils.R @@ -11,7 +11,7 @@ #' @param as.string logical If as.string is TRUE the string representation of the #' Date is returned, otherwise a Date object. #' @examples -#' index_to_date(2020.25) +#' \dontrun{index_to_date(2020.25)} index_to_date <- function (x, as.string = FALSE) { if(inherits(x, "Date")) { @@ -45,7 +45,7 @@ index_to_date <- function (x, as.string = FALSE) #' #' @return The numeric representation of the date that can be used with ts #' @examples -#' date_to_index("2020-07-01") +#' \dontrun{date_to_index("2020-07-01")} date_to_index <- function(x) { x <- as.character(x) components <- as.numeric(unlist(strsplit(x, "-"))) diff --git a/tests/testthat/test_db_create_connection.R b/tests/testthat/test_db_create_connection.R index caba7b4..40bdb92 100644 --- a/tests/testthat/test_db_create_connection.R +++ b/tests/testthat/test_db_create_connection.R @@ -94,6 +94,8 @@ test_that("password from env, missing", { }) test_that("asking for password", { + skip_if_not(require(rstudioapi) && rstudioapi::isAvailable()) + fake_dbConnect = mock() with_mock( @@ -122,7 +124,7 @@ test_that("getting password from file", { Sys.info = mock(list(user = "bobby")), file.exists = mock(TRUE), dbConnect = fake_dbConnect, - readPasswordFile = fake_readlines, + "timeseriesdb:::readPasswordFile" = fake_readlines, { db_connection_create("mydb", passwd = "my/password/file", @@ -146,7 +148,7 @@ test_that("password from file, line no too big", { with_mock( file.exists = mock(TRUE), - readPasswordFile = fake_readlines, + "timeseriesdb:::readPasswordFile" = fake_readlines, { expect_error( db_connection_create("mydb", diff --git a/tests/testthat/test_db_with_helpers.R b/tests/testthat/test_db_with_helpers.R index 7f59aac..55449d2 100644 --- a/tests/testthat/test_db_with_helpers.R +++ b/tests/testthat/test_db_with_helpers.R @@ -6,7 +6,7 @@ test_that("It creates a temp table and hands it over to admin", { with_mock( dbWriteTable = fake_dbWriteTable, - db_grant_to_admin = fake_db_grant_to_admin, + "timeseriesdb:::db_grant_to_admin" = fake_db_grant_to_admin, dbRemoveTable = mock(), { db_with_temp_table("con", "temp", "content", "field.types", {1+1}, "schema") @@ -37,7 +37,7 @@ test_that("it evaluates the code", { fake_code = mock() with_mock( dbWriteTable = mock(), - db_grant_to_admin = mock(), + "timeseriesdb:::db_grant_to_admin" = mock(), dbRemoveTable = mock(), { db_with_temp_table("con", "temp", "content", "field.types", fake_code(), "schema") @@ -51,7 +51,7 @@ test_that("it removes the table even in error case", { with_mock( dbWriteTable = mock(), - db_grant_to_admin = mock(), + "timeseriesdb:::db_grant_to_admin" = mock(), dbRemoveTable = fake_remove, { capture_error(db_with_temp_table("con", "temp", "content", "field.types", stop("oh noes"), "schema")) @@ -67,7 +67,7 @@ context("db_with_tmp_read") test_that("It warns when using regex with multiple ts_keys", { with_mock( dbWriteTable = mock(), - db_grant_to_admin = mock(), + "timeseriesdb:::db_grant_to_admin" = mock(), dbRemoveTable = mock(), dbExecute = mock(), dbQuoteIdentifier = mock(), @@ -85,7 +85,7 @@ test_that("It only uses the first element of ts_keys when regex == TRUE", { db_quote_literal_mock = mock() with_mock( dbWriteTable = mock(), - db_grant_to_admin = mock(), + "timeseriesdb:::db_grant_to_admin" = mock(), dbRemoveTable = mock(), dbExecute = mock(), dbQuoteIdentifier = mock(), @@ -103,7 +103,7 @@ test_that("It evaluates the code", { with_mock( dbWriteTable = mock(), - db_grant_to_admin = mock(), + "timeseriesdb:::db_grant_to_admin" = mock(), dbRemoveTable = mock(), dbExecute = mock(), dbQuoteIdentifier = mock(), @@ -121,7 +121,7 @@ test_that("It removes the temp table in error case", { with_mock( dbWriteTable = mock(), - db_grant_to_admin = mock(), + "timeseriesdb:::db_grant_to_admin" = mock(), dbRemoveTable = fake_dbRemoveTable, dbExecute = mock(), dbQuoteIdentifier = mock(), @@ -144,7 +144,7 @@ test_with_fresh_db(con_admin, "temp_ts_read gets cleaned up in failure case", { boom_bot <- mock(stop("Kablammy!")) with_mock( - get_tsl_from_res = boom_bot, + "timeseriesdb:::get_tsl_from_res" = boom_bot, { e <- capture_error(db_ts_read(con_admin, "rts1", schema = "tsdb_test")) diff --git a/tests/testthat/test_json_to_ts.R b/tests/testthat/test_json_to_ts.R index 662d51a..01a7097 100644 --- a/tests/testthat/test_json_to_ts.R +++ b/tests/testthat/test_json_to_ts.R @@ -28,7 +28,7 @@ mock_date_to_index <- mock(2019) test_that("it converts a regular json to ts", { # Is this too pedantic? with_mock( - date_to_index = mock_date_to_index, + "timeseriesdb:::date_to_index" = mock_date_to_index, { x <- json_to_ts(regular_json) expect_is(x, "ts") diff --git a/tests/testthat/test_metadata.R b/tests/testthat/test_metadata.R index a7d77c8..ab5076d 100644 --- a/tests/testthat/test_metadata.R +++ b/tests/testthat/test_metadata.R @@ -147,7 +147,7 @@ test_that("as.tsmeta.data.table skips depth check", { fake_as.tsmeta.list <- mock() with_mock( - as.tsmeta.list = fake_as.tsmeta.list, + "timeseriesdb:::as.tsmeta.list" = fake_as.tsmeta.list, { as.tsmeta(as.data.table(meta_df())) } diff --git a/tests/testthat/test_read_metadata.R b/tests/testthat/test_read_metadata.R index b7c4f4d..a6bfc9b 100644 --- a/tests/testthat/test_read_metadata.R +++ b/tests/testthat/test_read_metadata.R @@ -14,8 +14,8 @@ test_that("is passes correct args to db_call_function unlocalized", { fake_db_with_tmp_read <- function(con, keys, regex, code, schema){force(code)} with_mock( - db_call_function = fake_db_call_function, - db_with_tmp_read = fake_db_with_tmp_read, + "timeseriesdb:::db_call_function" = fake_db_call_function, + "timeseriesdb:::db_with_tmp_read" = fake_db_with_tmp_read, { db_metadata_read("con", "vts1", valid_on = "2020-01-01", schema = "schema") @@ -38,8 +38,8 @@ test_that("is passes correct args to db_call_function localized", { fake_db_with_tmp_read <- function(con, keys, regex, code, schema){force(code)} with_mock( - db_with_tmp_read = fake_db_with_tmp_read, - db_call_function = fake_db_call_function, + "timeseriesdb:::db_with_tmp_read" = fake_db_with_tmp_read, + "timeseriesdb:::db_call_function" = fake_db_call_function, { db_metadata_read("con", "vts1", valid_on = "2020-01-01", schema = "schema", locale = "de") diff --git a/tests/testthat/test_release_calendar.R b/tests/testthat/test_release_calendar.R index f440746..b656b82 100644 --- a/tests/testthat/test_release_calendar.R +++ b/tests/testthat/test_release_calendar.R @@ -20,9 +20,9 @@ test_that("defaults", { schema){force(code)} with_mock( - db_call_function = fake_db_call_function, + "timeseriesdb:::db_call_function" = fake_db_call_function, dbWriteTable = mock(), - db_with_temp_table = fake_db_with_tmp_table, + "timeseriesdb:::db_with_temp_table" = fake_db_with_tmp_table, { db_release_create("con", "a_release", diff --git a/tests/testthat/test_store_metadata.R b/tests/testthat/test_store_metadata.R index c4d4af5..0562bda 100644 --- a/tests/testthat/test_store_metadata.R +++ b/tests/testthat/test_store_metadata.R @@ -49,11 +49,11 @@ test_that("is passes correct args to db_call_function unlocalized", { fake_db_call_function = mock() with_mock( - db_with_temp_table = function(con, name, content, field.types, code, schema){eval(code)}, - toJSON = mock("json"), - fromJSON = mock(list(status = "ok")), + "timeseriesdb:::db_with_temp_table" = function(con, name, content, field.types, code, schema){eval(code)}, + "jsonlite::toJSON" = mock("json"), + "jsonlite::fromJSON" = mock(list(status = "ok")), dbExecute = mock(), - db_call_function = fake_db_call_function, + "timeseriesdb:::db_call_function" = fake_db_call_function, { db_metadata_store("con", as.tsmeta.list( @@ -334,11 +334,11 @@ test_that("is passes correct args to db_call_function localized", { fake_db_call_function = mock() with_mock( - db_with_temp_table = function(con, name, content, field.types, code, schema){eval(code)}, - toJSON = mock("json"), - fromJSON = mock(list(status = "ok")), + "timeseriesdb:::db_with_temp_table" = function(con, name, content, field.types, code, schema){eval(code)}, + "jsonlite::toJSON" = mock("json"), + "jsonlite::fromJSON" = mock(list(status = "ok")), dbExecute = mock(), - db_call_function = fake_db_call_function, + "timeseriesdb:::db_call_function" = fake_db_call_function, { db_metadata_store("con", as.tsmeta.list(