Skip to content

Commit 68dc1f4

Browse files
committed
Updating unit tests
1 parent 566923e commit 68dc1f4

File tree

7 files changed

+94
-152
lines changed

7 files changed

+94
-152
lines changed

tests/data/raw_to_standard/planned_events_test_expected_results.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@
345345
"beginning_cross_street": "CO 65",
346346
"ending_cross_street": "US 6",
347347
"valid": False,
348+
"vehicle_impact": "all-lanes-closed",
348349
},
349350
},
350351
}

tests/data/standard_to_wzdx/planned_events_translator_data.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"types_of_work": [
3333
{"type_name": "below-road-work", "is_architectural_change": True}
3434
],
35+
"vehicle_impact": "some-lanes-closed",
3536
},
3637
},
3738
}
@@ -108,6 +109,7 @@
108109
"restrictions": [],
109110
"beginning_milepost": 50.0,
110111
"ending_milepost": 60.0,
112+
"vehicle_impact": "some-lanes-closed",
111113
},
112114
},
113115
}

tests/raw_to_standard/planned_events_test.py

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

226226

227+
# --------------------------------------------------------------------------------Unit test for get_vehicle_impact function--------------------------------------------------------------------------------
228+
def test_get_vehicle_impact_some_lanes_closed():
229+
lanes = [
230+
{"order": 1, "type": "shoulder", "status": "open"},
231+
{"order": 2, "type": "general", "status": "closed"},
232+
{"order": 3, "type": "general", "status": "closed"},
233+
{"order": 4, "type": "shoulder", "status": "open"},
234+
]
235+
test_vehicle_impact = planned_events.get_vehicle_impact(lanes, False)
236+
expected_vehicle_impact = "some-lanes-closed"
237+
assert test_vehicle_impact == expected_vehicle_impact
238+
239+
240+
def test_get_vehicle_impact_all_lanes_closed():
241+
lanes = [
242+
{"order": 1, "type": "shoulder", "status": "closed"},
243+
{"order": 2, "type": "general", "status": "closed"},
244+
{"order": 3, "type": "general", "status": "closed"},
245+
{"order": 4, "type": "shoulder", "status": "closed"},
246+
]
247+
test_vehicle_impact = planned_events.get_vehicle_impact(lanes, False)
248+
expected_vehicle_impact = "all-lanes-closed"
249+
assert test_vehicle_impact == expected_vehicle_impact
250+
251+
252+
def test_get_vehicle_impact_all_lanes_open():
253+
lanes = [
254+
{"order": 1, "type": "shoulder", "status": "open"},
255+
{"order": 2, "type": "general", "status": "open"},
256+
{"order": 3, "type": "general", "status": "open"},
257+
{"order": 4, "type": "shoulder", "status": "open"},
258+
]
259+
test_vehicle_impact = planned_events.get_vehicle_impact(lanes, False)
260+
expected_vehicle_impact = "all-lanes-open"
261+
assert test_vehicle_impact == expected_vehicle_impact
262+
263+
264+
def test_get_vehicle_impact_alternating_description_valid():
265+
lanes = [
266+
{"order": 1, "type": "shoulder", "status": "open"},
267+
{"order": 2, "type": "general", "status": "closed"},
268+
{"order": 3, "type": "general", "status": "open"},
269+
{"order": 4, "type": "shoulder", "status": "closed"},
270+
]
271+
test_vehicle_impact = planned_events.get_vehicle_impact(lanes, True)
272+
expected_vehicle_impact = "alternating-one-way"
273+
assert test_vehicle_impact == expected_vehicle_impact
274+
275+
227276
def test_is_incident_true_true():
228277
msg = {
229278
"properties": {"id": "OpenTMS-Incident2028603626", "type": "Emergency Roadwork"}
@@ -313,6 +362,25 @@ def test_is_incident_wz_false_2():
313362
assert actual == (False, False)
314363

315364

365+
def test_detect_alternating_traffic_true():
366+
additional_impacts = ["Alternating traffic", "Alternating Lanes"]
367+
assert planned_events.detect_alternating_traffic(additional_impacts)
368+
369+
additional_impacts = ["Alternating traffic"]
370+
assert planned_events.detect_alternating_traffic(additional_impacts)
371+
372+
373+
def test_detect_alternating_traffic_false():
374+
additional_impacts = None
375+
assert not planned_events.detect_alternating_traffic(additional_impacts)
376+
377+
additional_impacts = []
378+
assert not planned_events.detect_alternating_traffic(additional_impacts)
379+
380+
additional_impacts = ["other impact"]
381+
assert not planned_events.detect_alternating_traffic(additional_impacts)
382+
383+
316384
class MockGeospatialApi:
317385
def __init__(
318386
self, getCachedRequest=lambda x: None, setCachedRequest=lambda x, y: None

tests/standard_to_wzdx/planned_events_translator_test.py

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -63,88 +63,6 @@ def test_parse_work_zone_invalid_data():
6363
assert test_feature == None
6464

6565

66-
# --------------------------------------------------------------------------------Unit test for get_vehicle_impact function--------------------------------------------------------------------------------
67-
def test_get_vehicle_impact_some_lanes_closed():
68-
lanes = [
69-
{"order": 1, "type": "shoulder", "status": "open"},
70-
{"order": 2, "type": "general", "status": "closed"},
71-
{"order": 3, "type": "general", "status": "closed"},
72-
{"order": 4, "type": "shoulder", "status": "open"},
73-
]
74-
test_vehicle_impact = planned_events_translator.get_vehicle_impact(
75-
lanes, "description"
76-
)
77-
expected_vehicle_impact = "some-lanes-closed"
78-
assert test_vehicle_impact == expected_vehicle_impact
79-
80-
81-
def test_get_vehicle_impact_all_lanes_closed():
82-
lanes = [
83-
{"order": 1, "type": "shoulder", "status": "closed"},
84-
{"order": 2, "type": "general", "status": "closed"},
85-
{"order": 3, "type": "general", "status": "closed"},
86-
{"order": 4, "type": "shoulder", "status": "closed"},
87-
]
88-
test_vehicle_impact = planned_events_translator.get_vehicle_impact(
89-
lanes, "description"
90-
)
91-
expected_vehicle_impact = "all-lanes-closed"
92-
assert test_vehicle_impact == expected_vehicle_impact
93-
94-
95-
def test_get_vehicle_impact_all_lanes_open():
96-
lanes = [
97-
{"order": 1, "type": "shoulder", "status": "open"},
98-
{"order": 2, "type": "general", "status": "open"},
99-
{"order": 3, "type": "general", "status": "open"},
100-
{"order": 4, "type": "shoulder", "status": "open"},
101-
]
102-
test_vehicle_impact = planned_events_translator.get_vehicle_impact(
103-
lanes, "description"
104-
)
105-
expected_vehicle_impact = "all-lanes-open"
106-
assert test_vehicle_impact == expected_vehicle_impact
107-
108-
109-
def test_get_vehicle_impact_alternating_description_valid():
110-
lanes = [
111-
{"order": 1, "type": "shoulder", "status": "open"},
112-
{"order": 2, "type": "general", "status": "closed"},
113-
{"order": 3, "type": "general", "status": "open"},
114-
{"order": 4, "type": "shoulder", "status": "closed"},
115-
]
116-
test_vehicle_impact = planned_events_translator.get_vehicle_impact(
117-
lanes,
118-
"Between Utopia Place and CO 14 (Laporte) from Mile Point 354.5 to Mile Point 355.7. Paving operations. Alternating traffic. "
119-
"Starting June 5, 2025 at 7:00AM MDT until June 5, 2025 at about 5:00PM MDT. Full schedule below: \u2022 June 5, 7:00AM - "
120-
"June 5, 5:00PM Comment: Delays of up to 15 minutes can be anticipated. The speed limit will be reduced to 40 mph through the "
121-
"work zone. More project information is available at 970-632-7440 or sherry@sawpr.com.",
122-
)
123-
expected_vehicle_impact = "alternating-one-way"
124-
assert test_vehicle_impact == expected_vehicle_impact
125-
126-
127-
def test_get_vehicle_impact_alternating_comment_invalid():
128-
lanes = [
129-
{"order": 1, "type": "shoulder", "status": "open"},
130-
{"order": 2, "type": "general", "status": "closed"},
131-
{"order": 3, "type": "general", "status": "open"},
132-
{"order": 4, "type": "shoulder", "status": "closed"},
133-
]
134-
test_vehicle_impact = planned_events_translator.get_vehicle_impact(
135-
lanes,
136-
"Between 3300 Road and Pleasure Park Road (1 to 4 miles west of Hotchkiss) from Mile Point 18.9 to Mile Point 15.6. "
137-
"Road construction. Starting June 5, 2025 at 6:01AM MDT until June 5, 2025 at about 6:00PM MDT. Full schedule below: "
138-
"\u2022 June 5, 6:01AM - June 5, 6:00PM Comment: Shoulder widening will start on the north side. Crews continue pipe "
139-
"installation and waterline work between Mile Point 15-16 in both the eastbound and westbound direction. Alternating "
140-
"single lane traffic under flagger control will be implemented throughout the work zone and delays are expected during "
141-
"peak commuter times. Motorists should expect delays through the work zone. There will be one lane alternating traffic "
142-
"during the majority of the project and shoulder closures as needed and periodic traffic stops in order to move equipment.",
143-
)
144-
expected_vehicle_impact = "some-lanes-closed"
145-
assert test_vehicle_impact == expected_vehicle_impact
146-
147-
14866
# --------------------------------------------------------------------------------Unit test for wzdx_creator function--------------------------------------------------------------------------------
14967
@patch.dict(
15068
os.environ,

tests/tools/cdot_geospatial_api_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ def test_get_route_between_measures():
8989

9090
def test_get_route_between_measures_allow_reversal():
9191
routeId = "070A"
92-
startMeasure = 50
93-
endMeasure = 60
92+
startMeasure = 60
93+
endMeasure = 50
9494
actual = cdot_geospatial_api.GeospatialApi().get_route_between_measures(
9595
routeId, startMeasure, endMeasure, compressed=True
9696
)

wzdx/raw_to_standard/planned_events.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ def update_lanes_alternating_traffic(lanes: list[dict]) -> list[dict]:
558558
return lanes
559559

560560

561-
def detect_alternating_traffic(lane_impacts: list[dict]) -> bool:
561+
def detect_alternating_traffic(additional_impacts: list[dict]) -> bool:
562562
"""Check if there are any lane impacts indicating alternating traffic
563563
564564
Args:
@@ -567,9 +567,9 @@ def detect_alternating_traffic(lane_impacts: list[dict]) -> bool:
567567
Returns:
568568
bool: whether there are any alternating traffic impacts
569569
"""
570-
if not lane_impacts:
570+
if not additional_impacts:
571571
return False
572-
return "Alternating traffic" in lane_impacts
572+
return "Alternating traffic" in additional_impacts
573573

574574

575575
def get_lane_impacts(

wzdx/sample_files/standard/planned_events/standard_planned_event_OpenTMS-Event20643308360_westbound.json

Lines changed: 18 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -15,70 +15,22 @@
1515
"last_updated_timestamp": 1731013775261
1616
},
1717
"geometry": [
18-
[
19-
-105.16586083999994,
20-
39.734858632000055
21-
],
22-
[
23-
-105.16638882599995,
24-
39.73443766200006
25-
],
26-
[
27-
-105.16854799099997,
28-
39.73271605700006
29-
],
30-
[
31-
-105.17077491299995,
32-
39.73094029200007
33-
],
34-
[
35-
-105.17293965199997,
36-
39.72943332800003
37-
],
38-
[
39-
-105.17468559199995,
40-
39.72842892500006
41-
],
42-
[
43-
-105.17580481399995,
44-
39.727785029000074
45-
],
46-
[
47-
-105.17843878399998,
48-
39.72609999900004
49-
],
50-
[
51-
-105.17993813899994,
52-
39.72512450600004
53-
],
54-
[
55-
-105.18206644899999,
56-
39.723739730000034
57-
],
58-
[
59-
-105.18563422299997,
60-
39.72141816000004
61-
],
62-
[
63-
-105.18769294899994,
64-
39.72000476800008
65-
],
66-
[
67-
-105.18847369599996,
68-
39.71936694800007
69-
],
70-
[
71-
-105.18984140499998,
72-
39.718052475000036
73-
],
74-
[
75-
-105.190781717,
76-
39.71695507100003
77-
],
78-
[
79-
-105.19270413899994,
80-
39.714462801000025
81-
]
18+
[-105.16586083999994, 39.734858632000055],
19+
[-105.16638882599995, 39.73443766200006],
20+
[-105.16854799099997, 39.73271605700006],
21+
[-105.17077491299995, 39.73094029200007],
22+
[-105.17293965199997, 39.72943332800003],
23+
[-105.17468559199995, 39.72842892500006],
24+
[-105.17580481399995, 39.727785029000074],
25+
[-105.17843878399998, 39.72609999900004],
26+
[-105.17993813899994, 39.72512450600004],
27+
[-105.18206644899999, 39.723739730000034],
28+
[-105.18563422299997, 39.72141816000004],
29+
[-105.18769294899994, 39.72000476800008],
30+
[-105.18847369599996, 39.71936694800007],
31+
[-105.18984140499998, 39.718052475000036],
32+
[-105.190781717, 39.71695507100003],
33+
[-105.19270413899994, 39.714462801000025]
8234
],
8335
"header": {
8436
"description": "Between Exit 263: Colorado Mills Parkway (West Pleasant View) and C-470 (Golden) from Mile Point 262 to Mile Point 260. Both shoulders closed due to road construction. Starting November 12, 2024 at 7:00AM MST until November 12, 2024 at about 6:00PM MST. Full schedule below: \u00e2\u20ac\u00a2 November 12, 7:00AM - November 12, 6:00PM",
@@ -124,6 +76,7 @@
12476
"beginning_cross_street": "Exit 263: Colorado Mills Parkway (West Pleasant View)",
12577
"ending_cross_street": "C-470 (Golden)",
12678
"valid": false,
79+
"vehicle_impact": "some-lanes-closed",
12780
"route_details_start": {
12881
"Route": "070A_DEC",
12982
"Measure": 262.0,
@@ -141,4 +94,4 @@
14194
"condition_1": true
14295
}
14396
}
144-
}
97+
}

0 commit comments

Comments
 (0)