From 551bc52864a950c97e1f8759d3a55c78aa797f88 Mon Sep 17 00:00:00 2001 From: Keisuke ANDO Date: Sun, 29 Sep 2024 20:25:56 +0900 Subject: [PATCH] :white_check_mark: Enhanced function to mock --- tests/testthat/test-download-accident-data.R | 22 ++++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/tests/testthat/test-download-accident-data.R b/tests/testthat/test-download-accident-data.R index dc63091..393a02b 100644 --- a/tests/testthat/test-download-accident-data.R +++ b/tests/testthat/test-download-accident-data.R @@ -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$")