How to use the pydsdl.Primitive function in pydsdl

To help you get started, we’ve selected a few pydsdl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github UAVCAN / pyuavcan / tests / dsdl / _compiler.py View on Github external
def _test_constants(model: pydsdl.CompositeType) -> None:
    cls = pyuavcan.dsdl.get_generated_class(model)
    for c in model.constants:
        if isinstance(c.data_type, pydsdl.PrimitiveType):
            reference = c.value
            generated = pyuavcan.dsdl.get_attribute(cls, c.name)
            assert isinstance(reference, pydsdl.Primitive)
            assert reference.native_value == pytest.approx(generated), \
                'The generated constant does not compare equal against the DSDL source'
github UAVCAN / pyuavcan / tests / dsdl / _constants.py View on Github external
def _unittest_slow_constants(generated_packages: typing.List[pyuavcan.dsdl.GeneratedPackageInfo]) -> None:
    for info in generated_packages:
        for model in _util.expand_service_types(info.models, keep_services=True):
            dtype = pyuavcan.dsdl.get_class(model)
            for c in model.constants:
                if isinstance(c.data_type, pydsdl.PrimitiveType):  # pragma: no branch
                    reference = c.value
                    generated = pyuavcan.dsdl.get_attribute(dtype, c.name)
                    assert isinstance(reference, pydsdl.Primitive)
                    assert reference.native_value == pytest.approx(generated), \
                        'The generated constant does not compare equal against the DSDL source'
            if issubclass(dtype, pyuavcan.dsdl.FixedPortObject):
                assert issubclass(dtype, pyuavcan.dsdl.CompositeObject) \
                    and issubclass(dtype, pyuavcan.dsdl.FixedPortObject)
                assert pyuavcan.dsdl.get_fixed_port_id(dtype) == pyuavcan.dsdl.get_model(dtype).fixed_port_id