Skip to content

Commit

Permalink
Merge pull request #657 from bioimage-io/cleanup
Browse files Browse the repository at this point in the history
Cleanup
  • Loading branch information
FynnBe authored Nov 15, 2024
2 parents 09f42d0 + 8f80aea commit d539faf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ def get_ref_url(
) -> str:
"""get github url with line range fragment to reference implementation from non-raw github file url
example:
>>> get_ref_url(
... "class",
... "Binarize",
... "https://github.com/bioimage-io/core-bioimage-io-python/blob/main/bioimageio/core/prediction_pipeline/_processing.py"
... )
'https://github.com/bioimage-io/core-bioimage-io-python/blob/main/bioimageio/core/prediction_pipeline/_processing.py#L120-L127'
Example:
>>> get_ref_url(
... "class",
... "Binarize",
... "https://github.com/bioimage-io/core-bioimage-io-python/blob/main/bioimageio/core/prediction_pipeline/_processing.py"
... )
'https://github.com/bioimage-io/core-bioimage-io-python/blob/main/bioimageio/core/prediction_pipeline/_processing.py#L120-L127'
"""
# hotfix to handle requests not available in pyodide, see
# https://github.com/bioimage-io/bioimage.io/issues/216#issuecomment-1012422194
Expand Down
56 changes: 26 additions & 30 deletions tests/test_package.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import io
import shutil
from pathlib import Path
from tempfile import TemporaryDirectory

from deepdiff import DeepDiff

Expand Down Expand Up @@ -54,34 +53,31 @@ def test_save_bioimageio_package_to_stream_default(unet2d_path: Path):
assert isinstance(stream, io.BytesIO)


def test_save_bioimageio_package_as_folder(unet2d_path: Path):
def test_save_bioimageio_package_as_folder(unet2d_path: Path, tmp_path: Path):
from bioimageio.spec import load_description, save_bioimageio_package_as_folder

with TemporaryDirectory() as tmp_dir:
tmp_dir = Path(tmp_dir)

package_folder = tmp_dir / "package"
_ = save_bioimageio_package_as_folder(unet2d_path, output_path=package_folder)

# load package
model = load_description(package_folder)
assert isinstance(model, v0_5.ModelDescr)

# alter package
doc = model.documentation
assert isinstance(doc, v0_5.RelativeFilePath)
new_doc = f"copy_{doc}"
shutil.move(str(package_folder / str(doc)), str(package_folder / new_doc))
model.documentation = package_folder / new_doc

# export altered package
altered_package = tmp_dir / "altered_package"
altered_package = save_bioimageio_package_as_folder(
model, output_path=altered_package, weights_priority_order=["onnx"]
)
assert (altered_package / new_doc).exists(), altered_package / new_doc

# load altered package
reloaded_model = load_description(altered_package)
assert isinstance(reloaded_model, v0_5.ModelDescr)
assert str(reloaded_model.documentation).startswith("copy_")
package_folder = tmp_path / "package"
_ = save_bioimageio_package_as_folder(unet2d_path, output_path=package_folder)

# load package
model = load_description(package_folder)
assert isinstance(model, v0_5.ModelDescr)

# alter package
doc = model.documentation
assert isinstance(doc, v0_5.RelativeFilePath)
new_doc = f"copy_{doc}"
shutil.move(str(package_folder / str(doc)), str(package_folder / new_doc))
model.documentation = package_folder / new_doc

# export altered package
altered_package = tmp_path / "altered_package"
altered_package = save_bioimageio_package_as_folder(
model, output_path=altered_package, weights_priority_order=["onnx"]
)
assert (altered_package / new_doc).exists(), altered_package / new_doc

# load altered package
reloaded_model = load_description(altered_package)
assert isinstance(reloaded_model, v0_5.ModelDescr)
assert str(reloaded_model.documentation).startswith("copy_")

0 comments on commit d539faf

Please sign in to comment.