-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b7b857c
commit 7e042c7
Showing
5 changed files
with
146 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,28 @@ | ||
from typing import TYPE_CHECKING, Iterable, Sequence | ||
from typing import Iterable, Sequence, TypeVar, overload | ||
|
||
from ome_types.model.ome_2016_06 import Annotation | ||
|
||
from ._base_type import OMEType | ||
|
||
if TYPE_CHECKING: | ||
from ome_types.model.ome_2016_06 import StructuredAnnotations | ||
_T_co = TypeVar("_T_co", covariant=True) # Any type covariant containers. | ||
|
||
|
||
class StructuredAnnotationsMixin(OMEType, Sequence): | ||
def _iter_annotations(self: "StructuredAnnotations") -> Iterable[Annotation]: | ||
class StructuredAnnotationsMixin(OMEType, Sequence[Annotation]): # type: ignore | ||
def _iter_annotations(self) -> Iterable[Annotation]: | ||
for x in self.__fields__.values(): | ||
if issubclass(x.type_, Annotation): | ||
yield from getattr(self, x.name) | ||
else: | ||
breakpoint() | ||
|
||
def __getitem__(self: "StructuredAnnotations", key) -> Annotation: | ||
@overload | ||
def __getitem__(self, index: int) -> Annotation: | ||
... | ||
|
||
@overload | ||
def __getitem__(self, index: slice) -> Sequence[Annotation]: | ||
... | ||
|
||
def __getitem__(self, key: int | slice) -> Annotation | Sequence[Annotation]: | ||
return list(self._iter_annotations())[key] | ||
|
||
def __len__(self) -> int: | ||
return len(list(self._iter_annotations())) | ||
|
||
def append(self: "StructuredAnnotations", value: Annotation) -> None: | ||
raise NotImplementedError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
# SHOULD_FAIL_VALIDATION = {"invalid_xml_annotation", "bad"} | ||
# SHOULD_FAIL_ROUNDTRIP = { | ||
# # Order of elements in StructuredAnnotations and Union are jumbled. | ||
# "timestampannotation-posix-only", | ||
# "transformations-downgrade", | ||
# "invalid_xml_annotation", | ||
# } | ||
# SHOULD_FAIL_ROUNDTRIP_LXML = { | ||
# "folders-simple-taxonomy", | ||
# "folders-larger-taxonomy", | ||
# } | ||
# SKIP_ROUNDTRIP = { | ||
# # These have XMLAnnotations with extra namespaces and mixed content, which | ||
# # the automated round-trip test code doesn't properly verify yet. So even | ||
# # though these files do appear to round-trip correctly when checked by eye, | ||
# # we'll play it safe and skip them until the test is fixed. | ||
# "spim", | ||
# "xmlannotation-body-space", | ||
# "xmlannotation-multi-value", | ||
# "xmlannotation-svg", | ||
# } | ||
|
||
DATA = Path(__file__).parent / "data" | ||
ALL_XML = set(DATA.glob("*.ome.xml")) | ||
INVALID = {DATA / "invalid_xml_annotation.ome.xml", DATA / "bad.ome.xml"} | ||
|
||
|
||
def _true_stem(p: Path) -> str: | ||
return p.name.partition(".")[0] | ||
|
||
|
||
@pytest.fixture(params=sorted(ALL_XML), ids=_true_stem) | ||
def any_xml(request: pytest.FixtureRequest) -> Path: | ||
return request.param | ||
|
||
|
||
@pytest.fixture(params=sorted(ALL_XML - INVALID), ids=_true_stem) | ||
def valid_xml(request: pytest.FixtureRequest) -> Path: | ||
return request.param | ||
|
||
|
||
@pytest.fixture(params=INVALID, ids=_true_stem) | ||
def invalid_xml(request: pytest.FixtureRequest) -> Path: | ||
return request.param |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters