Skip to content

Commit

Permalink
✅ Enhanced function to mock
Browse files Browse the repository at this point in the history
  • Loading branch information
NONONOexe committed Sep 29, 2024
1 parent 2dd4e3a commit 551bc52
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions tests/testthat/test-download-accident-data.R
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
test_that("`download_accident_data` works with valid inputs", {
local_mocked_bindings(download.file = function(url, destfile) {
file.copy(mock_accident_data_path, destfile, overwrite = TRUE)
if (!file.exists(mock_accident_data_path)) {
cat("Source file does not exist: ", mock_accident_data_path, "\n")
}

copy_result <- file.copy(mock_accident_data_path, destfile,
overwrite = TRUE)

if (!copy_result) {
cat("Failed to copy file: ", mock_accident_data_path, " to ", destfile,
"\n")
}

return(destfile)
})

# Test with "main" data type
downloaded_file_path <- suppressMessages(
download_accident_data("main", temp_dir, 2022)
download_accident_data("main", tempdir(), 2022)
)

## --DEBUG BEGIN--
cat("Tempdir: ", temp_dir, "\n")
cat("Downloaded file path: ", downloaded_file_path, "\n")
cat("Is tempdir exists? ", dir.exists(temp_dir), "\n")
cat("Is downloaded file exists? ", file.exists(downloaded_file_path), "\n")
## --DEBUG END--

expect_true(file.exists(downloaded_file_path))
expect_match(downloaded_file_path, "honhyo_2022[.]csv$")

Expand Down

0 comments on commit 551bc52

Please sign in to comment.