Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
else:
out = [make_random_object(model.element_type) for _ in range(model.capacity)]
if model.capacity < 10000:
if isinstance(et, pydsdl.UnsignedIntegerType) and et.bit_length <= 8 and fifty_fifty():
out = bytes(out)
return out
elif isinstance(model, pydsdl.VariableLengthArrayType):
length = random.randint(0, model.capacity)
et = model.element_type
if isinstance(et, pydsdl.UnsignedIntegerType) and et.bit_length == 8: # Special case for faster testing
out = numpy.random.randint(0, 256, size=length, dtype=numpy.uint8)
else:
out = [make_random_object(model.element_type) for _ in range(length)]
if length < 10000: # pragma: no branch
if isinstance(et, pydsdl.UnsignedIntegerType) and et.bit_length <= 8 and fifty_fifty():
out = bytes(out)
if model.string_like and fifty_fifty():
try:
out = bytes(out).decode()
except ValueError:
pass
return out
elif isinstance(model, pydsdl.StructureType):
o = pyuavcan.dsdl.get_class(model)()
for f in model.fields_except_padding:
v = make_random_object(f.data_type)
pyuavcan.dsdl.set_attribute(o, f.name, v)
return o
elif isinstance(model, pydsdl.UnionType):
def _numpy_scalar_type(t: pydsdl.Any) -> str:
def pick_width(w: int) -> int:
for o in [8, 16, 32, 64]:
if w <= o:
return o
raise ValueError(f'Invalid bit width: {w}') # pragma: no cover
if isinstance(t, pydsdl.BooleanType):
return f'_np_.bool'
elif isinstance(t, pydsdl.SignedIntegerType):
return f'_np_.int{pick_width(t.bit_length)}'
elif isinstance(t, pydsdl.UnsignedIntegerType):
return f'_np_.uint{pick_width(t.bit_length)}'
elif isinstance(t, pydsdl.FloatType):
return f'_np_.float{pick_width(t.bit_length)}'
else:
assert not isinstance(t, pydsdl.PrimitiveType), 'Forgot to handle some primitive types'
return f'_np_.object_'