Skip to content

Commit

Permalink
Fix remaining bug in interpret_cache_type using CSV without suggested…
Browse files Browse the repository at this point in the history
… packages installed.
  • Loading branch information
orgadish committed Jan 19, 2024
1 parent 349dd92 commit 04947fa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion R/interpret_type.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
)

Expand Down
22 changes: 14 additions & 8 deletions tests/testthat/test-cached_read.R
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...)
}
}

Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 04947fa

Please sign in to comment.