diff --git a/bioimageio/spec/_internal/common_nodes.py b/bioimageio/spec/_internal/common_nodes.py index 4a258859..09d1a616 100644 --- a/bioimageio/spec/_internal/common_nodes.py +++ b/bioimageio/spec/_internal/common_nodes.py @@ -60,6 +60,7 @@ from .io_utils import write_content_to_zip from .node import Node from .packaging_context import PackagingContext +from .root_url import RootHttpUrl from .url import HttpUrl from .utils import ( assert_all_params_set_explicitly, @@ -343,12 +344,12 @@ def validation_summary(self) -> ValidationSummary: assert self._validation_summary is not None, "access only after initialization" return self._validation_summary - _root: Union[HttpUrl, DirectoryPath] = PrivateAttr( + _root: Union[RootHttpUrl, DirectoryPath, ZipPath] = PrivateAttr( default_factory=lambda: validation_context_var.get().root ) @property - def root(self) -> Union[HttpUrl, DirectoryPath]: + def root(self) -> Union[RootHttpUrl, DirectoryPath, ZipPath]: return self._root @classmethod diff --git a/bioimageio/spec/_internal/url.py b/bioimageio/spec/_internal/url.py index 2865439a..de998d96 100644 --- a/bioimageio/spec/_internal/url.py +++ b/bioimageio/spec/_internal/url.py @@ -121,7 +121,7 @@ class HttpUrl(RootHttpUrl): _exists: Optional[bool] = None def _after_validator(self): - super()._after_validator() + self = super()._after_validator() context = validation_context_var.get() if ( context.perform_io_checks diff --git a/bioimageio/spec/_internal/validation_context.py b/bioimageio/spec/_internal/validation_context.py index 7195c0b7..43caa206 100644 --- a/bioimageio/spec/_internal/validation_context.py +++ b/bioimageio/spec/_internal/validation_context.py @@ -10,7 +10,7 @@ from pydantic import DirectoryPath from ._settings import settings -from .io_basics import AbsoluteDirectory, FileName, Sha256 +from .io_basics import FileName, Sha256 from .root_url import RootHttpUrl from .warning_levels import WarningLevel @@ -21,7 +21,7 @@ class ValidationContext: init=False, default_factory=list ) - root: Union[RootHttpUrl, AbsoluteDirectory, ZipFile] = Path() + root: Union[RootHttpUrl, DirectoryPath, ZipFile] = Path() """url/directory serving as base to resolve any relative file paths""" warning_level: WarningLevel = 50 diff --git a/tests/test_internal/test_url.py b/tests/test_internal/test_url.py index aecd8f14..73f3027d 100644 --- a/tests/test_internal/test_url.py +++ b/tests/test_internal/test_url.py @@ -2,6 +2,7 @@ import pytest import requests.exceptions +from requests_mock import Mocker as RequestsMocker from bioimageio.spec._internal.validation_context import ValidationContext @@ -32,11 +33,11 @@ def test_httpurl_valid(url: str): ("let's ignore this I guess??", 405), ], ) -def test_httpurl_mock_valid(text: str, status_code: int, requests_mock): +def test_httpurl_mock_valid(text: str, status_code: int, requests_mock: RequestsMocker): from bioimageio.spec._internal.url import HttpUrl url = "https://example.com" - requests_mock.get(url, text=text, status_code=status_code) + _ = requests_mock.get(url, text=text, status_code=status_code) assert HttpUrl(url).exists() @@ -48,12 +49,14 @@ def test_httpurl_mock_valid(text: str, status_code: int, requests_mock): ("just wrong", 199), ], ) -def test_httpurl_mock_invalid(text: str, status_code: int, requests_mock): +def test_httpurl_mock_invalid( + text: str, status_code: int, requests_mock: RequestsMocker +): from bioimageio.spec._internal.url import HttpUrl url = "https://example.com" - requests_mock.head(url, text=text, status_code=status_code) - requests_mock.get(url, text=text, status_code=status_code) + _ = requests_mock.head(url, text=text, status_code=status_code) + _ = requests_mock.get(url, text=text, status_code=status_code) with ValidationContext(perform_io_checks=True): with pytest.raises(ValueError): _ = HttpUrl(url) @@ -68,11 +71,11 @@ def test_httpurl_mock_invalid(text: str, status_code: int, requests_mock): requests.exceptions.InvalidURL, ], ) -def test_httpurl_mock_exc(exc: Type[Exception], requests_mock): +def test_httpurl_mock_exc(exc: Type[Exception], requests_mock: RequestsMocker): from bioimageio.spec._internal.url import HttpUrl url = "https://example.com" - requests_mock.head(url, exc=exc) + _ = requests_mock.head(url, exc=exc) with ValidationContext(perform_io_checks=True): with pytest.raises(ValueError): _ = HttpUrl(url)