Skip to content

Commit

Permalink
add back autogen test
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 committed Jun 30, 2023
1 parent 4d1b13e commit 522d389
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 18 deletions.
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,11 @@ no_implicit_reexport = true
ignore_missing_imports = true
disallow_untyped_defs = true

[[tool.mypy.overrides]]
module = ['ome_types.model.ome_2016_06.structured_annotations']
# Definition of "__iter__" in base class "BaseModel"
# is incompatible with definition in base class "Sequence"
disable_error_code = "misc"

[tool.coverage.run]
source = ["src/ome_types"]
6 changes: 5 additions & 1 deletion src/ome_autogen/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ def build_model(
_print_gray("Running mypy ...")

mypy = ["mypy", str(package_dir), "--strict"]
subprocess.check_output(mypy) # noqa S

try:
subprocess.check_output(mypy, stderr=subprocess.STDOUT) # noqa S
except subprocess.CalledProcessError as e:
raise RuntimeError(f"mypy errors:\n\n{e.output.decode()}") from e

# print a bold green checkmark
_print_green(f"\u2713 OME python model created at {OUTPUT_PACKAGE}")
Expand Down
2 changes: 1 addition & 1 deletion src/ome_types/_mixins/_structured_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ def __getitem__(self, key: int | slice) -> Annotation | Sequence[Annotation]:
def __len__(self) -> int:
return len(list(self._iter_annotations()))

def __iter__(self) -> Iterator[Annotation]:
def __iter__(self) -> Iterator[Annotation]: # type: ignore[override]
return self._iter_annotations()
13 changes: 7 additions & 6 deletions src/ome_types/model/_color.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
from typing import Any
from typing import Any, Tuple, Union

from pydantic import color
from xsdata.formats.converter import Converter, converter

__all__ = ["Color"]

ColorTuple = Union[Tuple[int, int, int], Tuple[int, int, int, float]]
ColorType = Union[ColorTuple, str, int]


class Color(color.Color):
def __init__(self, val: color.ColorType = -1) -> None:
def __init__(self, val: ColorType = -1) -> None:
try:
val_int = int(val) # type: ignore
val = self._int2tuple(int(val)) # type: ignore
except ValueError:
pass
else:
val = self._int2tuple(val_int)
super().__init__(val)
super().__init__(val) # type: ignore [arg-type]

@classmethod
def _int2tuple(cls, val: int) -> tuple[int, int, int, float]:
Expand Down
23 changes: 13 additions & 10 deletions tests/test_autogen.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@
import sys
from pathlib import Path

import pytest
from _pytest.monkeypatch import MonkeyPatch

ome_autogen = pytest.importorskip("_ome_autogen")
XSD = Path(__file__).parent.parent.parent / "src" / "ome_types" / "ome-2016-06.xsd"
import ome_autogen.main


def test_autogen(tmp_path_factory):
def test_autogen(tmp_path: Path, monkeypatch: MonkeyPatch) -> None:
"""Test that autogen works without raising an exception.
This does *not* actually test the resulting model.
and that mypy has no issues with it.
"""
target_dir = tmp_path_factory.mktemp("_ome_types_test_model")
ome_autogen.convert_schema(url=XSD, target_dir=target_dir)
sys.path.insert(0, str(target_dir.parent))
assert importlib.import_module(target_dir.name)
sys.path.pop(0)
ome_autogen.main.build_model(output_dir=tmp_path, do_formatting=True, do_mypy=True)

monkeypatch.delitem(sys.modules, "ome_types")
monkeypatch.delitem(sys.modules, "ome_types.model")
monkeypatch.delitem(sys.modules, "ome_types.model.ome_2016_06")
monkeypatch.syspath_prepend(str(tmp_path))
mod = importlib.import_module("ome_types.model.ome_2016_06")
assert mod.__file__ and mod.__file__.startswith(str(tmp_path))
assert mod.Channel(color="blue")

0 comments on commit 522d389

Please sign in to comment.