summaryrefslogtreecommitdiffstats
path: root/lab_control/test/sds1000xe_test.py
blob: bf9c6c46a9965ad6160a2f4b26c24390ba5b4320 (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
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)