示例#1
0
    def __init__(self,
                 name,
                 source_dict: dict,
                 parent=None,
                 children=None,
                 break_on_noncore_attribute=False):
        """Creates an VSS Node object from parsed yaml instance represented as a dict.

            Args:
                name: Name of this VSS instance.
                source_dict: VSS instance represented as dict from yaml parsing.
                parent: Optional parent of this node instance.
                children: Optional children instances of this node.

            Returns:
                VSSNode object according to the Vehicle Signal Specification.

        """

        super().__init__(name, parent, children)
        try:
            VSSNode.validate_vss_element(source_dict, name)
        except NonCoreAttributeException as e:
            print("Warning: {}".format(e))
            if break_on_noncore_attribute:
                print("You asked for strict checking. Terminating.")
                sys.exit(-1)

        self.description = source_dict["description"]
        self.type = VSSType.from_str(source_dict["type"])
        self.uuid = source_dict["uuid"]

        if "datatype" in source_dict.keys():
            self.data_type = VSSDataType.from_str(source_dict["datatype"])

        if "unit" in source_dict.keys():
            self.unit = Unit.from_str(source_dict["unit"])

        if "min" in source_dict.keys():
            self.min = source_dict["min"]

        if "max" in source_dict.keys():
            self.max = source_dict["max"]

        if "enum" in source_dict.keys():
            self.enum = source_dict["enum"]

        if "aggregate" in source_dict.keys():
            self.aggregate = source_dict["aggregate"]

        if "default" in source_dict.keys():
            self.default_value = source_dict["default"]

        if "instances" in source_dict.keys():
            self.instances = source_dict["instances"]

        if "deprecation" in source_dict.keys():
            self.deprecation = source_dict["deprecation"]
示例#2
0
    def __init__(self, name, source_dict: dict, parent=None, children=None):
        """Creates an VSS Node object from parsed yaml instance represented as a dict.

            Args:
                name: Name of this VSS instance.
                source_dict: VSS instance represented as dict from yaml parsing.
                parent: Optional parent of this node instance.
                children: Optional children instances of this node.

            Returns:
                VSSNode object according to the Vehicle Signal Specification.

        """

        super().__init__(name, parent, children)
        VSSNode.validate_vss_element(source_dict, name)
        self.description = source_dict["description"]
        self.type = VSSType.from_str(source_dict["type"])
        self.uuid = source_dict["uuid"]

        if "datatype" in source_dict.keys():
            self.data_type = VSSDataType.from_str(source_dict["datatype"])

        if "unit" in source_dict.keys():
            self.unit = Unit.from_str(source_dict["unit"])

        if "min" in source_dict.keys():
            self.min = source_dict["min"]

        if "max" in source_dict.keys():
            self.max = source_dict["max"]

        if "enum" in source_dict.keys():
            self.enum = source_dict["enum"]

        if "aggregate" in source_dict.keys():
            self.aggregate = source_dict["aggregate"]

        if "default" in source_dict.keys():
            self.default_value = source_dict["default"]

        if "value" in source_dict.keys():
            self.value = source_dict["value"]

        if "instances" in source_dict.keys():
            self.instances = source_dict["instances"]
示例#3
0
 def test_invalid_unit(self):
     with self.assertRaises(Exception): Unit.from_str("not_a_valid_case")
示例#4
0
    def test_units(self):
        """
        Test correct parsing of units
        """

        self.assertEqual(Unit.MILIMETER, Unit.from_str("mm"))
        self.assertEqual(Unit.CENTIMETER, Unit.from_str("cm"))
        self.assertEqual(Unit.METER, Unit.from_str("m"))
        self.assertEqual(Unit.KILOMETER, Unit.from_str("km"))
        self.assertEqual(Unit.KILOMETERPERHOUR, Unit.from_str("km/h"))
        self.assertEqual(Unit.METERSPERSECONDSQUARED, Unit.from_str("m/s^2"))
        self.assertEqual(Unit.LITER, Unit.from_str("l"))
        self.assertEqual(Unit.DEGREECELCIUS, Unit.from_str("celsius"))
        self.assertEqual(Unit.DEGREE, Unit.from_str("degrees"))
        self.assertEqual(Unit.DEGREEPERSECOND, Unit.from_str("degrees/s"))
        self.assertEqual(Unit.KILOWATT, Unit.from_str("kW"))
        self.assertEqual(Unit.KILOWATTHOURS, Unit.from_str("kWh"))
        self.assertEqual(Unit.KILOGRAMM, Unit.from_str("kg"))
        self.assertEqual(Unit.VOLT, Unit.from_str("V"))
        self.assertEqual(Unit.AMPERE, Unit.from_str("A"))
        self.assertEqual(Unit.SECOND, Unit.from_str("s"))
        self.assertEqual(Unit.MINUTE, Unit.from_str("min"))
        self.assertEqual(Unit.WEEKS, Unit.from_str("weeks"))
        self.assertEqual(Unit.MONTHS, Unit.from_str("months"))
        self.assertEqual(Unit.UNIXTIMESTAMP, Unit.from_str("UNIX Timestamp"))
        self.assertEqual(Unit.PASCAL, Unit.from_str("Pa"))
        self.assertEqual(Unit.KILOPASCAL, Unit.from_str("kPa"))
        self.assertEqual(Unit.PERCENT, Unit.from_str("percent"))
        self.assertEqual(Unit.CUBICMETER, Unit.from_str("cm^3"))
        self.assertEqual(Unit.HORSEPOWER, Unit.from_str("PS"))
        self.assertEqual(Unit.STARS, Unit.from_str("stars"))
        self.assertEqual(Unit.GRAMMPERSECOND, Unit.from_str("g/s"))
        self.assertEqual(Unit.GRAMMPERKM, Unit.from_str("g/km"))
        self.assertEqual(Unit.KILOWATTHOURSPER100KM, Unit.from_str("kWh/100km"))
        self.assertEqual(Unit.LITERPER100KM, Unit.from_str("l/100km"))
        self.assertEqual(Unit.LITERPERHOUR, Unit.from_str("l/h"))
        self.assertEqual(Unit.MILESPERGALLON, Unit.from_str("mpg"))
        self.assertEqual(Unit.POUND, Unit.from_str("lbs"))
        self.assertEqual(Unit.NEWTONMETER, Unit.from_str("Nm"))
        self.assertEqual(Unit.REVOLUTIONSPERMINUTE, Unit.from_str("rpm"))
        self.assertEqual(Unit.INCH, Unit.from_str("inch"))
        self.assertEqual(Unit.RATIO, Unit.from_str("ratio"))