EdgePi-Cloud / edgepi-python-sdk

Python SDK to control EdgePi, an industrial PC/PLC/IoT device powered by Raspberry Pi CM4
MIT License
5 stars 3 forks source link

integration test dac test failing #416

Closed farzadpanahi closed 4 months ago

farzadpanahi commented 4 months ago
------------------------------ Captured log setup ------------------------------
17:48:56 INFO [edgepi_dac.py:57] Initializing DAC Bus
17:48:56 INFO [edgepi_eeprom.py:40] Initializing EEPROM Access
17:48:58 INFO [dac_commands.py:21] Initializing DAC Methods
17:48:58 INFO [edgepi_gpio.py:26] GPIO initializing
______ test_dac_write_and_read_voltages[DACChannel.AOUT3-5.1111-raises26] ______

analog_out = <DACChannel.AOUT3: 2>, voltage = 5.1111
raises = <_pytest.python_api.RaisesContext object at 0x7fa0158160>
dac = <edgepi.dac.edgepi_dac.EdgePiDAC object at 0x7f9fe9e220>

    @pytest.mark.parametrize(
        "analog_out, voltage, raises",
        [
            (CH.AOUT1, LOWER_VOLT_LIMIT, does_not_raise()),
            (CH.AOUT1, 2.5, does_not_raise()),
            (CH.AOUT1, UPPER_VOLT_LIMIT, does_not_raise()),
            (CH.AOUT2, LOWER_VOLT_LIMIT, does_not_raise()),
            (CH.AOUT2, 2.5, does_not_raise()),
            (CH.AOUT2, UPPER_VOLT_LIMIT, does_not_raise()),
            (CH.AOUT3, LOWER_VOLT_LIMIT, does_not_raise()),
            (CH.AOUT3, 2.5, does_not_raise()),
            (CH.AOUT3, UPPER_VOLT_LIMIT, does_not_raise()),
            (CH.AOUT4, LOWER_VOLT_LIMIT, does_not_raise()),
            (CH.AOUT4, 2.5, does_not_raise()),
            (CH.AOUT4, UPPER_VOLT_LIMIT, does_not_raise()),
            (CH.AOUT5, LOWER_VOLT_LIMIT, does_not_raise()),
            (CH.AOUT5, 2.5, does_not_raise()),
            (CH.AOUT5, UPPER_VOLT_LIMIT, does_not_raise()),
            (CH.AOUT6, LOWER_VOLT_LIMIT, does_not_raise()),
            (CH.AOUT6, 2.5, does_not_raise()),
            (CH.AOUT6, UPPER_VOLT_LIMIT, does_not_raise()),
            (CH.AOUT7, LOWER_VOLT_LIMIT, does_not_raise()),
            (CH.AOUT7, 2.5, does_not_raise()),
            (CH.AOUT7, UPPER_VOLT_LIMIT, does_not_raise()),
            (CH.AOUT8, LOWER_VOLT_LIMIT, does_not_raise()),
            (CH.AOUT8, 2.5, does_not_raise()),
            (CH.AOUT8, UPPER_VOLT_LIMIT, does_not_raise()),
            (CH.AOUT1, -0.1, pytest.raises(ValueError)),
            (CH.AOUT2, 5.118, pytest.raises(ValueError)),
            (CH.AOUT3, 5.[111](https://github.com/EdgePi-Cloud/edgepi-python-sdk/actions/runs/8916925521/job/24489175731?pr=414#step:5:112)1, pytest.raises(ValueError)),
        ],
    )
    def test_dac_write_and_read_voltages(analog_out, voltage, raises, dac):
        with raises:
            # expected_voltage = (voltage)*dac.dac_ops.dict_calib_param[analog_out.value].gain -\
            #  dac.dac_ops.dict_calib_param[analog_out.value].offset
            dac.write_voltage(analog_out, voltage)
            code, voltage_val, gain_state = dac.get_state(analog_out, True, True, True)
            dac_gain = 2 if gain_state else 1
            expected_voltage = dac.dac_ops.code_to_voltage(analog_out.value, code, dac_gain)
            assert voltage_val == pytest.approx(expected_voltage, abs=STORE_ERROR)
>           assert code == dac.dac_ops.voltage_to_code(analog_out.value, voltage, dac_gain)
E           Failed: DID NOT RAISE <class 'ValueError'>

src/test_edgepi/integration_tests/test_dac/test_dac.py:79: Failed
FAILED src/test_edgepi/integration_tests/test_dac/test_dac.py::test_dac_write_and_read_voltages[DACChannel.AOUT2-5.118-raises25]
FAILED src/test_edgepi/integration_tests/test_dac/test_dac.py::test_dac_write_and_read_voltages[DACChannel.AOUT3-5.1111-raises26]