How to use the pydsdl.FloatType.__name__ 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
ts = time.process_time()
    sr = pyuavcan.dsdl.serialize(o)
    perf_sample[0] = time.process_time() - ts

    ts = time.process_time()
    d = pyuavcan.dsdl.try_deserialize(type(o), sr)
    perf_sample[1] = time.process_time() - ts

    assert d is not None
    assert type(o) is type(d)
    assert pyuavcan.dsdl.get_type(o) == pyuavcan.dsdl.get_type(d)
    assert _are_close(pyuavcan.dsdl.get_type(o), o, d), f'{o} != {d}; sr: {bytes(sr).hex()}'
    # Similar floats may produce drastically different string representations, so if there is at least one float inside,
    # we skip the string representation equality check.
    if pydsdl.FloatType.__name__ not in repr(pyuavcan.dsdl.get_type(d)):
        assert str(o) == str(d)
        assert repr(o) == repr(d)

    return perf_sample
github UAVCAN / pyuavcan / tests / dsdl / _builtin_form.py View on Github external
def _unittest_slow_builtin_form_automatic(generated_packages: typing.List[pyuavcan.dsdl.GeneratedPackageInfo]) -> None:
    for info in generated_packages:
        for model in _util.expand_service_types(info.models):
            if max(model.bit_length_set) / 8 > 1024 * 1024:
                _logger.info('Automatic test of %s skipped because the type is too large', model)
                continue        # Skip large objects because they take forever to convert and test

            obj = _util.make_random_object(model)
            bi = pyuavcan.dsdl.to_builtin(obj)
            reconstructed = pyuavcan.dsdl.update_from_builtin(pyuavcan.dsdl.get_class(model)(), bi)

            if str(obj) != str(reconstructed) or repr(obj) != repr(reconstructed):  # pragma: no branch
                if pydsdl.FloatType.__name__ not in repr(model):  # pragma: no cover
                    _logger.info('Automatic comparison cannot be performed because the objects of type %s may '
                                 'contain floats. Please implement proper DSDL object comparison methods and '
                                 'update this test to use them.',
                                 model)
                    _logger.info('Original random object: %r', obj)
                    _logger.info('Reconstructed object:   %r', reconstructed)
                    _logger.info('Built-in representation: %r', bi)
                else:
                    assert False, f'{obj} != {reconstructed}'
github UAVCAN / pyuavcan / tests / dsdl / _random.py View on Github external
ts = time.process_time()
    d = pyuavcan.dsdl.deserialize(type(obj), chunks)    # GC must be disabled while we're in the timed context
    des_sample = time.process_time() - ts

    gc.enable()

    assert d is not None
    assert type(obj) is type(d)
    assert pyuavcan.dsdl.get_model(obj) == pyuavcan.dsdl.get_model(d)

    if not _util.are_close(pyuavcan.dsdl.get_model(obj), obj, d):  # pragma: no cover
        assert False, f'{obj} != {d}; sr: {bytes().join(chunks).hex()}'  # Branched for performance reasons

    # Similar floats may produce drastically different string representations, so if there is at least one float inside,
    # we skip the string representation equality check.
    if pydsdl.FloatType.__name__ not in repr(pyuavcan.dsdl.get_model(d)):
        assert str(obj) == str(d)
        assert repr(obj) == repr(d)

    return ser_sample, des_sample