From 1c0320ad6a5b3da8f98eb79abe497929ba39291d Mon Sep 17 00:00:00 2001 From: Jeremy Muhlich Date: Tue, 21 Jul 2020 12:40:25 -0400 Subject: [PATCH 1/2] Add special-case hacks for BinData class In the schema BinData is an extension of string, but modeling this in python as a subclass of str with extra constructor args is not feasible. Instead this change moves the string content to a `value` attribute which aligns with how our to_dict converter presents element text content. Fixes #9 --- src/ome_autogen.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/ome_autogen.py b/src/ome_autogen.py index 4dd97c7b..7420e3b2 100644 --- a/src/ome_autogen.py +++ b/src/ome_autogen.py @@ -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 @@ -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" @@ -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() From 34d232eed78068567a7a263da6f5f02e97e86339 Mon Sep 17 00:00:00 2001 From: Jeremy Muhlich Date: Tue, 21 Jul 2020 13:10:29 -0400 Subject: [PATCH 2/2] Remove xfail from many sample xml files and tidy * Now that BinData parses properly we can remove the xfail marker from about half of the sample ome-xml files * Refactor filename stem extraction * Invert SHOULD_PASS to SHOULD_FAIL for easier updating * Remove +x mode bit from sample xml files --- testing/data/ROI.ome.xml | 0 testing/data/commentannotation.ome.xml | 0 testing/data/filter.ome.xml | 0 testing/data/folders-larger-taxonomy.ome.xml | 0 testing/data/folders-simple-taxonomy.ome.xml | 0 testing/data/hcs.ome.xml | 0 .../data/instrument-units-alternate.ome.xml | 0 testing/data/instrument-units-default.ome.xml | 0 testing/data/instrument.ome.xml | 0 testing/data/mapannotation.ome.xml | 0 testing/data/metadata-only.ome.xml | 0 testing/data/minimum-specification.ome.xml | 0 .../data/multi-channel-time-series.ome.xml | 0 ...multi-channel-z-series-time-series.ome.xml | 0 testing/data/multi-channel-z-series.ome.xml | 0 testing/data/multi-channel.ome.xml | 0 testing/data/no-date.ome.xml | 0 .../one-screen-one-plate-four-wells.ome.xml | 0 testing/data/single-image.ome.xml | 0 testing/data/spim.ome.xml | 0 testing/data/tagannotation.ome.xml | 0 testing/data/time-series.ome.xml | 0 .../timestampannotation-posix-only.ome.xml | 0 testing/data/timestampannotation.ome.xml | 0 .../data/transformations-downgrade.ome.xml | 0 testing/data/transformations-upgrade.ome.xml | 0 .../two-screens-two-plates-four-wells.ome.xml | 0 testing/data/xmlannotation-body-space.ome.xml | 0 .../data/xmlannotation-multi-value.ome.xml | 0 testing/data/xmlannotation-svg.ome.xml | 0 testing/data/z-series-time-series.ome.xml | 0 testing/data/z-series.ome.xml | 0 testing/test_autogen.py | 34 +++++++++++++++---- 33 files changed, 28 insertions(+), 6 deletions(-) mode change 100755 => 100644 testing/data/ROI.ome.xml mode change 100755 => 100644 testing/data/commentannotation.ome.xml mode change 100755 => 100644 testing/data/filter.ome.xml mode change 100755 => 100644 testing/data/folders-larger-taxonomy.ome.xml mode change 100755 => 100644 testing/data/folders-simple-taxonomy.ome.xml mode change 100755 => 100644 testing/data/hcs.ome.xml mode change 100755 => 100644 testing/data/instrument-units-alternate.ome.xml mode change 100755 => 100644 testing/data/instrument-units-default.ome.xml mode change 100755 => 100644 testing/data/instrument.ome.xml mode change 100755 => 100644 testing/data/mapannotation.ome.xml mode change 100755 => 100644 testing/data/metadata-only.ome.xml mode change 100755 => 100644 testing/data/minimum-specification.ome.xml mode change 100755 => 100644 testing/data/multi-channel-time-series.ome.xml mode change 100755 => 100644 testing/data/multi-channel-z-series-time-series.ome.xml mode change 100755 => 100644 testing/data/multi-channel-z-series.ome.xml mode change 100755 => 100644 testing/data/multi-channel.ome.xml mode change 100755 => 100644 testing/data/no-date.ome.xml mode change 100755 => 100644 testing/data/one-screen-one-plate-four-wells.ome.xml mode change 100755 => 100644 testing/data/single-image.ome.xml mode change 100755 => 100644 testing/data/spim.ome.xml mode change 100755 => 100644 testing/data/tagannotation.ome.xml mode change 100755 => 100644 testing/data/time-series.ome.xml mode change 100755 => 100644 testing/data/timestampannotation-posix-only.ome.xml mode change 100755 => 100644 testing/data/timestampannotation.ome.xml mode change 100755 => 100644 testing/data/transformations-downgrade.ome.xml mode change 100755 => 100644 testing/data/transformations-upgrade.ome.xml mode change 100755 => 100644 testing/data/two-screens-two-plates-four-wells.ome.xml mode change 100755 => 100644 testing/data/xmlannotation-body-space.ome.xml mode change 100755 => 100644 testing/data/xmlannotation-multi-value.ome.xml mode change 100755 => 100644 testing/data/xmlannotation-svg.ome.xml mode change 100755 => 100644 testing/data/z-series-time-series.ome.xml mode change 100755 => 100644 testing/data/z-series.ome.xml diff --git a/testing/data/ROI.ome.xml b/testing/data/ROI.ome.xml old mode 100755 new mode 100644 diff --git a/testing/data/commentannotation.ome.xml b/testing/data/commentannotation.ome.xml old mode 100755 new mode 100644 diff --git a/testing/data/filter.ome.xml b/testing/data/filter.ome.xml old mode 100755 new mode 100644 diff --git a/testing/data/folders-larger-taxonomy.ome.xml b/testing/data/folders-larger-taxonomy.ome.xml old mode 100755 new mode 100644 diff --git a/testing/data/folders-simple-taxonomy.ome.xml b/testing/data/folders-simple-taxonomy.ome.xml old mode 100755 new mode 100644 diff --git a/testing/data/hcs.ome.xml b/testing/data/hcs.ome.xml old mode 100755 new mode 100644 diff --git a/testing/data/instrument-units-alternate.ome.xml b/testing/data/instrument-units-alternate.ome.xml old mode 100755 new mode 100644 diff --git a/testing/data/instrument-units-default.ome.xml b/testing/data/instrument-units-default.ome.xml old mode 100755 new mode 100644 diff --git a/testing/data/instrument.ome.xml b/testing/data/instrument.ome.xml old mode 100755 new mode 100644 diff --git a/testing/data/mapannotation.ome.xml b/testing/data/mapannotation.ome.xml old mode 100755 new mode 100644 diff --git a/testing/data/metadata-only.ome.xml b/testing/data/metadata-only.ome.xml old mode 100755 new mode 100644 diff --git a/testing/data/minimum-specification.ome.xml b/testing/data/minimum-specification.ome.xml old mode 100755 new mode 100644 diff --git a/testing/data/multi-channel-time-series.ome.xml b/testing/data/multi-channel-time-series.ome.xml old mode 100755 new mode 100644 diff --git a/testing/data/multi-channel-z-series-time-series.ome.xml b/testing/data/multi-channel-z-series-time-series.ome.xml old mode 100755 new mode 100644 diff --git a/testing/data/multi-channel-z-series.ome.xml b/testing/data/multi-channel-z-series.ome.xml old mode 100755 new mode 100644 diff --git a/testing/data/multi-channel.ome.xml b/testing/data/multi-channel.ome.xml old mode 100755 new mode 100644 diff --git a/testing/data/no-date.ome.xml b/testing/data/no-date.ome.xml old mode 100755 new mode 100644 diff --git a/testing/data/one-screen-one-plate-four-wells.ome.xml b/testing/data/one-screen-one-plate-four-wells.ome.xml old mode 100755 new mode 100644 diff --git a/testing/data/single-image.ome.xml b/testing/data/single-image.ome.xml old mode 100755 new mode 100644 diff --git a/testing/data/spim.ome.xml b/testing/data/spim.ome.xml old mode 100755 new mode 100644 diff --git a/testing/data/tagannotation.ome.xml b/testing/data/tagannotation.ome.xml old mode 100755 new mode 100644 diff --git a/testing/data/time-series.ome.xml b/testing/data/time-series.ome.xml old mode 100755 new mode 100644 diff --git a/testing/data/timestampannotation-posix-only.ome.xml b/testing/data/timestampannotation-posix-only.ome.xml old mode 100755 new mode 100644 diff --git a/testing/data/timestampannotation.ome.xml b/testing/data/timestampannotation.ome.xml old mode 100755 new mode 100644 diff --git a/testing/data/transformations-downgrade.ome.xml b/testing/data/transformations-downgrade.ome.xml old mode 100755 new mode 100644 diff --git a/testing/data/transformations-upgrade.ome.xml b/testing/data/transformations-upgrade.ome.xml old mode 100755 new mode 100644 diff --git a/testing/data/two-screens-two-plates-four-wells.ome.xml b/testing/data/two-screens-two-plates-four-wells.ome.xml old mode 100755 new mode 100644 diff --git a/testing/data/xmlannotation-body-space.ome.xml b/testing/data/xmlannotation-body-space.ome.xml old mode 100755 new mode 100644 diff --git a/testing/data/xmlannotation-multi-value.ome.xml b/testing/data/xmlannotation-multi-value.ome.xml old mode 100755 new mode 100644 diff --git a/testing/data/xmlannotation-svg.ome.xml b/testing/data/xmlannotation-svg.ome.xml old mode 100755 new mode 100644 diff --git a/testing/data/z-series-time-series.ome.xml b/testing/data/z-series-time-series.ome.xml old mode 100755 new mode 100644 diff --git a/testing/data/z-series.ome.xml b/testing/data/z-series.ome.xml old mode 100755 new mode 100644 diff --git a/testing/test_autogen.py b/testing/test_autogen.py index b6c291b4..86e5e125 100644 --- a/testing/test_autogen.py +++ b/testing/test_autogen.py @@ -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): @@ -35,16 +54,19 @@ def mark_xfail(fname): ), ) +def true_stem(p): + 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: