diff options
author | Eddy Pedroni <eddy@0xf7.com> | 2022-05-31 10:11:32 +0200 |
---|---|---|
committer | Eddy Pedroni <eddy@0xf7.com> | 2022-05-31 10:11:32 +0200 |
commit | 26416e3d8cddc3663b69a8e2e9064137afd4b345 (patch) | |
tree | 552a248f11a0347d7db34ccd1784a1d0197f5cb7 | |
parent | d74da5609919e8e57c126b5a66ee40a29d4f7c28 (diff) |
Refactored SDS1000XE
-rw-r--r-- | lab_control/sds1000xe.py | 26 | ||||
-rw-r--r-- | lab_control/test/mock_jds6600_device.py | 2 | ||||
-rw-r--r-- | lab_control/test/sds1000xe_test.py | 35 |
3 files changed, 33 insertions, 30 deletions
diff --git a/lab_control/sds1000xe.py b/lab_control/sds1000xe.py index a3ffe9c..ef6627c 100644 --- a/lab_control/sds1000xe.py +++ b/lab_control/sds1000xe.py @@ -12,20 +12,8 @@ class SDS1000XE(Oscilloscope): self._socket.connect((address, SDS1000XE.PORT)) self._socket.settimeout(SDS1000XE.TIMEOUT) - def measureAmplitude(self, channel: int) -> float: - return self._measure(channel, "AMPL") - - def measurePeakToPeak(self, channel: int) -> float: - return self._measure(channel, "PKPK") - - def measureRMS(self, channel: int) -> float: - return self._measure(channel, "RMS") - - def measureFrequency(self, channel: int) -> float: - return self._measure(channel, "FREQ") - def _measure(self, channel: int, code: str) -> float: - assert channel in SDS1000XE.AVAILABLE_CHANNELS + assert channel in SDS1000XE.AVAILABLE_CHANNELS, "SDS1000X-E: Invalid channel {channel}" query = f"C{channel}:PAVA? {code}\r\n" self._socket.sendall(query.encode()) @@ -40,3 +28,15 @@ class SDS1000XE(Oscilloscope): return measurement + def measureAmplitude(self, channel: int) -> float: + return self._measure(channel, "AMPL") + + def measurePeakToPeak(self, channel: int) -> float: + return self._measure(channel, "PKPK") + + def measureRMS(self, channel: int) -> float: + return self._measure(channel, "RMS") + + def measureFrequency(self, channel: int) -> float: + return self._measure(channel, "FREQ") + diff --git a/lab_control/test/mock_jds6600_device.py b/lab_control/test/mock_jds6600_device.py index a37d8a8..426b8ac 100644 --- a/lab_control/test/mock_jds6600_device.py +++ b/lab_control/test/mock_jds6600_device.py @@ -51,8 +51,8 @@ class MockJDS6600Device(): self._channels[1].on = args[1] == "1" # channel frequency - # TODO implement correct behaviour elif function == 23 or function == 24: + # TODO implement correct behaviour ch = function - 23 frequency = float(args[0]) self._channels[ch].frequency = frequency diff --git a/lab_control/test/sds1000xe_test.py b/lab_control/test/sds1000xe_test.py index bf9c6c4..6f3de80 100644 --- a/lab_control/test/sds1000xe_test.py +++ b/lab_control/test/sds1000xe_test.py @@ -15,33 +15,36 @@ def mockDevice(): 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 checkFloatMeasurement(testValues, setValue, measureValue): + for channel in SDS1000XE.AVAILABLE_CHANNELS: + for value in testValues: + setValue(channel, value) + measuredValue = measureValue(channel) + assert measuredValue == value def test_amplitudeMeasurement(uut, mockDevice): - testCases = [(1, 16.23987), (2, 0.0), (3, -0.0164), (4, 10.1)] - checkFloatMeasurement(testCases, mockDevice.setAmplitude, uut.measureAmplitude) + testValues = [16.23987, 0.0, -0.0164, 10.1] + checkFloatMeasurement(testValues, 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) + testValues = [16.23987, 0.0, -0.0164, 10.1] + checkFloatMeasurement(testValues, 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) + testValues = [16.23987, 0.0, -0.0164, 10.1] + checkFloatMeasurement(testValues, 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) + testValues = [16.23987, 0.0, -0.0164, 93489.15] + checkFloatMeasurement(testValues, mockDevice.setFrequency, uut.measureFrequency) def test_invalidChannel(uut, mockDevice): # Channel is checked by the UUT before the request is sent - testCases = [0, 5] + testCases = [-1, 0, 5, None] + testMethods = [uut.measureAmplitude, uut.measurePeakToPeak, uut.measureRMS, uut.measureFrequency] for t in testCases: - with pytest.raises(AssertionError): - measuredAmplitude = uut.measureAmplitude(t) + for m in testMethods: + with pytest.raises(AssertionError): + m(t) |