-
Notifications
You must be signed in to change notification settings - Fork 374
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
Stop mocking dataverse contentprovider test #1389
Closed
Closed
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 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 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,67 @@ | ||
import hashlib | ||
import os | ||
from tempfile import TemporaryDirectory | ||
|
||
import pytest | ||
|
||
from repo2docker.contentproviders import Dataverse | ||
|
||
test_dv = Dataverse() | ||
harvard_dv = next(_ for _ in test_dv.hosts if _["name"] == "Harvard Dataverse") | ||
cimmyt_dv = next(_ for _ in test_dv.hosts if _["name"] == "CIMMYT Research Data") | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("doi", "resolved"), | ||
[ | ||
( | ||
"doi:10.7910/DVN/6ZXAGT/3YRRYJ", | ||
{"host": harvard_dv, "record": "doi:10.7910/DVN/6ZXAGT"}, | ||
), | ||
( | ||
"10.7910/DVN/6ZXAGT/3YRRYJ", | ||
{"host": harvard_dv, "record": "doi:10.7910/DVN/6ZXAGT"}, | ||
), | ||
( | ||
"https://dataverse.harvard.edu/api/access/datafile/3323458", | ||
{"host": harvard_dv, "record": "doi:10.7910/DVN/3MJ7IR"}, | ||
), | ||
( | ||
"https://data.cimmyt.org/dataset.xhtml?persistentId=hdl:11529/10016", | ||
{"host": cimmyt_dv, "record": "hdl:11529/10016"}, | ||
), | ||
("/some/random/string", None), | ||
("https://example.com/path/here", None), | ||
# Non dataverse DOIs | ||
("https://doi.org/10.21105/joss.01277", None), | ||
], | ||
) | ||
def test_detect(doi, resolved): | ||
assert Dataverse().detect(doi) == resolved | ||
|
||
|
||
def test_dataverse_fetch(): | ||
spec = {"host": harvard_dv, "record": "doi:10.7910/DVN/TJCLKP"} | ||
|
||
dv = Dataverse() | ||
|
||
with TemporaryDirectory() as d: | ||
output = [] | ||
for l in dv.fetch(spec, d): | ||
output.append(l) | ||
|
||
# Verify two directories | ||
assert set(os.listdir(d)) == {"data", "code"} | ||
|
||
# Verify sha256sum of three files | ||
expected_sha = { | ||
"data/primary/primary-data.zip": "880f99a1e1d54a2553be61301f92e06b29236785b8d4d1b7ad0b4595d9d7512b", | ||
"data/2023-01-03.tsv": "cc9759e8e6bc076dd7c1a8eb53a7ea3d38e8697fa9f544d15768db308516cc5f", | ||
"code/language.py": "1ffb3b3cdc9de01279779f3fc88824672c8ec3ab1c41ecdd5c1b59a9b0202215", | ||
} | ||
|
||
for subpath, expected_sha in expected_sha.items(): | ||
with open(os.path.join(d, subpath), "rb") as f: | ||
h = hashlib.sha256() | ||
h.update(f.read()) | ||
assert h.hexdigest() == expected_sha |
This file was deleted.
Oops, something went wrong.
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.
Can you add a comment explaining what this iterates through, and what we end up comparing in the test? Are the names
Harvard Dataverse
/CIMMYT Research Data
considered immutable properties of the repository?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.
@manics I'll do so, although I didn't add these - they were already there in the existing file.
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.
@manics I've incorporated this into #1390, and simply removed using "host" this way completely.