Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: to_etree_element #201

Merged
merged 6 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add test
  • Loading branch information
tlambert03 committed Jul 12, 2023
commit 37c67ac38efd05525edd82e8b0515b119712c103
13 changes: 13 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
ALL_XML = set(DATA.glob("*.ome.xml"))
INVALID = {DATA / "invalid_xml_annotation.ome.xml", DATA / "bad.ome.xml"}
OLD_SCHEMA = {DATA / "seq0000xy01c1.ome.xml", DATA / "2008_instrument.ome.xml"}
WITH_XML_ANNOTATIONS = {
DATA / "ome_ns.ome.xml",
DATA / "OverViewScan.ome.xml",
DATA / "spim.ome.xml",
DATA / "xmlannotation-svg.ome.xml",
DATA / "xmlannotation-multi-value.ome.xml",
DATA / "xmlannotation-body-space.ome.xml",
}


def _true_stem(p: Path) -> str:
Expand All @@ -39,6 +47,11 @@ def invalid_xml(request: pytest.FixtureRequest) -> Path:
return request.param


@pytest.fixture(params=sorted(WITH_XML_ANNOTATIONS), ids=_true_stem)
def with_xml_annotations(request: pytest.FixtureRequest) -> Path:
return request.param


@pytest.fixture
def single_xml() -> Path:
return DATA / "example.ome.xml"
Expand Down
16 changes: 16 additions & 0 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,19 @@ def test_numpy_pixel_types() -> None:

for m in model.PixelType:
numpy.dtype(m.numpy_dtype)


def test_xml_annotations_to_etree(with_xml_annotations: Path) -> None:
from xsdata_pydantic_basemodel.compat import AnyElement

try:
from lxml.etree import _Element as Elem
except ImportError:
from xml.etree.ElementTree import Element as Elem # type: ignore

ome = from_xml(with_xml_annotations)
for anno in ome.structured_annotations:
if isinstance(anno, model.XMLAnnotation):
for elem in anno.value.any_elements:
assert isinstance(elem, AnyElement)
assert isinstance(elem.to_etree_element(), Elem)