initialize hosts as instance variable
MODIFY
repo2docker/contentproviders/figshare.py
repo2docker/contentproviders/figshare.py
@@ -23,7 +23,8 @@ class Figshare(DoiProvider):
- https://figshare.com/articles/binder-examples_requirements/9784088 (only one zipfile, no DOI)
"""
- hosts = [
+ def __init__(self):
+ self.hosts = [
{
"hostname": [
"https://figshare.com/articles/",

MODIFY
repo2docker/contentproviders/zenodo.py
repo2docker/contentproviders/zenodo.py
@@ -14,10 +14,11 @@ from ..utils import copytree, deep_get
class Zenodo(DoiProvider):
"""Provide contents of a Zenodo deposit."""
+ def __init__(self):
# We need the hostname (url where records are), api url (for metadata),
# filepath (path to files in metadata), filename (path to filename in
# metadata), download (path to file download URL), and type (path to item type in metadata)
- hosts = [
+ self.hosts = [
{
"hostname": ["https://zenodo.org/record/", "http://zenodo.org/record/"],
"api": "https://zenodo.org/api/records/",

MODIFY
tests/unit/contentproviders/test_figshare.py
tests/unit/contentproviders/test_figshare.py
@@ -20,31 +20,32 @@ def test_content_id():
assert fig.content_id == "9782777"
+test_fig = Figshare()
test_dois_links = [
- ("10.6084/m9.figshare.9782777", {"host": Figshare.hosts[0], "article": "9782777"}),
+ ("10.6084/m9.figshare.9782777", {"host": test_fig.hosts[0], "article": "9782777"}),
(
"10.6084/m9.figshare.9782777.v1",
- {"host": Figshare.hosts[0], "article": "9782777"},
+ {"host": test_fig.hosts[0], "article": "9782777"},
),
(
"https://doi.org/10.6084/m9.figshare.9782777",
- {"host": Figshare.hosts[0], "article": "9782777"},
+ {"host": test_fig.hosts[0], "article": "9782777"},
),
(
"https://figshare.com/articles/title/97827771234",
- {"host": Figshare.hosts[0], "article": "97827771234"},
+ {"host": test_fig.hosts[0], "article": "97827771234"},
),
(
"https://figshare.com/articles/title/9782777/1",
- {"host": Figshare.hosts[0], "article": "9782777"},
+ {"host": test_fig.hosts[0], "article": "9782777"},
),
(
"https://figshare.com/articles/title/9782777/",
- {"host": Figshare.hosts[0], "article": "9782777"},
+ {"host": test_fig.hosts[0], "article": "9782777"},
),
]
-test_spec = {"host": Figshare.hosts[0], "article": "1234"}
+test_spec = {"host": test_fig.hosts[0], "article": "1234"}
@pytest.mark.parametrize("test_input,expected", test_dois_links)

MODIFY
tests/unit/contentproviders/test_zenodo.py
tests/unit/contentproviders/test_zenodo.py
@@ -21,6 +21,7 @@ def test_content_id():
assert zen.content_id == "3232985"
+test_zen = Zenodo()
test_hosts = [
(
[
@@ -28,7 +29,7 @@ test_hosts = [
"10.5281/zenodo.3232985",
"https://doi.org/10.5281/zenodo.3232985",
],
- {"host": Zenodo.hosts[0], "record": "3232985"},
+ {"host": test_zen.hosts[0], "record": "3232985"},
),
(
[
@@ -36,7 +37,7 @@ test_hosts = [
"10.22002/d1.1235",
"https://doi.org/10.22002/d1.1235",
],
- {"host": Zenodo.hosts[1], "record": "1235"},
+ {"host": test_zen.hosts[1], "record": "1235"},
),
]
@@ -99,7 +100,7 @@ def test_fetch_software_from_github_archive():
with patch.object(Zenodo, "urlopen", new=mock_urlopen):
zen = Zenodo()
- spec = {"host": Zenodo.hosts[0], "record": "1234"}
+ spec = {"host": test_zen.hosts[0], "record": "1234"}
with TemporaryDirectory() as d:
output = []
@@ -140,7 +141,7 @@ def test_fetch_software():
with patch.object(Zenodo, "urlopen", new=mock_urlopen):
with TemporaryDirectory() as d:
zen = Zenodo()
- spec = spec = {"host": Zenodo.hosts[0], "record": "1234"}
+ spec = spec = {"host": test_zen.hosts[0], "record": "1234"}
output = []
for l in zen.fetch(spec, d):
output.append(l)
@@ -181,7 +182,7 @@ def test_fetch_data():
with patch.object(Zenodo, "urlopen", new=mock_urlopen):
with TemporaryDirectory() as d:
zen = Zenodo()
- spec = {"host": Zenodo.hosts[0], "record": "1234"}
+ spec = {"host": test_zen.hosts[0], "record": "1234"}
output = []
for l in zen.fetch(spec, d):
output.append(l)

initialize hosts as instance variable