diff --git a/R/interpret_type.R b/R/interpret_type.R index ad6b31b..4bec4bd 100644 --- a/R/interpret_type.R +++ b/R/interpret_type.R @@ -31,7 +31,7 @@ get_csv_fns <- function(type = NULL) { }, "base" = list( read = vectorize_reader(utils::read.csv, "file_path"), - write = utils::write.csv + write = \(x, f) utils::write.csv(x, f, row.names = FALSE) ) ) diff --git a/tests/testthat/test-cached_read.R b/tests/testthat/test-cached_read.R index cba999f..11e3ca6 100644 --- a/tests/testthat/test-cached_read.R +++ b/tests/testthat/test-cached_read.R @@ -40,17 +40,19 @@ create_temp_cache_dir <- function() { # Helpers ----------------------------------------------------------------- -vectorized_read_csv <- function(...) { - vectorize_reader(read.csv)(...) +vectorized_read_csv <- function(files, ...) { + out <- suppressMessages(get_csv_read_fn()(files, ...)) + out$file_path <- NULL + out } #' A read_fn that has an expectation of being called or not. #' #' @param expected Whether to expect call or not. read_csv_with_expectation <- function(expected) { - function(...) { + function(files, ...) { expect(expected, "Original `read_fn` was called when not expected...") - vectorized_read_csv(...) + vectorized_read_csv(files, ...) } } @@ -77,6 +79,14 @@ expect_cache_file_info <- function(dir_path, exists, ext = CACHE_EXT) { # Expect Equal DFs expect_equal_dfs <- function(x, y) { + if (!is.data.frame(x) || !is.data.frame(y)) { + stop("`expect_equal_dfs` can only be used on data frames!") + } + + # Ignore the file_path. + x$file_path <- NULL + y$file_path <- NULL + xn <- names(x) yn <- names(y) @@ -139,10 +149,6 @@ expect_skip_file_info_works <- function(cache_ext, type = NULL) { type = type, ) - if ("file_path" %in% names(res)) { - res$file_path <- NULL - } - expect_equal_dfs(res, iris_complete) expect_cache_file(temp_cache_dir, TRUE, ext = cache_ext)