Exemple #1
0
def test_with_empty_sensors():
    adc = ADCDevice(hardware_required=False, **{
        "input_impedance": 1000.5,
        "bit_rate": 1,
        "sensors": {}
    })
    assert isinstance(adc, ADCDevice)
    assert adc.readings() == {}
Exemple #2
0
def test_with_valid_voltage_channel():
    config = {
        "device": "ADCPi",
        "input_impedance": 10,
        "bit_rate": 12,
        "sensors": {
            "your label": {
                "type": "voltage",
                "channel": 1,
                "zero_point": 0,
                "resistance": 50.5
            }
        }
    }
    adc = ADCDevice(hardware_required=False, **config)
    assert len(adc.sensors) == 1
    sensor = adc.sensors['your label']
    assert isinstance(sensor, ADCSensor)
    assert sensor.type == "voltage"
    assert sensor.sensitivity == 6.05
    assert str(adc) == "ADC(ch_1: 'your label')"
    assert vars(sensor) == {
        "type": "voltage",
        "channel": 1,
        "zero_point": 0.0,
        "ref_channel": None,
        "resistance": 50.5,
        "sensitivity": 6.05
    }
    assert sensor.config() == {
        "type": "voltage",
        "channel": 1,
        "zero_point": 0.0,
        "ref_channel": None,
        "resistance": 50.5,
    }
    assert adc.config() == {
        "device": "ADCPi",
        "address1": 104,
        "address2": 105,
        "input_impedance": 10.0,
        "bit_rate": 12,
        "sensors": {
            "your label": {
                "type": "voltage",
                "channel": 1,
                "ref_channel": None,
                "zero_point": 0,
                "resistance": 50.5
            }
        }
    }
Exemple #3
0
def test_with_missing_sensors():
    with pytest.raises(ADCError) as e:
        adc = ADCDevice(**{
            "input_impedance": "test",
            "bit_rate": "lots"
        })
    assert "Missing parameter: 'sensors'" in str(e)
Exemple #4
0
def test_with_invalid_sensors():
    with pytest.raises(ADCError) as e:
        adc = ADCDevice(**{
            "input_impedance": 1000,
            "bit_rate": 16,
            "sensors": "this is invalid"
        })
    assert "'sensors' must be a dictionary" in str(e)
Exemple #5
0
def test_with_invalid_bit_rate():
    with pytest.raises(ADCError) as e:
        adc = ADCDevice(**{
            "input_impedance": 1000,
            "bit_rate": "lots",
            "sensors": {}
        })
    assert "bit_rate: 'lots' must be an integer" in str(e)
Exemple #6
0
def test_with_invalid_impedance():
    with pytest.raises(ADCError) as e:
        adc = ADCDevice(**{
            "input_impedance": "test",
            "bit_rate": "lots",
            "sensors": {}
        })
    assert "input_impedance: 'test' must be a number" in str(e)
Exemple #7
0
def test_with_missing_channel():
    with pytest.raises(ADCError) as e:
        adc = ADCDevice(hardware_required=False, **{
            "input_impedance": 1.5,
            "bit_rate": 200000,
            "sensors": {
                "your label": {}
            }
        })
    assert "channel ['your label']: missing required field 'channel'" in str(e)
Exemple #8
0
def test_with_missing_zero_point():
    with pytest.raises(ADCError) as e:
        adc = ADCDevice(hardware_required=False, **{
            "input_impedance": 1.5,
            "bit_rate": 1.5,
            "sensors": {
                "your label": {
                    "channel": 1,
                    "type": "voltage",
                }
            }
        })
    assert "channel ['your label']: missing required field 'zero_point'" in str(e)
Exemple #9
0
def test_with_invalid_current_channel():
    with pytest.raises(ADCError) as e:
        adc = ADCDevice(hardware_required=False, **{
            "input_impedance": 1.5,
            "bit_rate": 12,
            "sensors": {
                "your label": {
                    "type": "current",
                    "channel": 1,
                    "zero_point": 0
                }
            }
        })
    assert "channel ['your label']: current sensors require 'milliVoltPerAmp' field to be set" in str(e)
Exemple #10
0
def test_with_invalid_voltage_channel():
    with pytest.raises(ADCError) as e:
        adc = ADCDevice(hardware_required=False, **{
            "input_impedance": 1.5,
            "bit_rate": 12,
            "sensors": {
                "your label": {
                    "type": "voltage",
                    "channel": 1,
                    "zero_point": 0
                }
            }
        })
    assert "channel ['your label']: voltage sensors require 'resistance' field to be set" in str(e)
Exemple #11
0
def test_with_invalid_zero_point():
    with pytest.raises(ADCError) as e:
        adc = ADCDevice(hardware_required=False, **{
            "input_impedance": 1.5,
            "bit_rate": 12,
            "sensors": {
                "your label": {
                    "type": "voltage",
                    "channel": 1,
                    "zero_point": "needs a float"
                }
            }
        })
    assert "channel ['your label']: zero_point: 'needs a float' (expected float)" in str(e)
Exemple #12
0
def test_with_valid_current_channel():
    adc = ADCDevice(hardware_required=False, **{
        "input_impedance": 10,
        "bit_rate": 12,
        "sensors": {
            "your label": {
                "type": "current",
                "channel": 1,
                "zero_point": 0,
                "milliVoltPerAmp": 10000
            }
        }
    })
    assert len(adc.sensors) == 1
    sensor = adc.sensors['your label']
    assert isinstance(sensor, ADCSensor)
    assert sensor.type == "current"
    assert sensor.sensitivity == 0.1
    assert str(adc) == "ADC(ch_1: 'your label')"
Exemple #13
0
def test_without_config():
    with pytest.raises(ADCError) as e:
        adc = ADCDevice(**{})
    assert "Missing parameter: 'input_impedance'" in str(e)
Exemple #14
0
def test_with_missing_bit_rate():
    with pytest.raises(ADCError) as e:
        adc = ADCDevice(**{
            "input_impedance": "test"
        })
    assert "Missing parameter: 'bit_rate'" in str(e)