Skip to content

Commit

Permalink
digest Zenodo API update (#528)
Browse files Browse the repository at this point in the history
* account for /content in zenodo api

* bump post

* skip tests depending on zenodo
  • Loading branch information
FynnBe authored Oct 16, 2023
1 parent 91ea364 commit 333cfaa
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 7 deletions.
4 changes: 2 additions & 2 deletions bioimageio/spec/VERSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "0.4.9post1"
}
"version": "0.4.9post2"
}
15 changes: 10 additions & 5 deletions bioimageio/spec/shared/raw_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
"""
import dataclasses
import os

import packaging.version
import pathlib
from dataclasses import dataclass
from typing import ClassVar, List, Optional, Sequence, Union
from urllib.parse import urlparse
from urllib.request import url2pathname

import packaging.version
from marshmallow import missing
from marshmallow.utils import _Missing

Expand Down Expand Up @@ -72,9 +71,15 @@ def __truediv__(self, other):
return other
else:
other = pathlib.PurePosixPath(other)
return dataclasses.replace(
self, path=(pathlib.PurePosixPath(self.path) / other).as_posix(), uri_string=None
)
if (
self.authority == "zenodo.org"
and self.path.startswith("/api/records/")
and self.path.endswith("/content")
):
new_path = (pathlib.PurePosixPath(self.path).parent / other / "content").as_posix()
else:
new_path = (pathlib.PurePosixPath(self.path) / other).as_posix()
return dataclasses.replace(self, path=new_path, uri_string=None)
elif isinstance(other, URI):
return other
else:
Expand Down
6 changes: 6 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
import zipfile
from typing import Sequence

import pytest

from bioimageio.spec.io_ import (
load_raw_resource_description,
save_raw_resource_description,
serialize_raw_resource_description,
)
from bioimageio.spec.shared import yaml

SKIP_ZENODO = True
SKIP_ZENODO_REASON = "zenodo api changes"


def run_subprocess(commands: Sequence[str], **kwargs) -> subprocess.CompletedProcess:
return subprocess.run(commands, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding="utf-8", **kwargs)
Expand Down Expand Up @@ -45,6 +50,7 @@ def test_cli_validate_model_url_wo_cache():
assert ret.returncode == 0


@pytest.mark.skipif(SKIP_ZENODO, reason=SKIP_ZENODO_REASON)
def test_cli_validate_model_doi():
ret = run_subprocess(["bioimageio", "validate", "10.5281/zenodo.5744489"])
assert ret.returncode == 0
Expand Down
9 changes: 9 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import zipfile
from io import BytesIO, StringIO

import pytest

from bioimageio.spec import (
load_raw_resource_description,
serialize_raw_resource_description,
Expand All @@ -9,6 +11,9 @@
from bioimageio.spec.model import format_version, raw_nodes
from bioimageio.spec.shared import yaml

SKIP_ZENODO = True
SKIP_ZENODO_REASON = "zenodo api changes"


def test_validate_dataset(dataset_rdf):
from bioimageio.spec.commands import validate
Expand Down Expand Up @@ -41,13 +46,15 @@ def test_validate_model_as_url():
)["error"]


@pytest.mark.skipif(SKIP_ZENODO, reason=SKIP_ZENODO_REASON)
def test_validate_model_as_zenodo_sandbox_doi():
from bioimageio.spec.commands import validate

doi = "10.5281/zenodo.5744489"
assert not validate(doi, update_format=False, update_format_inner=False)["error"]


@pytest.mark.skipif(SKIP_ZENODO, reason=SKIP_ZENODO_REASON)
def test_validate_model_as_zenodo_doi():
from bioimageio.spec.commands import validate

Expand All @@ -66,6 +73,7 @@ def test_validate_model_as_bioimageio_full_version_id_partner():
assert summary["status"] == "passed", summary["error"]


@pytest.mark.skipif(SKIP_ZENODO, reason=SKIP_ZENODO_REASON)
def test_validate_model_as_bioimageio_full_version_id_zenodo():
from bioimageio.spec.commands import validate

Expand All @@ -82,6 +90,7 @@ def test_validate_model_as_bioimageio_resource_id_partner():
assert summary["status"] == "passed", summary["error"]


@pytest.mark.skipif(SKIP_ZENODO, reason=SKIP_ZENODO_REASON)
def test_validate_model_as_bioimageio_resource_id_zenodo():
from bioimageio.spec.commands import validate

Expand Down
6 changes: 6 additions & 0 deletions tests/test_io.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import pathlib

import pytest

from bioimageio.spec.shared import yaml

SKIP_ZENODO = True
SKIP_ZENODO_REASON = "zenodo api changes"


def test_get_resource_package_content(unet2d_nuclei_broad_latest, unet2d_nuclei_broad_url):
from bioimageio.spec import get_resource_package_content
Expand All @@ -13,6 +18,7 @@ def test_get_resource_package_content(unet2d_nuclei_broad_latest, unet2d_nuclei_
assert local_keys == remote_keys


@pytest.mark.skipif(SKIP_ZENODO, reason=SKIP_ZENODO_REASON)
def test_load_animal_nickname():
from bioimageio.spec import load_raw_resource_description
from bioimageio.spec.model.v0_4.raw_nodes import Model as Model04
Expand Down
5 changes: 5 additions & 0 deletions tests/test_schema_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
from bioimageio.spec.model.v0_4 import raw_nodes as raw_nodes_m04
from bioimageio.spec.shared import yaml

SKIP_ZENODO = True
SKIP_ZENODO_REASON = "zenodo api changes"


def test_model_rdf_is_valid_general_rdf(unet2d_nuclei_broad_latest):
from bioimageio.spec.rdf.schema import RDF
Expand Down Expand Up @@ -216,6 +219,7 @@ def test_output_ref_shape_too_small(model_dict):
}


@pytest.mark.skipif(SKIP_ZENODO, reason=SKIP_ZENODO_REASON)
def test_model_has_parent_with_uri(model_dict):
from bioimageio.spec.model.schema import Model

Expand All @@ -225,6 +229,7 @@ def test_model_has_parent_with_uri(model_dict):
assert isinstance(valid_data, raw_nodes_m04.Model)


@pytest.mark.skipif(SKIP_ZENODO, reason=SKIP_ZENODO_REASON)
def test_model_has_parent_with_id(model_dict):
from bioimageio.spec.model.schema import Model

Expand Down

0 comments on commit 333cfaa

Please sign in to comment.