Skip to content

Commit

Permalink
ci: coverage changes (#195)
Browse files Browse the repository at this point in the history
* ci: coverage changes

* import or skip lxml

* add badge
  • Loading branch information
tlambert03 authored Jul 8, 2023
1 parent 151fef5 commit a329034
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 13 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
Version](https://img.shields.io/pypi/pyversions/ome-types.svg)](https://python.org)
[![Tests](https://github.com/tlambert03/ome-types/workflows/tests/badge.svg)](https://github.com/tlambert03/ome-types/actions)
[![Docs](https://readthedocs.org/projects/ome-types/badge/?version=latest)](https://ome-types.readthedocs.io/en/latest/?badge=latest)
<!-- [![conda-forge](https://img.shields.io/conda/vn/conda-forge/ome-types)](https://anaconda.org/conda-forge/ome-types) -->
[![codecov](https://codecov.io/gh/tlambert03/ome-types/branch/master/graph/badge.svg?token=GocY9y8A32)](https://codecov.io/gh/tlambert03/ome-types)


## A pure-python implementation of the OME data model

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ exclude_lines = [

[tool.coverage.run]
source = ["src/ome_types", "src/ome_autogen"]
omit = ["src/ome_types/_autogenerated/*"]


# Entry points -- REMOVE ONCE XSDATA-PYDANTIC-BASEMODEL IS SEPARATE
Expand Down
1 change: 1 addition & 0 deletions src/ome_autogen/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pragma: no cover
from ome_autogen.main import build_model

build_model()
2 changes: 1 addition & 1 deletion src/ome_autogen/_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def class_params(self, obj: Class) -> Iterator[tuple[str, str, str]]:
# to fixup the numpy docstring format.
# https://github.com/tefra/xsdata/issues/818

if sys.version_info < (3, 8):
if sys.version_info < (3, 8): # pragma: no cover
# i don't know why, but in python 3.7, it's not picking up our
# template ... so this method yields too many values to unpack
# xsdata/formats/dataclass/templates/docstrings.numpy.jinja2", line 6
Expand Down
8 changes: 3 additions & 5 deletions src/ome_autogen/_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

# we don't need RenameDuplicateAttributes because we inject
# proper enum names in our _generator.py
UNWANTED_HANDLERS = [(RenameDuplicateAttributes, None)]
UNWANTED_HANDLERS = [RenameDuplicateAttributes]


def display_help(self: Attribute) -> str | None:
Expand Down Expand Up @@ -63,12 +63,10 @@ def analyze_classes(self, classes: list[Class]) -> list[Class]:
container = ClassContainer(config=self.config)

for handlers in container.processors.values():
for idx, h in enumerate(list(handlers)):
for unwanted, wanted in UNWANTED_HANDLERS:
for h in list(handlers):
for unwanted in UNWANTED_HANDLERS:
if isinstance(h, unwanted):
handlers.remove(h)
if wanted is not None:
handlers.insert(idx, wanted(container))

container.extend(classes)

Expand Down
2 changes: 1 addition & 1 deletion src/ome_autogen/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _check_mypy(package_dir: str) -> None:
mypy = ["mypy", package_dir, "--strict"]
try:
subprocess.check_output(mypy, stderr=subprocess.STDOUT) # noqa S
except subprocess.CalledProcessError as e:
except subprocess.CalledProcessError as e: # pragma: no cover
raise RuntimeError(f"mypy errors:\n\n{e.output.decode()}") from e


Expand Down
2 changes: 1 addition & 1 deletion src/ome_types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

try:
__version__ = version("ome-types")
except PackageNotFoundError:
except PackageNotFoundError: # pragma: no cover
__version__ = "unknown"

from ome_types import model
Expand Down
2 changes: 1 addition & 1 deletion src/ome_types/_mixins/_base_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def _quantity_property(field_name: str) -> property:

def quantity(self: Any) -> Optional["pint.Quantity"]:
value = getattr(self, field_name)
if value is None:
if value is None: # pragma: no cover
return None

unit = cast("Enum", getattr(self, _UNIT_FIELD.format(field_name)))
Expand Down
2 changes: 1 addition & 1 deletion src/ome_types/_mixins/_bin_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def _v(cls, values: dict) -> Dict[str, Any]:
# seems like it could be done in a default_factory, but that would
# require more modification of xsdata I think
if "value" not in values:
if values.get("length") != 0:
if values.get("length") != 0: # pragma: no cover
warnings.warn(
"BinData length is non-zero but value is missing", stacklevel=2
)
Expand Down
2 changes: 1 addition & 1 deletion src/ome_types/_mixins/_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def validate_id(cls: type[BaseModel], value: int | str) -> Any:
msg = f"Casting invalid {id_name}ID {value!r} to {newname!r}"
warnings.warn(msg, stacklevel=2)
return newname
elif not isinstance(value, int):
elif not isinstance(value, int): # pragma: no cover
raise ValueError(f"Invalid ID value: {value!r}, {type(value)}")

# update the counter to be at least this value
Expand Down
1 change: 1 addition & 0 deletions src/ome_types/_mixins/_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
class InstrumentMixin:
@property
def light_source_group(self) -> List["LightSource"]:
# here for backwards compatibility
slf = cast("Instrument", self)
return [
*slf.arcs,
Expand Down
2 changes: 1 addition & 1 deletion src/ome_types/model/_shape_union.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _validate_root(cls, v: ShapeType) -> ShapeType:
for cls_ in _ShapeCls:
with suppress(ValidationError):
return cls_(**v)
raise ValueError(f"Invalid shape: {v}")
raise ValueError(f"Invalid shape: {v}") # pragma: no cover

def __repr__(self) -> str:
return f"{self.__class__.__name__}({self.__root__!r})"
Expand Down
7 changes: 7 additions & 0 deletions tests/test_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
if TYPE_CHECKING:
import xmlschema

DATA = Path(__file__).parent / "data"
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
Expand Down Expand Up @@ -154,3 +155,9 @@ def _sort_elements(element: ET.Element, recursive: bool = True) -> None:
# Recursively sort child elements for each subelement
for child in element:
_sort_elements(child)


def test_canonicalize() -> None:
pytest.importorskip("lxml")
ome = from_xml(DATA / "example.ome.xml", validate=True)
_ = to_xml(ome, validate=True, canonicalize=True)

0 comments on commit a329034

Please sign in to comment.