-
Notifications
You must be signed in to change notification settings - Fork 90
Add support for NIST Public Data Reposity DOIs #442
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
Open
jat255
wants to merge
2
commits into
fatiando:main
Choose a base branch
from
jat255:add_NIST_pdr_doi_repository
base: main
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
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,7 +7,9 @@ | |||||||
| """ | ||||||||
| Test the downloader classes and functions separately from the Pooch core. | ||||||||
| """ | ||||||||
| import hashlib | ||||||||
| import os | ||||||||
| import re | ||||||||
| import sys | ||||||||
| from tempfile import TemporaryDirectory | ||||||||
|
|
||||||||
|
|
@@ -33,6 +35,7 @@ | |||||||
| FigshareRepository, | ||||||||
| ZenodoRepository, | ||||||||
| DataverseRepository, | ||||||||
| NISTPDRRepository, | ||||||||
| doi_to_url, | ||||||||
| ) | ||||||||
| from ..processors import Unzip | ||||||||
|
|
@@ -45,6 +48,8 @@ | |||||||
| pooch_test_zenodo_url, | ||||||||
| pooch_test_zenodo_with_slash_url, | ||||||||
| pooch_test_dataverse_url, | ||||||||
| pooch_test_nist_pdr_url, | ||||||||
| pooch_test_nist_pdr_nested_file, | ||||||||
| ) | ||||||||
|
|
||||||||
|
|
||||||||
|
|
@@ -140,6 +145,93 @@ def test_doi_downloader(url): | |||||||
| check_tiny_data(outfile) | ||||||||
|
|
||||||||
|
|
||||||||
| @pytest.mark.network | ||||||||
| def test_doi_downloader_nist_pdr(): | ||||||||
| """ | ||||||||
| Test the DOI downloader for the NIST PDR. | ||||||||
|
|
||||||||
| The NIST PDR does not have a record with 'tiny-data.txt', | ||||||||
| so uses a slightly different test implementation than test_doi_downloader() | ||||||||
| """ | ||||||||
| with TemporaryDirectory() as local_store: | ||||||||
| downloader = DOIDownloader() | ||||||||
| outfile = os.path.join(local_store, "README.txt") | ||||||||
| to_download = pooch_test_nist_pdr_url("simple") + "README.txt" | ||||||||
| downloader(to_download, outfile, None) | ||||||||
|
|
||||||||
| assert os.path.exists(outfile) | ||||||||
| with open(outfile, encoding="utf-8") as tinydata: | ||||||||
| content = tinydata.read() | ||||||||
| true_content = ( | ||||||||
| "The `labbench` python library provides tools for instrument automation" | ||||||||
| ) | ||||||||
| assert content.strip()[:70] == true_content | ||||||||
|
|
||||||||
|
|
||||||||
| @pytest.mark.network | ||||||||
| def test_doi_downloader_nist_pdr_file_in_collection(): | ||||||||
| """ | ||||||||
| Test the DOI downloader for the NIST PDR. | ||||||||
|
|
||||||||
| This test tests a file deeper in a nested collection | ||||||||
| """ | ||||||||
| with TemporaryDirectory() as local_store: | ||||||||
| downloader = DOIDownloader() | ||||||||
| file_path = pooch_test_nist_pdr_nested_file()["filename"] | ||||||||
| outfile = os.path.join(local_store, file_path.rsplit("/", maxsplit=1)[-1]) | ||||||||
| to_download = pooch_test_nist_pdr_url("nested_collection") + file_path | ||||||||
| downloader(to_download, outfile, None) | ||||||||
|
|
||||||||
| assert os.path.exists(outfile) | ||||||||
| with open(outfile, "rb") as tinydata: | ||||||||
| assert ( | ||||||||
| hashlib.sha256(tinydata.read()).hexdigest() | ||||||||
| == pooch_test_nist_pdr_nested_file()["checksum"][7:] | ||||||||
| ) | ||||||||
|
|
||||||||
|
|
||||||||
| @pytest.mark.network | ||||||||
| def test_doi_downloader_nist_pdr_missing_file(): | ||||||||
| """ | ||||||||
| Test the DOI downloader for the NIST PDR. | ||||||||
|
|
||||||||
| This test tests a file deeper in a nested collection | ||||||||
| """ | ||||||||
| with TemporaryDirectory() as local_store: | ||||||||
| downloader = DOIDownloader() | ||||||||
| file_path = "nonexistent_file.txt" | ||||||||
| outfile = os.path.join(local_store, file_path.rsplit("/", maxsplit=1)[-1]) | ||||||||
| to_download = pooch_test_nist_pdr_url("nested_collection") + file_path | ||||||||
| with pytest.raises( | ||||||||
| ValueError, | ||||||||
| match=re.escape( | ||||||||
| "File 'nonexistent_file.txt' not found in data archive " | ||||||||
| "https://data.nist.gov/od/id/8C40CFA7931709DAE0532457068179072082 " | ||||||||
| "(doi:10.18434/M32082).", | ||||||||
| ), | ||||||||
| ): | ||||||||
| downloader(to_download, outfile, None) | ||||||||
|
|
||||||||
|
|
||||||||
| def test_populate_registry_nist_pdr(tmp_path): | ||||||||
|
Member
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. The registry population requires us to ping the server, so let's decorate this test with
Suggested change
|
||||||||
| """ | ||||||||
| Test if population of registry is correctly done for NIST PDR. | ||||||||
| """ | ||||||||
| # Create sample pooch object | ||||||||
| puppy = Pooch(base_url="", path=tmp_path) | ||||||||
| _doi = "10.18434/M32082" | ||||||||
| _doi_url = doi_to_url(_doi) | ||||||||
| # Create NIST PDR downloader | ||||||||
| downloader = NISTPDRRepository(doi=_doi, archive_url=_doi_url) | ||||||||
| # Populate registry | ||||||||
| downloader.populate_registry(puppy) | ||||||||
| assert len(puppy.registry) == 101 | ||||||||
| assert ( | ||||||||
| puppy.registry[pooch_test_nist_pdr_nested_file()["filename"]] | ||||||||
| == pooch_test_nist_pdr_nested_file()["checksum"] | ||||||||
| ) | ||||||||
|
|
||||||||
|
|
||||||||
| @pytest.mark.network | ||||||||
| def test_zenodo_downloader_with_slash_in_fname(): | ||||||||
| """ | ||||||||
|
|
||||||||
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
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.
These notes were intended only for the Zenodo downloader, so we can remove them from here.