Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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'
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