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

Stop mocking dataverse contentprovider test #1389

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ jobs:
- r
- unit
- venv
- contentproviders
include:
# The actions/setup-python action with Python version 3.6 isn't
# possible to use with the ubuntu-22.04 runner, so we use ubuntu-20.04
Expand Down
67 changes: 67 additions & 0 deletions tests/contentproviders/test_dataverse.py
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")
Copy link
Member

@manics manics Dec 17, 2024

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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.

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
160 changes: 0 additions & 160 deletions tests/unit/contentproviders/test_dataverse.py

This file was deleted.