Skip to content

Commit 321daa6

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 172f8b0 commit 321daa6

File tree

2 files changed

+62
-19
lines changed

2 files changed

+62
-19
lines changed

repo2docker/contentproviders/dataverse.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def get_persistent_id_from_url(self, url: str) -> str:
106106
)
107107
return data["items"][0]["dataset_persistent_id"]
108108
elif parsed_url.path.startswith("/file.xhtml"):
109-
file_persistent_id = qs['persistentId'][0]
109+
file_persistent_id = qs["persistentId"][0]
110110
dataset_persistent_id = file_persistent_id.rsplit("/", 1)[0]
111111
if file_persistent_id == dataset_persistent_id:
112112
# We can't figure this one out, throw an error
@@ -155,7 +155,6 @@ def fetch(self, spec, output_dir, yield_output=False):
155155
copytree(os.path.join(output_dir, d), output_dir)
156156
shutil.rmtree(os.path.join(output_dir, d))
157157

158-
159158
# Save persistent id
160159
self.persitent_id = persistent_id
161160

tests/contentproviders/test_dataverse.py

+61-17
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,50 @@
1010
harvard_dv = next(_ for _ in test_dv.hosts if _["name"] == "Harvard Dataverse")
1111
cimmyt_dv = next(_ for _ in test_dv.hosts if _["name"] == "CIMMYT Research Data")
1212

13+
1314
@pytest.mark.parametrize(
1415
("doi", "resolved"),
1516
[
16-
("doi:10.7910/DVN/6ZXAGT/3YRRYJ", {"host": harvard_dv, "url": "https://dataverse.harvard.edu/file.xhtml?persistentId=doi:10.7910/DVN/6ZXAGT/3YRRYJ"}),
17-
("10.7910/DVN/6ZXAGT/3YRRYJ", {"host": harvard_dv, "url": "https://dataverse.harvard.edu/file.xhtml?persistentId=doi:10.7910/DVN/6ZXAGT/3YRRYJ"}),
18-
("10.7910/DVN/TJCLKP", {"host": harvard_dv, "url": "https://dataverse.harvard.edu/citation?persistentId=doi:10.7910/DVN/TJCLKP"}),
19-
("https://dataverse.harvard.edu/api/access/datafile/3323458", {"host": harvard_dv, "url": "https://dataverse.harvard.edu/api/access/datafile/3323458"}),
20-
("https://data.cimmyt.org/dataset.xhtml?persistentId=hdl:11529/10016", {"host": cimmyt_dv, "url": "https://data.cimmyt.org/dataset.xhtml?persistentId=hdl:11529/10016"}),
17+
(
18+
"doi:10.7910/DVN/6ZXAGT/3YRRYJ",
19+
{
20+
"host": harvard_dv,
21+
"url": "https://dataverse.harvard.edu/file.xhtml?persistentId=doi:10.7910/DVN/6ZXAGT/3YRRYJ",
22+
},
23+
),
24+
(
25+
"10.7910/DVN/6ZXAGT/3YRRYJ",
26+
{
27+
"host": harvard_dv,
28+
"url": "https://dataverse.harvard.edu/file.xhtml?persistentId=doi:10.7910/DVN/6ZXAGT/3YRRYJ",
29+
},
30+
),
31+
(
32+
"10.7910/DVN/TJCLKP",
33+
{
34+
"host": harvard_dv,
35+
"url": "https://dataverse.harvard.edu/citation?persistentId=doi:10.7910/DVN/TJCLKP",
36+
},
37+
),
38+
(
39+
"https://dataverse.harvard.edu/api/access/datafile/3323458",
40+
{
41+
"host": harvard_dv,
42+
"url": "https://dataverse.harvard.edu/api/access/datafile/3323458",
43+
},
44+
),
45+
(
46+
"https://data.cimmyt.org/dataset.xhtml?persistentId=hdl:11529/10016",
47+
{
48+
"host": cimmyt_dv,
49+
"url": "https://data.cimmyt.org/dataset.xhtml?persistentId=hdl:11529/10016",
50+
},
51+
),
2152
("/some/random/string", None),
2253
("https://example.com/path/here", None),
2354
# Non dataverse DOIs
24-
("https://doi.org/10.21105/joss.01277", None)
25-
]
55+
("https://doi.org/10.21105/joss.01277", None),
56+
],
2657
)
2758
def test_detect(doi, resolved):
2859
assert Dataverse().detect(doi) == resolved
@@ -31,15 +62,28 @@ def test_detect(doi, resolved):
3162
@pytest.mark.parametrize(
3263
("url", "persistent_id"),
3364
[
34-
("https://dataverse.harvard.edu/file.xhtml?persistentId=doi:10.7910/DVN/6ZXAGT/3YRRYJ", "doi:10.7910/DVN/6ZXAGT"),
35-
("https://dataverse.harvard.edu/citation?persistentId=doi:10.7910/DVN/TJCLKP", "doi:10.7910/DVN/TJCLKP"),
36-
("https://dataverse.harvard.edu/api/access/datafile/3323458", "doi:10.7910/DVN/3MJ7IR"),
37-
("https://data.cimmyt.org/dataset.xhtml?persistentId=hdl:11529/10016", "hdl:11529/10016"),
38-
]
65+
(
66+
"https://dataverse.harvard.edu/file.xhtml?persistentId=doi:10.7910/DVN/6ZXAGT/3YRRYJ",
67+
"doi:10.7910/DVN/6ZXAGT",
68+
),
69+
(
70+
"https://dataverse.harvard.edu/citation?persistentId=doi:10.7910/DVN/TJCLKP",
71+
"doi:10.7910/DVN/TJCLKP",
72+
),
73+
(
74+
"https://dataverse.harvard.edu/api/access/datafile/3323458",
75+
"doi:10.7910/DVN/3MJ7IR",
76+
),
77+
(
78+
"https://data.cimmyt.org/dataset.xhtml?persistentId=hdl:11529/10016",
79+
"hdl:11529/10016",
80+
),
81+
],
3982
)
4083
def test_get_persistent_id(url, persistent_id):
4184
assert Dataverse().get_persistent_id_from_url(url) == persistent_id
4285

86+
4387
def test_dataverse_fetch():
4488

4589
dv = Dataverse()
@@ -55,13 +99,13 @@ def test_dataverse_fetch():
5599

56100
# Verify sha256sum of three files
57101
expected_sha = {
58-
'data/primary/primary-data.zip': '880f99a1e1d54a2553be61301f92e06b29236785b8d4d1b7ad0b4595d9d7512b',
59-
'data/2023-01-03.tsv': 'cc9759e8e6bc076dd7c1a8eb53a7ea3d38e8697fa9f544d15768db308516cc5f',
60-
'code/language.py': '1ffb3b3cdc9de01279779f3fc88824672c8ec3ab1c41ecdd5c1b59a9b0202215'
102+
"data/primary/primary-data.zip": "880f99a1e1d54a2553be61301f92e06b29236785b8d4d1b7ad0b4595d9d7512b",
103+
"data/2023-01-03.tsv": "cc9759e8e6bc076dd7c1a8eb53a7ea3d38e8697fa9f544d15768db308516cc5f",
104+
"code/language.py": "1ffb3b3cdc9de01279779f3fc88824672c8ec3ab1c41ecdd5c1b59a9b0202215",
61105
}
62106

63107
for subpath, expected_sha in expected_sha.items():
64-
with open(os.path.join(d, subpath), 'rb') as f:
108+
with open(os.path.join(d, subpath), "rb") as f:
65109
h = hashlib.sha256()
66110
h.update(f.read())
67-
assert h.hexdigest() == expected_sha
111+
assert h.hexdigest() == expected_sha

0 commit comments

Comments
 (0)