summaryrefslogtreecommitdiffstats
path: root/lab_control/test/jds6600_unittest.py
diff options
context:
space:
mode:
Diffstat (limited to 'lab_control/test/jds6600_unittest.py')
-rw-r--r--lab_control/test/jds6600_unittest.py99
1 files changed, 99 insertions, 0 deletions
diff --git a/lab_control/test/jds6600_unittest.py b/lab_control/test/jds6600_unittest.py
new file mode 100644
index 0000000..c3b283b
--- /dev/null
+++ b/lab_control/test/jds6600_unittest.py
@@ -0,0 +1,99 @@
+import pytest
+
+from lab_control.jds6600 import JDS6600
+from lab_control.test.mock_jds6600_device import MockJDS6600Device
+from lab_control.connection.direct_connection import DirectConnection as MockConnection
+
+@pytest.fixture
+def mockDevice():
+ return MockJDS6600Device()
+
+@pytest.fixture
+def mockConnection(mockDevice):
+ return MockConnection(mockDevice._handleRequest)
+
+@pytest.fixture
+def uut(mockConnection):
+ return JDS6600("", mockConnection)
+
+def checkNumericalParameter(testValues, writeValue, valueInMock):
+ for ch in JDS6600.AVAILABLE_CHANNELS:
+ assert valueInMock(ch) is None
+
+ for value in testValues:
+ writeValue(ch, value)
+ assert valueInMock(ch) == value
+
+def checkInvalidNumericalParameter(testValues, writeValue, valueInMock):
+ for ch in JDS6600.AVAILABLE_CHANNELS:
+ for value in testValues:
+ with pytest.raises(AssertionError):
+ writeValue(ch, value)
+
+def test_serialPortConfiguration(mockConnection):
+ with pytest.raises(AssertionError):
+ mockConnection.checkConfiguration()
+
+ uut = JDS6600("", mockConnection)
+ mockConnection.checkConfiguration()
+
+ uut.closePort()
+
+def test_channelOnAndOff(uut, mockDevice):
+ for ch in JDS6600.AVAILABLE_CHANNELS:
+ assert not mockDevice.isOn(ch)
+ uut.setOn(ch)
+ assert mockDevice.isOn(ch)
+ uut.setOff(ch)
+ assert not mockDevice.isOn(ch)
+
+def test_setFrequency(uut, mockDevice):
+ checkNumericalParameter([0.0, 100.0, 100000.0, 60000000.0], uut.setFrequency, mockDevice.getFrequency)
+
+def test_setInvalidFrequency(uut, mockDevice):
+ checkInvalidNumericalParameter([-10.0, 60000000.1, None], uut.setFrequency, mockDevice.getFrequency)
+
+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):
+ checkInvalidNumericalParameter([-0.1, -10.0, 20.1, None], uut.setAmplitude, mockDevice.getAmplitude)
+
+def test_setFunction(uut, mockDevice):
+ checkNumericalParameter(range(0, 17), uut.setFunction, mockDevice.getFunction)
+
+def test_setInvalidFunction(uut, mockDevice):
+ checkInvalidNumericalParameter([-1, -10, 17, 20, None], uut.setFunction, mockDevice.getFunction)
+
+def test_invalidChannel(uut):
+ testMethods = [uut.setFrequency, uut.setAmplitude, uut.setFunction]
+ for ch in [-1, 0, 3, None]:
+ for method in testMethods:
+ with pytest.raises(AssertionError):
+ method(ch, 0)
+
+ with pytest.raises(AssertionError):
+ uut.setOn(ch)
+
+ with pytest.raises(AssertionError):
+ uut.setOff(ch)
+
+def test_setFrequencySingleFailure(uut, mockDevice):
+ testFrequency = 1000.0
+ testChannel = 1
+ assert mockDevice.getFrequency(testChannel) is None
+
+ mockDevice.injectFailures(1)
+ uut.setFrequency(testChannel, testFrequency)
+
+ assert mockDevice.getFrequency(testChannel) == testFrequency
+
+def test_setFrequencyMultipleFailures(uut, mockDevice):
+ testFrequency = 1000.0
+ testChannel = 1
+ assert mockDevice.getFrequency(testChannel) is None
+
+ mockDevice.injectFailures(2)
+ uut.setFrequency(testChannel, testFrequency)
+
+ assert mockDevice.getFrequency(testChannel) == 0.0