Skip to content

Commit

Permalink
CodeCov and SonarQube recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
willGraham01 committed Jan 31, 2025
1 parent 62aacee commit 8aa6020
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
16 changes: 7 additions & 9 deletions movement/roi/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@ class BaseRegionOfInterest:
instantiated, however its primary purpose is to reduce code duplication.
"""

__default_name: str = "Un-named"
__supported_type: TypeAlias = SupportedGeometry
__default_name: str = "Un-named region"

_name: str | None
_shapely_geometry: __supported_type
_shapely_geometry: SupportedGeometry

@property
def coords(self) -> CoordinateSequence:
Expand Down Expand Up @@ -85,7 +84,7 @@ def name(self) -> str:
return self._name if self._name else self.__default_name

@property
def region(self) -> __supported_type:
def region(self) -> SupportedGeometry:
"""``shapely.Geometry`` representation of the region."""
return self._shapely_geometry

Expand Down Expand Up @@ -139,15 +138,14 @@ def __init__(
ValueError,
"Cannot create a loop from a single line segment.",
)
self._shapely_geometry = (
shapely.Polygon(shell=points, holes=holes)
if dimensions == 2
else (
if dimensions == 2:
self._shapely_geometry = shapely.Polygon(shell=points, holes=holes)
else:
self._shapely_geometry = (
shapely.LinearRing(coordinates=points)
if closed
else shapely.LineString(coordinates=points)
)
)

def __repr__(self) -> str: # noqa: D105
return str(self)
Expand Down
7 changes: 1 addition & 6 deletions movement/roi/line.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""1-dimensional lines of interest."""

from typing import TypeAlias

from movement.roi.base import BaseRegionOfInterest, LineLike, PointLikeList
from movement.roi.base import BaseRegionOfInterest, PointLikeList


class LineOfInterest(BaseRegionOfInterest):
Expand All @@ -22,9 +20,6 @@ class LineOfInterest(BaseRegionOfInterest):
pairs of points, to form the LoI that is to be studied.
"""

__default_name: str = "Un-named line"
__supported_type: TypeAlias = LineLike

def __init__(
self,
points: PointLikeList,
Expand Down
6 changes: 1 addition & 5 deletions movement/roi/polygon.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"""2-dimensional regions of interest."""

from collections.abc import Sequence
from typing import TypeAlias

from movement.roi.base import BaseRegionOfInterest, PointLikeList, RegionLike
from movement.roi.base import BaseRegionOfInterest, PointLikeList
from movement.roi.line import LineOfInterest


Expand All @@ -23,9 +22,6 @@ class PolygonOfInterest(BaseRegionOfInterest):
(closed) ``LineOfInterest``, and may be treated accordingly.
"""

__default_name: str = "Un-named polygon"
__supported_type: TypeAlias = RegionLike

def __init__(
self,
boundary: PointLikeList,
Expand Down
19 changes: 18 additions & 1 deletion tests/test_unit/test_roi/test_instantiate.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
pytest.param(
"unit_square_pts",
{"dimensions": 2, "closed": False},
{"is_closed": True, "dimensions": 2, "name": "Un-named"},
{"is_closed": True, "dimensions": 2, "name": "Un-named region"},
id="Polygon, closed is ignored",
),
pytest.param(
Expand Down Expand Up @@ -59,6 +59,15 @@
ValueError("Cannot create a loop from a single line segment."),
id="Cannot close single line segment.",
),
pytest.param(
"unit_square_pts",
{"dimensions": 3, "closed": False},
ValueError(
"Only regions of interest of dimension 1 or 2 "
"are supported (requested 3)"
),
id="Bad dimensionality",
),
],
)
def test_creation(
Expand All @@ -82,10 +91,18 @@ def test_creation(
expected_closure = kwargs_for_creation.pop("closed", False)
if expected_dim == 2:
assert isinstance(roi.region, shapely.Polygon)
assert len(roi.coords) == len(input_pts) + 1
string_should_contain = "-gon"
elif expected_closure:
assert isinstance(roi.region, shapely.LinearRing)
assert len(roi.coords) == len(input_pts) + 1
string_should_contain = "line segment(s)"
else:
assert isinstance(roi.region, shapely.LineString)
assert len(roi.coords) == len(input_pts)
string_should_contain = "line segment(s)"
assert string_should_contain in roi.__str__()
assert string_should_contain in roi.__repr__()

for attribute_name, expected_value in expected_results.items():
assert getattr(roi, attribute_name) == expected_value

0 comments on commit 8aa6020

Please sign in to comment.