Exemplo n.º 1
0
def test_read_scheme_non_convertible_value():
    """Test that the read scheme matches the expected when the read value
    is non-convertible.

    In this case, it doesn't raise the error but log a warning.
    The error value is still processed and left for the plugin level to handle.
    """
    dev = make_metainfo_response()

    rr = api.ReadResponse(timestamp='november',
                          type='temperature',
                          value='101a')

    response_scheme = ReadResponse(dev, [rr])

    assert response_scheme.data == {
        'type': 'thermistor',
        'data': {
            'temperature': {
                'value': '101a',
                'timestamp': 'november',
                'unit': {
                    'name': 'celsius',
                    'symbol': 'C'
                }
            }
        }
    }
Exemplo n.º 2
0
def test_read_scheme_no_precision():
    """Test that the read scheme matches the expected when no precision is given
    for the device
    """
    dev = make_metainfo_response()
    dev.output[0].precision = 0

    rr = api.ReadResponse(timestamp='november',
                          type='temperature',
                          value='10.98765432')

    response_scheme = ReadResponse(dev, [rr])

    assert response_scheme.data == {
        'type': 'thermistor',
        'data': {
            'temperature': {
                'value': 10.98765432,
                'timestamp': 'november',
                'unit': {
                    'name': 'celsius',
                    'symbol': 'C'
                }
            }
        }
    }
Exemplo n.º 3
0
def test_read_scheme_null_value():
    """Test that the read scheme matches the expected when there is no read value.
    """
    dev = make_device_response()

    reading = api.Reading(
        timestamp='november',
        type='temperature',
    )

    response_scheme = ReadResponse(dev, [reading])

    assert response_scheme.data == {
        'kind': 'thermistor',
        'data': [
            {
                'info': '',
                'type': 'temperature',
                'value': None,
                'timestamp': 'november',
                'unit': {
                    'name': 'celsius',
                    'symbol': 'C'
                }
            }
        ]
    }
Exemplo n.º 4
0
def test_read_scheme_with_precision_rounding_2():
    """Test that the read scheme matches the expected when the read value
    must be rounded to the specified precision.
    """
    dev = make_metainfo_response()

    rr = api.ReadResponse(timestamp='november',
                          type='temperature',
                          value='10.98765432')

    response_scheme = ReadResponse(dev, [rr])

    assert response_scheme.data == {
        'type': 'thermistor',
        'data': {
            'temperature': {
                'value': 10.988,
                'timestamp': 'november',
                'unit': {
                    'name': 'celsius',
                    'symbol': 'C'
                }
            }
        }
    }
Exemplo n.º 5
0
def test_read_scheme_no_precision():
    """Test that the read scheme matches the expected when no precision is given
    for the device
    """
    dev = make_device_response()
    dev.output[0].precision = 0

    reading = api.Reading(
        timestamp='november',
        type='temperature',
        float64_value=10.98765432
    )

    response_scheme = ReadResponse(dev, [reading])

    assert response_scheme.data == {
        'kind': 'thermistor',
        'data': [
            {
                'info': '',
                'type': 'temperature',
                'value': 10.98765432,
                'timestamp': 'november',
                'unit': {
                    'name': 'celsius',
                    'symbol': 'C'
                }
            }
        ]
    }
Exemplo n.º 6
0
def test_read_scheme_no_unit():
    """Test that the read scheme matches the expected when no unit is given
    for the device
    """
    dev = make_device_response()
    dev.output[0].unit.name = ''
    dev.output[0].unit.symbol = ''

    reading = api.Reading(
        timestamp='november',
        type='temperature',
        float64_value=10.98765432
    )

    response_scheme = ReadResponse(dev, [reading])

    assert response_scheme.data == {
        'kind': 'thermistor',
        'data': [
            {
                'info': '',
                'type': 'temperature',
                'value': 10.988,
                'timestamp': 'november',
                'unit': None
            }
        ]
    }
Exemplo n.º 7
0
def test_read_scheme_with_precision_rounding_2():
    """Test that the read scheme matches the expected when the read value
    must be rounded to the specified precision.
    """
    dev = make_device_response()

    reading = api.Reading(
        timestamp='november',
        type='temperature',
        float64_value=10.98765432
    )

    response_scheme = ReadResponse(dev, [reading])

    assert response_scheme.data == {
        'kind': 'thermistor',
        'data': [
            {
                'info': '',
                'type': 'temperature',
                'value': 10.988,
                'timestamp': 'november',
                'unit': {
                    'name': 'celsius',
                    'symbol': 'C'
                }
            }
        ]
    }
Exemplo n.º 8
0
def test_read_scheme_with_no_matching_readings():
    """Test that the read scheme matches the expected when no matching
    readings are provided.
    """
    dev = make_metainfo_response()

    rr = api.ReadResponse(timestamp='november', type='humidity', value='5')

    response_scheme = ReadResponse(dev, [rr])

    assert response_scheme.data == {'type': 'thermistor', 'data': {}}
Exemplo n.º 9
0
def test_read_scheme_with_no_matching_readings():
    """Test that the read scheme matches the expected when no matching
    readings are provided.
    """
    dev = make_device_response()

    reading = api.Reading(
        timestamp='november',
        type='humidity',
        int32_value=5
    )

    response_scheme = ReadResponse(dev, [reading])

    assert response_scheme.data == {
        'kind': 'thermistor',
        'data': []
    }
Exemplo n.º 10
0
    def __init__(self, device, device_reading):
        self.device = device
        self.readings = ReadResponse(device, [device_reading.reading])

        read_data = self.readings.data['data']
        if len(read_data) != 1:
            raise ValueError(
                'Expected a single reading for the cache read, but got {}'.
                format(len(read_data)))
        reading = read_data[0]

        self.data = {
            'location': {
                'rack': device_reading.rack,
                'board': device_reading.board,
                'device': device_reading.device,
            },
            'kind': self.readings.data['kind'],
            **reading,
        }
Exemplo n.º 11
0
def test_read_scheme():
    """Test that the read scheme matches the expected."""
    dev = make_metainfo_response()

    rr = api.ReadResponse(timestamp='november', type='temperature', value='10')

    response_scheme = ReadResponse(dev, [rr])

    assert response_scheme.data == {
        'type': 'thermistor',
        'data': {
            'temperature': {
                'value': 10.0,
                'timestamp': 'november',
                'unit': {
                    'name': 'celsius',
                    'symbol': 'C'
                }
            }
        }
    }
Exemplo n.º 12
0
def test_read_scheme_no_unit():
    """Test that the read scheme matches the expected when no unit is given
    for the device
    """
    dev = make_metainfo_response()
    dev.output[0].unit.name = ''
    dev.output[0].unit.symbol = ''

    rr = api.ReadResponse(timestamp='november',
                          type='temperature',
                          value='10.98765432')

    response_scheme = ReadResponse(dev, [rr])

    assert response_scheme.data == {
        'type': 'thermistor',
        'data': {
            'temperature': {
                'value': 10.988,
                'timestamp': 'november',
                'unit': None
            }
        }
    }