This repository was archived by the owner on Aug 2, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
create sub-directories when downloading files with ! #523
Open
amarjandu
wants to merge
1
commit into
master
Choose a base branch
from
issues/amar/1594-subdirs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,18 @@ | |
| from test import reset_tweak_changes, TEST_DIR | ||
|
|
||
|
|
||
| def get_uploaded_file_names(path: str): | ||
| files = [] | ||
| for entry in os.scandir(path=path): | ||
| if entry.is_file(): | ||
| files.append(entry.name) | ||
| if entry.is_dir(): | ||
| nested_files = get_uploaded_file_names(entry.path) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is building an excessive number of temporary strings and lists during recursion. Think about how you can make this more efficient. Also check if there isn't built-in functionality for performing a recursive listing of files. |
||
| for file in nested_files: | ||
| files.append('{}/{}'.format(entry.name, file)) | ||
| return files | ||
|
|
||
|
|
||
| class TestDssApi(unittest.TestCase): | ||
| staging_bucket = "org-humancellatlas-dss-cli-test" | ||
|
|
||
|
|
@@ -71,9 +83,31 @@ def test_python_nested_bundle_upload_download(self): | |
| downloaded_file_paths = [object_name_builder(p, dest_dir) for p in downloaded_file_names] | ||
| self.assertEqual(uploaded_files.sort(), downloaded_file_paths.sort()) | ||
|
|
||
| @unittest.skipIf(os.name is 'nt', 'Unable to test on Windows') # TODO windows testing refactor | ||
| def test_python_exclamation_replacement(self): | ||
| bundle_path = os.path.join(TEST_DIR, "res", "nested_bundle") | ||
| uploaded_files = set(get_uploaded_file_names(bundle_path)) | ||
|
|
||
| bundle_output = self.client.upload(src_dir=bundle_path, | ||
| replica="aws", | ||
| staging_bucket=self.staging_bucket) | ||
|
|
||
| bundle_uuid = bundle_output['bundle_uuid'] | ||
| bundle_version = bundle_output['version'] | ||
| bundle_fqid = "{}.{}".format(bundle_uuid, bundle_version) | ||
|
|
||
| manifest_files = bundle_output['files'] | ||
| self.assertEqual({file['name'] for file in manifest_files}, uploaded_files) | ||
|
|
||
| with tempfile.TemporaryDirectory() as dest_dir: | ||
| self.client.download(bundle_uuid=bundle_output['bundle_uuid'], replica="aws", download_dir=dest_dir) | ||
| nested_downloaded_files = [file.name for file in os.scandir('{}/{}/zarr'.format(dest_dir, bundle_fqid))] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you really have to list all files to assert that two of them were downloaded? What about |
||
| for file in ['exclamation.zattrs', 'nested.zattrs']: | ||
| self.assertIn(file, nested_downloaded_files) | ||
|
|
||
| def test_python_upload_download(self): | ||
| bundle_path = os.path.join(TEST_DIR, "res", "bundle") | ||
| uploaded_files = set(os.listdir(bundle_path)) | ||
| uploaded_files = set(get_uploaded_file_names(bundle_path)) | ||
|
|
||
| manifest = self.client.upload(src_dir=bundle_path, | ||
| replica="aws", | ||
|
|
@@ -139,7 +173,7 @@ def test_python_upload_download(self): | |
|
|
||
| def test_python_manifest_download(self): | ||
| bundle_path = os.path.join(TEST_DIR, "res", "bundle") | ||
| uploaded_files = set(os.listdir(bundle_path)) | ||
| uploaded_files = set(get_uploaded_file_names(bundle_path)) | ||
|
|
||
| manifest = self.client.upload(src_dir=bundle_path, | ||
| replica="aws", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "README": "The schema adopted in this zarr store may undergo changes in the future", | ||
| "sample_id": "0432e9a5-604f-4cb7-8571-014eb5fd8ba2" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "README": "The schema adopted in this zarr store may undergo changes in the future", | ||
| "sample_id": "0432e9a5-604f-4cb7-8571-014eb5fd8ba2" | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and
else: assert Falseat the end.