Beispiel #1
0
def test_config_latching(type_name, data, python_type, latched_value):
    """Make sure we can properly decode variables."""

    print("Testing config latching of type %s with data %s" % (type_name, repr(data)))
    desc = ConfigDescriptor(0x8000, type_name, python_type=python_type)
    desc.update_value(0, data)

    actual_latched = desc.latch()
    assert actual_latched == latched_value
Beispiel #2
0
def test_unsupported_type():
    """Make sure we throw en error if we have an unknown python type."""

    with pytest.raises(ArgumentError):
        desc = ConfigDescriptor(0x8000,
                                'uint8_t',
                                default=b'\0',
                                python_type="unsupported")
Beispiel #3
0
def test_nonnull_string():
    """Make sure we throw an exception for non-null terminated strings."""
    desc = ConfigDescriptor(0x8000, 'char[16]', python_type='string')
    desc.update_value(0, b'test string')

    with pytest.raises(DataError):
        desc.latch()
Beispiel #4
0
def test_default_values(type_name, default_value, latched_value, python_type, expected_exc):
    """Make sure we can properly convert default values to binary."""

    desc = ConfigDescriptor(0x8000, type_name, default_value, python_type=python_type)
    desc.clear()

    if expected_exc is not None:
        with pytest.raises(expected_exc):
            desc.latch()
    else:
        assert desc.latch() == latched_value
Beispiel #5
0
def test_empty():
    """Make sure we throw en error if we latch an empty config var."""

    desc = ConfigDescriptor(0x8000, 'uint8_t')
    with pytest.raises(DataError):
        desc.latch()
Beispiel #6
0
def test_bool_conversion():
    """Make sure we can convert to bool."""

    desc = ConfigDescriptor(0x8000, 'uint8_t', 0, python_type='bool')
    desc.clear()

    assert desc.latch() is False

    desc = ConfigDescriptor(0x8000, 'uint8_t', 1, python_type='bool')
    desc.clear()

    assert desc.latch() is True

    with pytest.raises(ArgumentError):
        desc = ConfigDescriptor(0x8000, 'uint8_t[2]', 0, python_type='bool')