Пример #1
0
    def test_comply_is_not_valid(self):
        container = TypeRulesContainer()
        proto_path = ProtoMessagePath(['Orientation3d', 'roll'])
        container.add_type_from_path(proto_path)

        root_container = TypeRulesContainer()
        root_path = ProtoMessagePath(['Orientation3d'])
        root_container.add_type_from_path(root_path)

        rule1 = Rule(verb="is_greater_than",
                     field_name='roll',
                     params=6,
                     path=proto_path,
                     extra_params=dict())
        rule2 = Rule(verb="is_less_than",
                     field_name='roll',
                     params=10,
                     path=proto_path,
                     extra_params=dict())

        rules = FieldRules("roll",
                           rules=[rule1, rule2],
                           path=proto_path,
                           root=root_container)

        rule = MessageTypeRules(name="Orientation3d")
        rule.add_field(rules)
        rule.add_type_from_path(rules)

        rule.root = container
        rule._path = proto_path
        rule.path = proto_path

        compliance = self.FRC.is_valid(self.linked_orient3d, rule)
        self.assertFalse(compliance)
Пример #2
0
    def test_comply_refers_to(self):
        """
        Check if the message object is referenced correctly
        """
        container = TypeRulesContainer()
        proto_path = ProtoMessagePath(
            ["GroundTruth", "host_vehicle_id", "refers_to"])
        container.add_type_from_path(proto_path)

        rule = Rule(
            verb="refers_to",
            params="MovingObject",
            extra_params=dict(),
            path=proto_path,
            field_name="host_vehicle_id",
        )
        rule.root = container
        self.FRC.refers_to(self.linked_hvid1, rule)
        self.FRC.refers_to(self.linked_hvid2, rule)
        self.FRC.refers_to(self.linked_hvid1, rule)

        references_list = self.FRC.id_manager._references

        print(references_list)

        # Check the instance type of the reference
        self.assertIsInstance(references_list[0][0], GroundTruth)

        # Check the id assignment of the reference to the object
        self.assertEqual(references_list[0][0].host_vehicle_id.value, 0)
        self.assertEqual(references_list[0][1], 0)
        self.assertEqual(references_list[0][2], "MovingObject")
Пример #3
0
    def test_not_comply_last_element(self):
        field_list = [self.lb1, self.lb2]
        container = TypeRulesContainer()
        proto_path = ProtoMessagePath(['LaneBoundary', 'BoundaryPoint'])
        container.add_type_from_path(proto_path)
        container.add_type_from_path(ProtoMessagePath(['Vector3d']))

        rule = Rule(verb="last_element",
                    params={'width': [{'is_equal': 0.11}],
                            'height': [{'is_equal': 0.13}]},
                    path=proto_path,
                    extra_params=dict(),
                    field_name='boundary_line')
        rule.root = container
        compliance = self.FRC.last_element(field_list, rule)
        self.assertFalse(compliance)
 def test_add_type_from_path(self):
     """Test the adding of a Message type from a path in the rule tree"""
     container = TypeRulesContainer()
     path = ProtoMessagePath(["foo", "bar", "type"])
     container.add_type_from_path(path)
     typecontainer = container.get_type(path)
     self.assertIsInstance(typecontainer.path, ProtoMessagePath)
     self.assertEqual(path.path, typecontainer.path.path)
 def test_from_directory(self):
     """Test import from directory"""
     ovr = OSIRules()
     ovr.from_yaml_directory("requirements-osi-3")
     test_path = ProtoMessagePath(["LaneBoundary", "BoundaryPoint"])
     ovr_container = ovr.rules.get_type(test_path)
     self.assertIsInstance(ovr_container.path, ProtoMessagePath)
     self.assertEqual(test_path.path, ovr_container.path.path)
    def test_not_comply_last_element(self):
        field_list = [self.lb1, self.lb2]
        container = TypeRulesContainer()
        proto_path = ProtoMessagePath(["LaneBoundary", "BoundaryPoint"])
        container.add_type_from_path(proto_path)
        container.add_type_from_path(ProtoMessagePath(["Vector3d"]))

        rule = Rule(
            verb="last_element",
            params={
                "width": [{"is_equal_to": 0.11}],
                "height": [{"is_equal_to": 0.13}],
            },
            path=proto_path,
            extra_params=dict(),
            field_name="boundary_line",
        )
        rule.root = container
        compliance = self.FRC.last_element(field_list, rule)
        self.assertFalse(compliance)
Пример #7
0
 def message_type(self):
     """
     Return a path to the message type in OSI3 as a ProtoMessagePath
     """
     if not self._message_type:
         field_type_desc = self.value.DESCRIPTOR
         message_type = []
         while field_type_desc is not None:
             message_type.insert(0, field_type_desc.name)
             field_type_desc = field_type_desc.containing_type
         self._message_type = ProtoMessagePath(message_type)
     return self._message_type
Пример #8
0
    def test_parse_yaml(self):
        """ Test the YAML parsing"""
        raw = """
        HostVehicleData:
            location:
                - is_set:
            location_rmse:
                - is_set: 
        """
        validation_rules = OSIRules()
        validation_rules.from_yaml(raw)
        rules = validation_rules.rules
        field = rules['HostVehicleData'].get_field('location')
        rule_check = Rule(verb='is_set',
                          field_name="location",
                          path=ProtoMessagePath(
                              ["HostVehicleData", "location", "is_set"]))

        self.assertEqual(field['is_set'], rule_check)
    def test_comply_is_globally_unique(self):
        """
        Test if the ID Manager has unique indices
        """
        container = TypeRulesContainer()
        proto_path = ProtoMessagePath(
            ["SensorView", "sensor_id", "is_globally_unique"])
        container.add_type_from_path(proto_path)

        rule = Rule(
            verb="is_globally_unique",
            field_name="sensor_id",
            extra_params=dict(),
            path=proto_path,
        )
        rule.root = container
        self.FRC.is_globally_unique(self.linked_sid, rule)
        self.FRC.is_globally_unique(self.linked_sid2, rule)
        self.FRC.is_globally_unique(self.linked_sid2, rule)
        index_dict = self.FRC.id_manager._index
        self.assertEqual(2, len(index_dict))