Skip to content

Commit

Permalink
Merge pull request #370 from henrykironde/ziptest
Browse files Browse the repository at this point in the history
Add tests for zip and unszip
  • Loading branch information
henrykironde authored Dec 16, 2023
2 parents 646ab63 + 4902f47 commit b7e35bb
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ testing_dir/*
inst/app/models.knit.md
*.DS_Store*
.Rproj.user
*Rplots.pdf*
49 changes: 48 additions & 1 deletion tests/testthat/test-23-fill_dir.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,51 @@ test_that(desc = "fill_models adds the models control list and any model scripts
expect_equal(sort(files),
sort(checks))

})
})


zip_name <- c("forecast_id_2019-11-15.zip")
eval_zip <- c("forecasts_evaluations.zip")
resources_forecast <- file.path(main3, "resources/portal-forecasts/forecasts")
expected <- c(
"forecast_id_1.01_forecast_table.csv",
"forecast_id_1.01_metadata.yaml",
"forecast_id_1.01_model_forecast.json",
"forecasts_evaluations.csv",
"forecasts_metadata.csv"
)
monk_forecast <- file.path(tempdir(), "forecasts/")
#Create the monk_forecast directory if it doesn't exist
if (!file.exists(monk_forecast)) {
dir.create(monk_forecast, recursive = TRUE)
}
#Copy files from resources_forecast to monk_forecast
file.copy(file.path(resources_forecast, expected), monk_forecast, overwrite = TRUE)
#Check if files are successfully copied
copied_files <- list.files(monk_forecast)
if (all(copied_files %in% expected)) {
print("Files copied successfully.")
} else {
warning("Failed to copy files.")
}


test_that("Zip All Forecast Files", {
skip_on_cran()
zip_unzip(type = "zip", forecast_path = monk_forecast)
expect_true(file.exists(file.path(monk_forecast, zip_name)),
info = paste("File", zip_name, "does not exist in the directory."))
expect_true(file.exists(file.path(monk_forecast, eval_zip)),
info = paste("File", zip_name, "does not exist in the directory."))
})


test_that("Unzip All Forecast Files", {
skip_on_cran()
zip_unzip(type = "unzip", forecast_path = monk_forecast)
file_existence <- sapply(expected, function(file_name) {
full_path <- file.path(resources_forecast, file_name)
file.exists(full_path)
})
expect_true(all(file_existence), info = "Not all expected files exist in the directory.")
})

0 comments on commit b7e35bb

Please sign in to comment.