Skip to content

Commit

Permalink
refactor assert
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzailpalnak committed Sep 22, 2020
1 parent a4e108d commit b04c3b1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 21 deletions.
12 changes: 8 additions & 4 deletions kaizen/map/matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ def add(
:param trace_information: information of the trace point for which the candidate was obtained
:return:
"""
assert all(
v is not None for v in [x, y, distance, road_information, trace_information]
), "Expected ['x', 'y', 'candidate_id', 'distance', 'road_information', 'trace_information'] to be not None"
assert None not in {
x,
y,
distance,
road_information,
trace_information,
}, "Expected ['x', 'y', 'candidate_id', 'distance', 'road_information', 'trace_information'] to be not None"

assert type(distance) is float, (
"Expected type to be 'float'," "got %s",
Expand All @@ -71,7 +75,7 @@ def add(

assert hasattr(road_information.property, "u") and hasattr(
road_information.property, "v"
), "Expected road to have start node 'u' and end node 'v'" "for every edge"
), ("Expected road to have start node 'u' and end node 'v'" "for every edge")

if isinstance(trace_information, dict):
trace_information = SimpleNamespace(**trace_information)
Expand Down
23 changes: 15 additions & 8 deletions kaizen/map/navigator.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,17 @@ def path_finder_from_traces(
filter_trace: bool = True,
area_simplify: float = 0,
):
assert all(
v is not None
for v in [grid, traces, search_space_threshold, filter_trace, area_simplify]
), (
assert None not in {
grid,
traces,
search_space_threshold,
filter_trace,
area_simplify,
}, (
"Expected ['grid', 'trace', 'search_space_threshold', 'filter_trace', 'area_simplify'']"
"to be not NONE"
)

assert isinstance(grid, Grid), (
"Expected 'grid' to be instance of 'Grid'" "got %s",
(type(grid),),
Expand Down Expand Up @@ -288,10 +292,13 @@ def path_finder_from_trace(
filter_trace: bool = True,
area_simplify: float = 0,
):
assert all(
v is not None
for v in [grid, trace, search_space_threshold, filter_trace, area_simplify]
), (
assert None not in {
grid,
trace,
search_space_threshold,
filter_trace,
area_simplify,
}, (
"Expected ['grid', 'trace', 'search_space_threshold', 'filter_trace', 'area_simplify'']"
"to be not NONE"
)
Expand Down
12 changes: 6 additions & 6 deletions kaizen/map/road.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from collections import OrderedDict, namedtuple
from types import SimpleNamespace

import geopandas
import networkx as nx
import rtree
from geopandas import GeoDataFrame
Expand Down Expand Up @@ -32,11 +31,12 @@ def add(
feature_geometry: dict,
weight: float,
):

assert all(
v is not None
for v in [feature_id, feature_property, feature_geometry, weight]
), "Expected ['feature_id', 'feature_property', 'feature_geometry', 'weight'] to be not None"
assert None not in {
feature_id,
feature_property,
feature_geometry,
weight,
}, "Expected ['feature_id', 'feature_property', 'feature_geometry', 'weight'] to be not None"

assert type(feature_id) is int, (
"Expected 'feature_id' type to be 'int'," "got %s",
Expand Down
10 changes: 7 additions & 3 deletions kaizen/map/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ def add(self, x, y, trace_point_id, trace_id, **kwargs):
:param kwargs:
:return:
"""
assert all(
v is not None for v in [x, y, trace_point_id, trace_id]
), "Expected ['x', 'y', 'trace_point_id', 'trace_id'] to be not None"
assert None not in {
x,
y,
trace_point_id,
trace_id,
}, "Expected ['x', 'y', 'trace_point_id', 'trace_id'] to be not None"

self[trace_id].append(
TracePoint(x, y, trace_point_id, trace_id, SimpleNamespace(**kwargs))
)
Expand Down

0 comments on commit b04c3b1

Please sign in to comment.