Skip to content

Commit 160aea1

Browse files
71 support more top level messages (#74)
* Add more message types * Fix double version schema bug * Update osi to current master * Change osi requirement to current master * Add remaining message types and unit tests --------- Signed-off-by: ClemensLinnhoff <[email protected]>
1 parent b6e642a commit 160aea1

5 files changed

+97
-4
lines changed

osivalidator/osi_general_validator.py

+26-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,18 @@ def command_line_arguments():
5454
"--type",
5555
"-t",
5656
help="Name of the type used to serialize data. Default is SensorView.",
57-
choices=["SensorView", "GroundTruth", "SensorData"],
57+
choices=[
58+
"SensorView",
59+
"SensorViewConfiguration",
60+
"GroundTruth",
61+
"HostVehicleData",
62+
"SensorData",
63+
"TrafficUpdate",
64+
"TrafficCommandUpdate",
65+
"TrafficCommand",
66+
"MotionRequest",
67+
"StreamingUpdate",
68+
],
5869
type=str,
5970
required=False,
6071
)
@@ -136,8 +147,22 @@ def detect_message_type(path: str):
136147
return "SensorData"
137148
if filename.find("_sv_") != -1:
138149
return "SensorView"
150+
if filename.find("_svc_") != -1:
151+
return "SensorViewConfiguration"
139152
if filename.find("_gt_") != -1:
140153
return "GroundTruth"
154+
if filename.find("_tu_") != -1:
155+
return "TrafficUpdate"
156+
if filename.find("_tcu_") != -1:
157+
return "TrafficCommandUpdate"
158+
if filename.find("_tc_") != -1:
159+
return "TrafficCommand"
160+
if filename.find("_hvd_") != -1:
161+
return "HostVehicleData"
162+
if filename.find("_mr_") != -1:
163+
return "MotionRequest"
164+
if filename.find("_su_") != -1:
165+
return "StreamingUpdate"
141166
return "SensorView"
142167

143168

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ ruamel.yaml>=0.18.5
55
defusedxml>=0.7.1
66
iso3166>=2.1.1
77
protobuf>=4.24.4
8-
open-simulation-interface @ git+https://github.com/OpenSimulationInterface/open-simulation-interface.git@v3.7.0-rc1
8+
open-simulation-interface @ git+https://github.com/OpenSimulationInterface/open-simulation-interface.git@master

rules2yml.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def gen_yml_rules(dir_name="rules", full_osi=False):
4747
for file in glob("open-simulation-interface/*.proto*"):
4848
filename = file.split("open-simulation-interface/")[1].split(".proto")[0]
4949

50-
if os.path.exists(f"{dir_name}/{filename}.yml"):
50+
if os.path.exists(f"{dir_name}/schema/{filename}_schema.yml"):
5151
continue
5252

5353
with open(f"{dir_name}/schema/{filename}_schema.yml", "a") as schema_file:

tests/test_osi_general_validator.py

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import unittest
2+
from osivalidator.osi_general_validator import detect_message_type
3+
4+
5+
class TestDetectMessageType(unittest.TestCase):
6+
def test_detect_message_type_sensor_data(self):
7+
path = "path/to/file_sd_123.osi"
8+
message_type = detect_message_type(path)
9+
self.assertEqual(message_type, "SensorData")
10+
11+
def test_detect_message_type_sensor_view(self):
12+
path = "path/to/file_sv_123.osi"
13+
message_type = detect_message_type(path)
14+
self.assertEqual(message_type, "SensorView")
15+
16+
def test_detect_message_type_sensor_view_config(self):
17+
path = "path/to/file_svc_123.osi"
18+
message_type = detect_message_type(path)
19+
self.assertEqual(message_type, "SensorViewConfiguration")
20+
21+
def test_detect_message_type_ground_truth(self):
22+
path = "path/to/file_gt_123.osi"
23+
message_type = detect_message_type(path)
24+
self.assertEqual(message_type, "GroundTruth")
25+
26+
def test_detect_message_type_traffic_update(self):
27+
path = "path/to/file_tu_123.osi"
28+
message_type = detect_message_type(path)
29+
self.assertEqual(message_type, "TrafficUpdate")
30+
31+
def test_detect_message_type_traffic_command_update(self):
32+
path = "path/to/file_tcu_123.osi"
33+
message_type = detect_message_type(path)
34+
self.assertEqual(message_type, "TrafficCommandUpdate")
35+
36+
def test_detect_message_type_traffic_command(self):
37+
path = "path/to/file_tc_123.osi"
38+
message_type = detect_message_type(path)
39+
self.assertEqual(message_type, "TrafficCommand")
40+
41+
def test_detect_message_type_host_vehicle_data(self):
42+
path = "path/to/file_hvd_123.osi"
43+
message_type = detect_message_type(path)
44+
self.assertEqual(message_type, "HostVehicleData")
45+
46+
def test_detect_message_type_motion_request(self):
47+
path = "path/to/file_mr_123.osi"
48+
message_type = detect_message_type(path)
49+
self.assertEqual(message_type, "MotionRequest")
50+
51+
def test_detect_message_type_streaming_update(self):
52+
path = "path/to/file_su_123.osi"
53+
message_type = detect_message_type(path)
54+
self.assertEqual(message_type, "StreamingUpdate")
55+
56+
def test_detect_message_type_unknown(self):
57+
path = "path/to/unknown_file.osi"
58+
message_type = detect_message_type(path)
59+
self.assertEqual(message_type, "SensorView")
60+
61+
def test_detect_message_type_empty_path(self):
62+
path = ""
63+
message_type = detect_message_type(path)
64+
self.assertEqual(message_type, "SensorView")
65+
66+
67+
if __name__ == "__main__":
68+
unittest.main()

0 commit comments

Comments
 (0)