Skip to content

Commit f166de2

Browse files
committed
Adding unit tests for get_lane_impacts
1 parent dda3982 commit f166de2

File tree

2 files changed

+130
-4
lines changed

2 files changed

+130
-4
lines changed

tests/raw_to_standard/planned_events_test.py

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,134 @@ def test_get_lanes_list_2():
224224
)
225225

226226

227+
def test_get_lane_impacts_santa_fe():
228+
lane_impacts = [
229+
{
230+
"direction": "north",
231+
"laneCount": 2,
232+
"laneClosures": "6000",
233+
"closedLaneTypes": ["left lane", "right lane"],
234+
},
235+
{
236+
"direction": "south",
237+
"laneCount": 2,
238+
"laneClosures": "0",
239+
"closedLaneTypes": [],
240+
},
241+
]
242+
direction = "north"
243+
has_alternating_traffic = False
244+
expected = [
245+
{"order": 1, "type": "general", "status": "closed"},
246+
{"order": 2, "type": "general", "status": "closed"},
247+
]
248+
actual = planned_events.get_lane_impacts(
249+
lane_impacts, direction, has_alternating_traffic
250+
)
251+
assert actual == expected
252+
253+
direction = "south"
254+
expected = [
255+
{"order": 1, "type": "general", "status": "open"},
256+
{"order": 2, "type": "general", "status": "open"},
257+
]
258+
actual = planned_events.get_lane_impacts(
259+
lane_impacts, direction, has_alternating_traffic
260+
)
261+
assert actual == expected
262+
263+
# Alternating traffic
264+
has_alternating_traffic = True
265+
266+
direction = "north"
267+
expected = [
268+
{"order": 1, "type": "general", "status": "alternating-flow"},
269+
{"order": 2, "type": "general", "status": "closed"},
270+
]
271+
actual = planned_events.get_lane_impacts(
272+
lane_impacts, direction, has_alternating_traffic
273+
)
274+
assert actual == expected
275+
276+
direction = "south"
277+
expected = [
278+
{"order": 1, "type": "general", "status": "alternating-flow"},
279+
{"order": 2, "type": "general", "status": "closed"},
280+
]
281+
actual = planned_events.get_lane_impacts(
282+
lane_impacts, direction, has_alternating_traffic
283+
)
284+
assert actual == expected
285+
286+
287+
def test_get_lane_impacts_el_paso():
288+
lane_impacts = [
289+
{
290+
"direction": "north",
291+
"laneCount": 4,
292+
"laneClosures": "800",
293+
"closedLaneTypes": ["right lane"],
294+
},
295+
{
296+
"direction": "south",
297+
"laneCount": 4,
298+
"laneClosures": "800",
299+
"closedLaneTypes": ["right lane"],
300+
},
301+
]
302+
direction = "north"
303+
has_alternating_traffic = False
304+
expected = [
305+
{"order": 1, "type": "general", "status": "open"},
306+
{"order": 2, "type": "general", "status": "open"},
307+
{"order": 3, "type": "general", "status": "open"},
308+
{"order": 4, "type": "general", "status": "closed"},
309+
]
310+
actual = planned_events.get_lane_impacts(
311+
lane_impacts, direction, has_alternating_traffic
312+
)
313+
assert actual == expected
314+
315+
direction = "south"
316+
expected = [
317+
{"order": 1, "type": "general", "status": "open"},
318+
{"order": 2, "type": "general", "status": "open"},
319+
{"order": 3, "type": "general", "status": "open"},
320+
{"order": 4, "type": "general", "status": "closed"},
321+
]
322+
actual = planned_events.get_lane_impacts(
323+
lane_impacts, direction, has_alternating_traffic
324+
)
325+
assert actual == expected
326+
327+
# Alternating traffic
328+
has_alternating_traffic = True
329+
330+
direction = "north"
331+
expected = [
332+
{"order": 1, "type": "general", "status": "alternating-flow"},
333+
{"order": 2, "type": "general", "status": "closed"},
334+
{"order": 3, "type": "general", "status": "closed"},
335+
{"order": 4, "type": "general", "status": "closed"},
336+
]
337+
actual = planned_events.get_lane_impacts(
338+
lane_impacts, direction, has_alternating_traffic
339+
)
340+
assert actual == expected
341+
342+
direction = "south"
343+
expected = [
344+
{"order": 1, "type": "general", "status": "alternating-flow"},
345+
{"order": 2, "type": "general", "status": "closed"},
346+
{"order": 3, "type": "general", "status": "closed"},
347+
{"order": 4, "type": "general", "status": "closed"},
348+
]
349+
actual = planned_events.get_lane_impacts(
350+
lane_impacts, direction, has_alternating_traffic
351+
)
352+
assert actual == expected
353+
354+
227355
# --------------------------------------------------------------------------------Unit test for get_vehicle_impact function--------------------------------------------------------------------------------
228356
def test_get_vehicle_impact_some_lanes_closed():
229357
lanes = [

wzdx/raw_to_standard/planned_events.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -574,16 +574,14 @@ def detect_alternating_traffic(additional_impacts: list[dict]) -> bool:
574574

575575
def get_lane_impacts(
576576
lane_impacts: list[dict],
577-
direction: Literal[
578-
"undefined", "eastbound", "westbound", "northbound", "southbound"
579-
],
577+
direction: Literal["undefined", "east", "west", "north", "south"],
580578
has_alternating_traffic: bool,
581579
) -> list[dict]:
582580
"""Get WZDx lane list from list of lane impacts and direction. If has_alternating_traffic is True, one lane will show alternating-flow while all other lanes will be closed
583581
584582
Args:
585583
lane_impacts (list[dict]): Planned event lane impacts
586-
direction (Literal["undefined", "eastbound", "westbound", "northbound", "southbound"]): Planned event direction
584+
direction (Literal["undefined", "east", "west", "north", "south"]): Planned event direction
587585
588586
Returns:
589587
list[dict]: _description_

0 commit comments

Comments
 (0)