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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
import pytest
import time
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)
def test_setVoltsPerDivision(uut, mockDevice):
testValues = [5e-3, 50e-3, 1e0, 5e0, 10e0, 100e0]
for channel in SDS1000XE.AVAILABLE_CHANNELS:
assert mockDevice.getVoltsPerDivision(channel) is None
for value in testValues:
uut.setVoltsPerDivision(channel, value)
time.sleep(0.1) # Allow time for the mock to receive and process the request
assert mockDevice.getVoltsPerDivision(channel) == value
|