Skip to content

Commit

Permalink
71 support more top level messages (#74)
Browse files Browse the repository at this point in the history
* 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 <clemens.linnhoff@partner.bmw.de>
  • Loading branch information
ClemensLinnhoff authored Jun 13, 2024
1 parent b6e642a commit 160aea1
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 4 deletions.
27 changes: 26 additions & 1 deletion osivalidator/osi_general_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,18 @@ def command_line_arguments():
"--type",
"-t",
help="Name of the type used to serialize data. Default is SensorView.",
choices=["SensorView", "GroundTruth", "SensorData"],
choices=[
"SensorView",
"SensorViewConfiguration",
"GroundTruth",
"HostVehicleData",
"SensorData",
"TrafficUpdate",
"TrafficCommandUpdate",
"TrafficCommand",
"MotionRequest",
"StreamingUpdate",
],
type=str,
required=False,
)
Expand Down Expand Up @@ -136,8 +147,22 @@ def detect_message_type(path: str):
return "SensorData"
if filename.find("_sv_") != -1:
return "SensorView"
if filename.find("_svc_") != -1:
return "SensorViewConfiguration"
if filename.find("_gt_") != -1:
return "GroundTruth"
if filename.find("_tu_") != -1:
return "TrafficUpdate"
if filename.find("_tcu_") != -1:
return "TrafficCommandUpdate"
if filename.find("_tc_") != -1:
return "TrafficCommand"
if filename.find("_hvd_") != -1:
return "HostVehicleData"
if filename.find("_mr_") != -1:
return "MotionRequest"
if filename.find("_su_") != -1:
return "StreamingUpdate"
return "SensorView"


Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ ruamel.yaml>=0.18.5
defusedxml>=0.7.1
iso3166>=2.1.1
protobuf>=4.24.4
open-simulation-interface @ git+https://github.com/OpenSimulationInterface/open-simulation-interface.git@v3.7.0-rc1
open-simulation-interface @ git+https://github.com/OpenSimulationInterface/open-simulation-interface.git@master
2 changes: 1 addition & 1 deletion rules2yml.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def gen_yml_rules(dir_name="rules", full_osi=False):
for file in glob("open-simulation-interface/*.proto*"):
filename = file.split("open-simulation-interface/")[1].split(".proto")[0]

if os.path.exists(f"{dir_name}/{filename}.yml"):
if os.path.exists(f"{dir_name}/schema/{filename}_schema.yml"):
continue

with open(f"{dir_name}/schema/{filename}_schema.yml", "a") as schema_file:
Expand Down
68 changes: 68 additions & 0 deletions tests/test_osi_general_validator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import unittest
from osivalidator.osi_general_validator import detect_message_type


class TestDetectMessageType(unittest.TestCase):
def test_detect_message_type_sensor_data(self):
path = "path/to/file_sd_123.osi"
message_type = detect_message_type(path)
self.assertEqual(message_type, "SensorData")

def test_detect_message_type_sensor_view(self):
path = "path/to/file_sv_123.osi"
message_type = detect_message_type(path)
self.assertEqual(message_type, "SensorView")

def test_detect_message_type_sensor_view_config(self):
path = "path/to/file_svc_123.osi"
message_type = detect_message_type(path)
self.assertEqual(message_type, "SensorViewConfiguration")

def test_detect_message_type_ground_truth(self):
path = "path/to/file_gt_123.osi"
message_type = detect_message_type(path)
self.assertEqual(message_type, "GroundTruth")

def test_detect_message_type_traffic_update(self):
path = "path/to/file_tu_123.osi"
message_type = detect_message_type(path)
self.assertEqual(message_type, "TrafficUpdate")

def test_detect_message_type_traffic_command_update(self):
path = "path/to/file_tcu_123.osi"
message_type = detect_message_type(path)
self.assertEqual(message_type, "TrafficCommandUpdate")

def test_detect_message_type_traffic_command(self):
path = "path/to/file_tc_123.osi"
message_type = detect_message_type(path)
self.assertEqual(message_type, "TrafficCommand")

def test_detect_message_type_host_vehicle_data(self):
path = "path/to/file_hvd_123.osi"
message_type = detect_message_type(path)
self.assertEqual(message_type, "HostVehicleData")

def test_detect_message_type_motion_request(self):
path = "path/to/file_mr_123.osi"
message_type = detect_message_type(path)
self.assertEqual(message_type, "MotionRequest")

def test_detect_message_type_streaming_update(self):
path = "path/to/file_su_123.osi"
message_type = detect_message_type(path)
self.assertEqual(message_type, "StreamingUpdate")

def test_detect_message_type_unknown(self):
path = "path/to/unknown_file.osi"
message_type = detect_message_type(path)
self.assertEqual(message_type, "SensorView")

def test_detect_message_type_empty_path(self):
path = ""
message_type = detect_message_type(path)
self.assertEqual(message_type, "SensorView")


if __name__ == "__main__":
unittest.main()

0 comments on commit 160aea1

Please sign in to comment.