From 899362520caf694fc9bc0b3117361fe8c404c70a Mon Sep 17 00:00:00 2001 From: AmiraBurns - USDA Date: Fri, 8 Mar 2024 10:49:05 -0700 Subject: [PATCH 1/8] modified top_directory helper function to accommodate sub-dirs in zip_files --- R/course.R | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/R/course.R b/R/course.R index 772743717..7ba4f0c02 100644 --- a/R/course.R +++ b/R/course.R @@ -529,10 +529,14 @@ top_directory <- function(filenames) { in_top <- path_dir(filenames) == "." unique_top <- unique(filenames[in_top]) is_directory <- grepl("/$", unique_top) - if (length(unique_top) > 1 || !is_directory) { - NA_character_ + if(length(unique(path_dir(filenames)))==1 & length(unique_top) == 0){ + unique_top <- unique(path_dir(filenames)) } else { - unique_top + if (length(unique_top) > 1 || !is_directory) { + NA_character_ + } else { + unique_top + } } } From 3eae5e7063e6b377ace20920901ace93fc773d82 Mon Sep 17 00:00:00 2001 From: Amira Burns <54477812+burnsal@users.noreply.github.com> Date: Tue, 12 Mar 2024 08:33:17 -0600 Subject: [PATCH 2/8] Update R/course.R stylistic updates Co-authored-by: Jennifer (Jenny) Bryan --- R/course.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/course.R b/R/course.R index 7ba4f0c02..ce2389576 100644 --- a/R/course.R +++ b/R/course.R @@ -529,7 +529,7 @@ top_directory <- function(filenames) { in_top <- path_dir(filenames) == "." unique_top <- unique(filenames[in_top]) is_directory <- grepl("/$", unique_top) - if(length(unique(path_dir(filenames)))==1 & length(unique_top) == 0){ + if (length(unique(path_dir(filenames))) == 1 && length(unique_top) == 0) { unique_top <- unique(path_dir(filenames)) } else { if (length(unique_top) > 1 || !is_directory) { From 0faf4de8114eca3c460d1aebbbd01ea8cce83dc1 Mon Sep 17 00:00:00 2001 From: AmiraBurns - USDA Date: Tue, 12 Mar 2024 08:41:18 -0600 Subject: [PATCH 3/8] add small zip for testthat/test_course rename --- tests/testthat/ref/foo-rename.zip | Bin 0 -> 161 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/testthat/ref/foo-rename.zip diff --git a/tests/testthat/ref/foo-rename.zip b/tests/testthat/ref/foo-rename.zip new file mode 100644 index 0000000000000000000000000000000000000000..7d4f6cc4618f52355f03dbc5b8691185f0b04b84 GIT binary patch literal 161 zcmWIWW@Zs#0D(zmX%RnLS|lZW=g68NHH&0fHxzP2m@{-fu=GrGAMv3AV9Vtz?+o~B*qAYRzNxs#9;sc DJr5zm literal 0 HcmV?d00001 From acc7f0cebfaa0964c46c31e9e4461cc79b10e694 Mon Sep 17 00:00:00 2001 From: AmiraBurns - USDA Date: Tue, 12 Mar 2024 09:30:34 -0600 Subject: [PATCH 4/8] add test for tidy_unzip_directory update --- tests/testthat/test-course.R | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/testthat/test-course.R b/tests/testthat/test-course.R index 0dff96f88..23abb81ab 100644 --- a/tests/testthat/test-course.R +++ b/tests/testthat/test-course.R @@ -106,6 +106,18 @@ test_that("tidy_unzip() deals with loose parts, reports unpack destination", { expect_identical(loose_dropbox_files, not_loose_files) }) +testthat("tidy_unzip() deals with different directory names inside zip file"){ + tmp <- file_temp(ext = ".zip") + fs::file_copy(test_file("foo-rename.zip"), tmp) + dest <- tidy_unzip(tmp) + + found <- path_file(dest) + expected <- unzip(test_file("foo-rename.zip"), list=TRUE)$Name + fs::dir_delete(dest) + + expect_identical(found, expected) +} + ## helpers ---- test_that("create_download_url() works", { expect_equal( From f1290423980da2a9efad3254cfd9442896565086 Mon Sep 17 00:00:00 2001 From: AmiraBurns - USDA Date: Tue, 26 Mar 2024 09:12:16 -0600 Subject: [PATCH 5/8] fix function name test_that typo --- tests/testthat/test-course.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-course.R b/tests/testthat/test-course.R index 03c3b3df7..b069d42a8 100644 --- a/tests/testthat/test-course.R +++ b/tests/testthat/test-course.R @@ -106,7 +106,7 @@ test_that("tidy_unzip() deals with loose parts, reports unpack destination", { expect_identical(loose_dropbox_files, not_loose_files) }) -testthat("tidy_unzip() deals with different directory names inside zip file", { +test_that("tidy_unzip() deals with different directory names inside zip file", { tmp <- file_temp(ext = ".zip") fs::file_copy(test_file("foo-rename.zip"), tmp) dest <- tidy_unzip(tmp) From 192b7acf8add553ee05e6b10304bc0086e21d136 Mon Sep 17 00:00:00 2001 From: AmiraBurns - USDA Date: Tue, 26 Mar 2024 10:42:46 -0600 Subject: [PATCH 6/8] add second file to /foo to test multiple files in the same directory --- tests/testthat/ref/foo-rename.zip | Bin 161 -> 301 bytes tests/testthat/ref/foo/file1.txt | 1 + 2 files changed, 1 insertion(+) create mode 100644 tests/testthat/ref/foo/file1.txt diff --git a/tests/testthat/ref/foo-rename.zip b/tests/testthat/ref/foo-rename.zip index 7d4f6cc4618f52355f03dbc5b8691185f0b04b84..d8341e925e89fd1364116d5a3793178f2200686c 100644 GIT binary patch literal 301 zcmWIWW@Zs#0D(zmX%RnLS|lZW=g68NHH&00NlU~|EdW8<0=_yK!ZS-7s)_F6cfQbg_4ZK5>ylQfkpxi zWMmRy!0kq$sSJz^3LpvykX?+d6Psf|>LEGw2*N^@WdrnBCKo-K)?uuRzNxs#9;scWgY}j diff --git a/tests/testthat/ref/foo/file1.txt b/tests/testthat/ref/foo/file1.txt new file mode 100644 index 000000000..674358ffa --- /dev/null +++ b/tests/testthat/ref/foo/file1.txt @@ -0,0 +1 @@ +I am file1.txt that lives inside /foo From f5c4315ad0208de3564984ef8346dfeb1c7b2484 Mon Sep 17 00:00:00 2001 From: AmiraBurns - USDA Date: Tue, 26 Mar 2024 10:43:16 -0600 Subject: [PATCH 7/8] update test_that tidy_dir to handle dir name updates --- tests/testthat/test-course.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-course.R b/tests/testthat/test-course.R index b069d42a8..d5ed08c4c 100644 --- a/tests/testthat/test-course.R +++ b/tests/testthat/test-course.R @@ -112,7 +112,8 @@ test_that("tidy_unzip() deals with different directory names inside zip file", { dest <- tidy_unzip(tmp) found <- path_file(dest) - expected <- unzip(test_file("foo-rename.zip"), list=TRUE)$Name + foonames <- unzip(test_file("foo-rename.zip"), list=TRUE)$Name + expected <- (unique(dirname(foonames))) fs::dir_delete(dest) expect_identical(found, expected) From 61893a0199f191428107fbd53110ef99fb2d8238 Mon Sep 17 00:00:00 2001 From: AmiraBurns - USDA Date: Tue, 26 Mar 2024 10:43:16 -0600 Subject: [PATCH 8/8] update test_that tidy_dir to handle dir name updates --- tests/testthat/test-course.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-course.R b/tests/testthat/test-course.R index b069d42a8..290158a98 100644 --- a/tests/testthat/test-course.R +++ b/tests/testthat/test-course.R @@ -112,7 +112,8 @@ test_that("tidy_unzip() deals with different directory names inside zip file", { dest <- tidy_unzip(tmp) found <- path_file(dest) - expected <- unzip(test_file("foo-rename.zip"), list=TRUE)$Name + foonames <- unzip(test_file("foo-rename.zip"), list=TRUE)$Name + expected <- (unique(path_dir(foonames))) fs::dir_delete(dest) expect_identical(found, expected)