summaryrefslogtreecommitdiffstats
path: root/lab_control/test/sds1000xe_test.py
blob: 6f3de80d69daa041df56b21d127f32a332f6bfc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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(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):
    testValues = [16.23987, 0.0, -0.0164, 10.1]
    checkFloatMeasurement(testValues, mockDevice.setAmplitude, uut.measureAmplitude)

def test_peakToPeakMeasurement(uut, mockDevice):
    testValues = [16.23987, 0.0, -0.0164, 10.1]
    checkFloatMeasurement(testValues, mockDevice.setPeakToPeak, uut.measurePeakToPeak)

def test_RMSMeasurement(uut, mockDevice):
    testValues = [16.23987, 0.0, -0.0164, 10.1]
    checkFloatMeasurement(testValues, mockDevice.setRMS, uut.measureRMS)

def test_frequencyMeasurement(uut, mockDevice):
    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 = [-1, 0, 5, None]
    testMethods = [uut.measureAmplitude, uut.measurePeakToPeak, uut.measureRMS, uut.measureFrequency]

    for t in testCases:
        for m in testMethods:
            with pytest.raises(AssertionError):
                m(t)