コード例 #1
0
def test_create_envirophat_with_multiple_sensors_with_label(mock_envirophat):
    sensor = {
        'sensor': 'weather.temperature',
        'label': 'temperature',
    }
    d = EnvirophatDevice(sensors=[sensor, 'weather.pressure'])

    assert d.sensors == [sensor, 'weather.pressure']
コード例 #2
0
def test_create_envirophat_with_single_sensor_with_label(mock_envirophat):
    sensor = {
        'sensor': 'weather.temperature',
        'label': 'temperature',
    }
    d = EnvirophatDevice(sensor=sensor)

    assert d.sensors == [sensor]
コード例 #3
0
def test_value_returns_dict_for_multiple_sensors_with_labels(mock_envirophat):
    sensors = [
        {
            'sensor': 'weather.temperature',
            'label': 'temp'
        },
        {
            'sensor': 'light.light',
            'label': 'light'
        },
    ]
    mock_envirophat.weather.temperature.return_value = 123
    mock_envirophat.light.light.return_value = 321
    d = EnvirophatDevice(sensors=sensors)

    assert d.value == {'temp': 123, 'light': 321}
コード例 #4
0
def test_create_envirophat_with_valid_sensors(sensor):
    d = EnvirophatDevice(sensor=sensor)

    assert d.sensors == [sensor]
コード例 #5
0
def test_create_envirophat_fails_with_empty_sensors(mock_envirophat):
    with pytest.raises(ValueError):
        EnvirophatDevice(sensors=[])
コード例 #6
0
def test_create_envirophat_fails_with_no_args(mock_envirophat):
    with pytest.raises(ValueError):
        EnvirophatDevice()
コード例 #7
0
def test_create_envirophat_with_multiple_sensors(mock_envirophat):
    d = EnvirophatDevice(sensors=['weather.temperature', 'weather.pressure'])

    assert d.sensors == ['weather.temperature', 'weather.pressure']
コード例 #8
0
def test_update_config_set_led_off(mock_envirophat):
    d = EnvirophatDevice(sensor='light.light')
    d.update_config({'leds': 'off'})

    assert not mock_envirophat.leds.on.called
    assert mock_envirophat.leds.off.called
コード例 #9
0
def test_value_returns_dict_for_single_sensor_with_label(mock_envirophat):
    mock_envirophat.light.light.return_value = 123
    d = EnvirophatDevice(sensor={'sensor': 'light.light', 'label': 'shiny'})

    assert d.value == {'shiny': 123}
コード例 #10
0
def test_value_returns_value_for_single_sensor(mock_envirophat):
    mock_envirophat.light.light.return_value = 123
    d = EnvirophatDevice(sensor='light.light')

    assert d.value == {'light.light': 123}
コード例 #11
0
def test_create_envirophat_with_single_sensor(mock_envirophat):
    d = EnvirophatDevice(sensor='weather.temperature')

    assert d.sensors == ['weather.temperature']
コード例 #12
0
def test_value_returns_dict_for_multiple_sensors(mock_envirophat):
    mock_envirophat.weather.temperature.return_value = 123
    mock_envirophat.light.light.return_value = 321
    d = EnvirophatDevice(sensors=['weather.temperature', 'light.light'])

    assert d.value == {'weather.temperature': 123, 'light.light': 321}
コード例 #13
0
def test_create_envirophat_fails_with_invalid_sensors(sensor):
    with pytest.raises(ValueError):
        EnvirophatDevice(sensor=sensor)