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

Improve model for BinData #11

Merged
merged 2 commits into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 9 additions & 2 deletions src/ome_autogen.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ def local_import(item_type):

def make_dataclass(component) -> List[str]:
lines = ["from pydantic.dataclasses import dataclass", ""]
if isinstance(component, XsdType):
# FIXME: Refactor to remove BinData special-case.
if component.local_name == "BinData":
base_type = None
elif isinstance(component, XsdType):
base_type = component.base_type
else:
base_type = component.type.base_type
Expand Down Expand Up @@ -105,6 +108,9 @@ def make_dataclass(component) -> List[str]:
lines += ["_no_default = object()", ""]

lines += ["@dataclass", f"class {component.local_name}{base_name}:"]
# FIXME: Refactor to remove BinData special-case.
if component.local_name == "BinData":
lines.append(" value: str")
lines += members.lines(
indent=1,
force_defaults=" = _no_default # type: ignore"
Expand Down Expand Up @@ -497,7 +503,8 @@ def _abstract_class(self) -> List[str]:
return lines

def lines(self) -> str:
if not self.is_complex:
# FIXME: Refactor to remove BinData special-case.
if not self.is_complex and self.elem.local_name != "BinData":
lines = self._simple_class()
elif self.elem.abstract:
lines = self._abstract_class()
Expand Down
Empty file modified testing/data/ROI.ome.xml
100755 → 100644
Empty file.
Empty file modified testing/data/commentannotation.ome.xml
100755 → 100644
Empty file.
Empty file modified testing/data/filter.ome.xml
100755 → 100644
Empty file.
Empty file modified testing/data/folders-larger-taxonomy.ome.xml
100755 → 100644
Empty file.
Empty file modified testing/data/folders-simple-taxonomy.ome.xml
100755 → 100644
Empty file.
Empty file modified testing/data/hcs.ome.xml
100755 → 100644
Empty file.
Empty file modified testing/data/instrument-units-alternate.ome.xml
100755 → 100644
Empty file.
Empty file modified testing/data/instrument-units-default.ome.xml
100755 → 100644
Empty file.
Empty file modified testing/data/instrument.ome.xml
100755 → 100644
Empty file.
Empty file modified testing/data/mapannotation.ome.xml
100755 → 100644
Empty file.
Empty file modified testing/data/metadata-only.ome.xml
100755 → 100644
Empty file.
Empty file modified testing/data/minimum-specification.ome.xml
100755 → 100644
Empty file.
Empty file modified testing/data/multi-channel-time-series.ome.xml
100755 → 100644
Empty file.
Empty file modified testing/data/multi-channel-z-series-time-series.ome.xml
100755 → 100644
Empty file.
Empty file modified testing/data/multi-channel-z-series.ome.xml
100755 → 100644
Empty file.
Empty file modified testing/data/multi-channel.ome.xml
100755 → 100644
Empty file.
Empty file modified testing/data/no-date.ome.xml
100755 → 100644
Empty file.
Empty file modified testing/data/one-screen-one-plate-four-wells.ome.xml
100755 → 100644
Empty file.
Empty file modified testing/data/single-image.ome.xml
100755 → 100644
Empty file.
Empty file modified testing/data/spim.ome.xml
100755 → 100644
Empty file.
Empty file modified testing/data/tagannotation.ome.xml
100755 → 100644
Empty file.
Empty file modified testing/data/time-series.ome.xml
100755 → 100644
Empty file.
Empty file modified testing/data/timestampannotation-posix-only.ome.xml
100755 → 100644
Empty file.
Empty file modified testing/data/timestampannotation.ome.xml
100755 → 100644
Empty file.
Empty file modified testing/data/transformations-downgrade.ome.xml
100755 → 100644
Empty file.
Empty file modified testing/data/transformations-upgrade.ome.xml
100755 → 100644
Empty file.
Empty file modified testing/data/two-screens-two-plates-four-wells.ome.xml
100755 → 100644
Empty file.
Empty file modified testing/data/xmlannotation-body-space.ome.xml
100755 → 100644
Empty file.
Empty file modified testing/data/xmlannotation-multi-value.ome.xml
100755 → 100644
Empty file.
Empty file modified testing/data/xmlannotation-svg.ome.xml
100755 → 100644
Empty file.
Empty file modified testing/data/z-series-time-series.ome.xml
100755 → 100644
Empty file.
Empty file modified testing/data/z-series.ome.xml
100755 → 100644
Empty file.
34 changes: 28 additions & 6 deletions testing/test_autogen.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,27 @@ def model(tmp_path_factory):
return importlib.import_module(target_dir.name)


SHOULD_PASS = {"example.ome", "small.ome"}
SHOULD_RAISE = {"bad.ome"}
SHOULD_FAIL = {
"ROI",
"commentannotation",
"filter",
"hcs",
"instrument",
"instrument-units-alternate",
"instrument-units-default",
"mapannotation",
"metadata-only",
"spim",
"tagannotation",
"timestampannotation",
"timestampannotation-posix-only",
"transformations-downgrade",
"transformations-upgrade",
"xmlannotation-body-space",
"xmlannotation-multi-value",
"xmlannotation-svg",
}
SHOULD_RAISE = {"bad"}


def mark_xfail(fname):
Expand All @@ -35,16 +54,19 @@ def mark_xfail(fname):
),
)

def true_stem(p):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

return p.name.partition(".")[0]


params = [
f if f.stem in SHOULD_PASS.union(SHOULD_RAISE) else mark_xfail(f)
for f in TESTING_DIR.glob("data/*.xml")
mark_xfail(f) if true_stem(f) in SHOULD_FAIL else f
for f in TESTING_DIR.glob("data/*.ome.xml")
]


@pytest.mark.parametrize("xml", params, ids=lambda x: x.stem)
@pytest.mark.parametrize("xml", params, ids=true_stem)
def test_convert_schema(model, xml):
if xml.stem in SHOULD_RAISE:
if true_stem(xml) in SHOULD_RAISE:
with pytest.raises(XMLSchemaValidationError):
assert from_xml(xml, model.OME)
else:
Expand Down