summaryrefslogtreecommitdiffstats
path: root/lab_control/test/jds6600_test.py
blob: 256a5d040c1578399b91995499cbf79cc889a352 (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
51
52
53
54
55
56
57
58
59
60
61
import pytest

from lab_control.jds6600 import JDS6600
from lab_control.test.mock_jds6600_device import MockJDS6600Device

AVAILABLE_CHANNELS = [1, 2]

@pytest.fixture
def mockDevice():
    d = MockJDS6600Device()
    yield d
    d.stop()

@pytest.fixture
def uut(mockDevice):
    uut = JDS6600(mockDevice.getPortName())
    yield uut
    uut.closePort()

def checkNumericalParameter(testValues, writeValue, valueInMock, expectValid=True):
    for ch in AVAILABLE_CHANNELS:
        assert valueInMock(ch) == None

        for value in testValues:
            writeValue(ch, value)
            expectedValue = value if expectValid else None
            assert valueInMock(ch) == expectedValue

def test_serialConfiguration(mockDevice):
    with pytest.raises(AssertionError):
        mockDevice.checkPortConfiguration()

    uut = JDS6600(mockDevice.getPortName())
    mockDevice.checkPortConfiguration()

def test_channelOnAndOff(uut, mockDevice):
    for ch in AVAILABLE_CHANNELS:
        assert not mockDevice.isOn(ch)
        uut.setOn(ch)
        assert mockDevice.isOn(ch)
        uut.setOff(ch)
        assert not mockDevice.isOn(ch)

def disabled_test_setFrequency(uut, mockDevice):
    checkNumericalParameter([0.0, 100.0, 100000.0], uut.setFrequency, mockDevice.getFrequency)
    
def test_setInvalidFrequency(uut, mockDevice):
    checkNumericalParameter([-10.0, 60000000.1, None], uut.setFrequency, mockDevice.getFrequency, expectValid=False)

def test_setAmplitude(uut, mockDevice):
    checkNumericalParameter([0.0, 0.1, 1.0, 10.0, 20.0], uut.setAmplitude, mockDevice.getAmplitude)

def test_setInvalidAmplitude(uut, mockDevice):
    checkNumericalParameter([-0.1, -10.0, 20.1, None], uut.setAmplitude, mockDevice.getAmplitude, expectValid=False)

def test_setFunction(uut, mockDevice):
    checkNumericalParameter(range(0, 17), uut.setFunction, mockDevice.getFunction)

def test_setInvalidFunction(uut, mockDevice):
    checkNumericalParameter([-1, -10, 17, 20, None], uut.setFunction, mockDevice.getFunction, expectValid=False)