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")
 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)
示例#3
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)
    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))
    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_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)