import pytest from lab_control.sds1000xe import SDS1000XE from lab_control.test.mock_sds1000xe_device import MockSDS1000XEDevice MOCK_DEVICE_IP = "127.0.0.1" @pytest.fixture def mockDevice(): d = MockSDS1000XEDevice() yield d d.stop() @pytest.fixture def uut(mockDevice): return SDS1000XE(MOCK_DEVICE_IP) def checkFloatMeasurement(testCases, setValue, measureValue): for channel, expectedValue in testCases: setValue(channel, expectedValue) measuredValue = measureValue(channel) assert measuredValue == expectedValue def test_amplitudeMeasurement(uut, mockDevice): testCases = [(1, 16.23987), (2, 0.0), (3, -0.0164), (4, 10.1)] checkFloatMeasurement(testCases, mockDevice.setAmplitude, uut.measureAmplitude) def test_peakToPeakMeasurement(uut, mockDevice): testCases = [(1, 16.23987), (2, 0.0), (3, -0.0164), (4, 10.1)] checkFloatMeasurement(testCases, mockDevice.setPeakToPeak, uut.measurePeakToPeak) def test_RMSMeasurement(uut, mockDevice): testCases = [(1, 16.23987), (2, 0.0), (3, -0.0164), (4, 10.1)] checkFloatMeasurement(testCases, mockDevice.setRMS, uut.measureRMS) def test_frequencyMeasurement(uut, mockDevice): testCases = [(1, 16.23987), (2, 0.0), (3, -0.0164), (4, 93489.15)] checkFloatMeasurement(testCases, mockDevice.setFrequency, uut.measureFrequency) def test_invalidChannel(uut, mockDevice): # Channel is checked by the UUT before the request is sent testCases = [0, 5] for t in testCases: with pytest.raises(AssertionError): measuredAmplitude = uut.measureAmplitude(t)