Skip to content

Commit

Permalink
Merge pull request #125 from Deltares/chore/remove_code_smells
Browse files Browse the repository at this point in the history
chore: Processed sonar cloud remarks
  • Loading branch information
Carsopre authored Nov 2, 2023
2 parents c6812d2 + c6c8d52 commit 0fb36d1
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ def is_valid(self) -> bool:

@dataclass
class ConstructionCostsSettings(KoswatConfigProtocol):
cb_damwand: ConstructionFactors = None
damwand_onverankerd: ConstructionFactors = None
damwand_verankerd: ConstructionFactors = None
diepwand: ConstructionFactors = None
kistdam: ConstructionFactors = None
cb_damwand: ConstructionFactors | None = None
damwand_onverankerd: ConstructionFactors | None = None
damwand_verankerd: ConstructionFactors | None = None
diepwand: ConstructionFactors | None = None
kistdam: ConstructionFactors | None = None

def get_construction_factors(
self, construction_type: ConstructionTypeEnum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def build(self) -> KoswatCsvFom:

def _get_total_meters_per_selected_measure(
self,
) -> list[tuple[Type[ReinforcementProfileProtocol], float]]:
) -> dict[ReinforcementProfileProtocol, int]:
# We consider the distance between adjacent locations
# ALWAYS to be of 1 meter.
_sorted_reinforcements = sorted(
Expand Down
2 changes: 1 addition & 1 deletion koswat/dike/surroundings/wrapper/surroundings_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def locations(self) -> list[PointSurroundings]:
def _match_locations(
point1: PointSurroundings, point2: PointSurroundings
) -> list[float]:
if not point1.location == point2.location:
if point1.location != point2.location:
logging.warning(
f"Mismatching railway polderside location {point2.location}"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self) -> None:

def _get_surroundings_from_fom(
self, csv_fom: KoswatTrajectSurroundingsWrapperCsvFom
) -> KoswatSurroundingsPolderside:
) -> KoswatSurroundingsPolderside | None:
_builder = KoswatSurroundingsPoldersideBuilder()
_builder.koswat_shp_fom = self.trajects_fom
_builder.koswat_csv_fom = csv_fom
Expand Down
4 changes: 2 additions & 2 deletions koswat/plots/dike/koswat_layer_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ def _get_xy_line_coords(
koswat_geometry: LineString | MultiLineString,
) -> tuple[list[float], list[float]]:
if isinstance(koswat_geometry, LineString):
return koswat_geometry.coords.xy
return tuple(map(list, koswat_geometry.coords.xy))

return list(
return tuple(
map(concatenate, zip(*map(lambda x: x.coords.xy, koswat_geometry.geoms)))
)

Expand Down
1 change: 1 addition & 0 deletions koswat/strategies/strategy_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

class StrategyProtocol(Protocol):
def apply_strategy(
self,
strategy_input: StrategyInput,
) -> list[StrategyLocationReinforcement]:
"""
Expand Down
34 changes: 34 additions & 0 deletions tests/plots/test_koswat_layer_plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pytest
from numpy import testing
from shapely.geometry import LineString, MultiLineString

from koswat.plots.dike.koswat_layer_plot import KoswatLayerPlot

_coordinates = [(0, 0), (0, 2), (2, 2), (2, 0)]


class TestKoswatLayerPlot:
@pytest.mark.parametrize(
"valid_geometry",
[
pytest.param(LineString(_coordinates), id="From LineString"),
pytest.param(
MultiLineString([_coordinates[:2], _coordinates[2:]]),
id="From MultiLineString",
),
],
)
def test_get_xy_line_coords_from_valid_geometry_returns_tuple(
self, valid_geometry: LineString | MultiLineString
):
# 1. Define test data.
assert valid_geometry.is_valid
_expected_x_coords, _expected_y_coords = zip(*_coordinates)

# 2. Run test.
_x_y_coordinates = KoswatLayerPlot._get_xy_line_coords(valid_geometry)

# 3. Verify expectations.
assert isinstance(_x_y_coordinates, tuple)
testing.assert_array_equal(_x_y_coordinates[0], _expected_x_coords)
testing.assert_array_equal(_x_y_coordinates[1], _expected_y_coords)

0 comments on commit 0fb36d1

Please sign in to comment.