Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issue #1961: tidy unzip directory #1962

Closed
wants to merge 15 commits into from

Conversation

burnsal
Copy link

@burnsal burnsal commented Mar 8, 2024

Fix for issue #1961 to allow use_zip to successfully unzip file with different directory structure

@jennybc
Copy link
Member

jennybc commented Mar 8, 2024

Can you create a small .zip file that displays the behaviour you're targetting? And add it as a test fixture, similar to yo-loose-regular.zip and the like, all explained here https://github.com/r-lib/usethis/tree/main/tests/testthat/ref.

Then you can add a new test for your scenario, along these lines:

test_that("tidy_unzip() deals with loose parts, reports unpack destination", {
tmp <- file_temp(ext = ".zip")
fs::file_copy(test_file("yo-loose-regular.zip"), tmp)
dest <- tidy_unzip(tmp)
loose_regular_files <- fs::path_file(fs::dir_ls(dest, recurse = TRUE))
fs::dir_delete(dest)
tmp <- file_temp(ext = ".zip")
fs::file_copy(test_file("yo-loose-dropbox.zip"), tmp)
dest <- tidy_unzip(tmp)
loose_dropbox_files <- fs::path_file(fs::dir_ls(dest, recurse = TRUE))
fs::dir_delete(dest)
tmp <- file_temp(ext = ".zip")
fs::file_copy(test_file("yo-not-loose.zip"), tmp)
dest <- tidy_unzip(tmp)
not_loose_files <- fs::path_file(fs::dir_ls(dest, recurse = TRUE))
fs::dir_delete(dest)
expect_identical(loose_regular_files, loose_dropbox_files)
expect_identical(loose_dropbox_files, not_loose_files)
})

You can put that in a new test, i.e. a new test_that() block inside test-course.R.

R/course.R Outdated Show resolved Hide resolved
@burnsal
Copy link
Author

burnsal commented Mar 12, 2024

Test fixture added. I was not able to find the test_file function, but the test works for me if I change that command to point to the test file in the testthat/ref folder, the test script runs smoothly.

@burnsal burnsal marked this pull request as draft March 26, 2024 15:13
@burnsal burnsal marked this pull request as ready for review March 26, 2024 17:01
@burnsal
Copy link
Author

burnsal commented Mar 26, 2024

@jennybc Sorry for the delay, it took me a while to get back to this! I have resolved typo on previous request and updated test to be compatible with current main branch.

jennybc added a commit that referenced this pull request Jul 27, 2024
Fixes #1961, closes #1962.

Analyzing the above gave me a new/different understanding of common ZIP file organization structures. I think I've got a better heuristic for setting `exdir`.
@jennybc jennybc closed this in 00341c1 Jul 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants