diff options
author | Eddy Pedroni <eddy@0xf7.com> | 2022-05-30 20:20:18 +0200 |
---|---|---|
committer | Eddy Pedroni <eddy@0xf7.com> | 2022-05-30 20:20:18 +0200 |
commit | d74da5609919e8e57c126b5a66ee40a29d4f7c28 (patch) | |
tree | 6d44613a7fbed9ad61be48030c3725b92ed923ad /lab_control/test | |
parent | 6b6c40b153890ef54ec0c9aa4976e604b14e89cb (diff) |
Added error handling to JDS6600 test cases
Diffstat (limited to 'lab_control/test')
-rw-r--r-- | lab_control/test/jds6600_test.py | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/lab_control/test/jds6600_test.py b/lab_control/test/jds6600_test.py index 256a5d0..c53388a 100644 --- a/lab_control/test/jds6600_test.py +++ b/lab_control/test/jds6600_test.py @@ -3,8 +3,6 @@ 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() @@ -17,14 +15,19 @@ def uut(mockDevice): yield uut uut.closePort() -def checkNumericalParameter(testValues, writeValue, valueInMock, expectValid=True): - for ch in AVAILABLE_CHANNELS: +def checkNumericalParameter(testValues, writeValue, valueInMock): + for ch in JDS6600.AVAILABLE_CHANNELS: assert valueInMock(ch) == None for value in testValues: writeValue(ch, value) - expectedValue = value if expectValid else None - assert valueInMock(ch) == expectedValue + 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_serialConfiguration(mockDevice): with pytest.raises(AssertionError): @@ -34,7 +37,7 @@ def test_serialConfiguration(mockDevice): mockDevice.checkPortConfiguration() def test_channelOnAndOff(uut, mockDevice): - for ch in AVAILABLE_CHANNELS: + for ch in JDS6600.AVAILABLE_CHANNELS: assert not mockDevice.isOn(ch) uut.setOn(ch) assert mockDevice.isOn(ch) @@ -45,17 +48,29 @@ 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) + 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): - checkNumericalParameter([-0.1, -10.0, 20.1, None], uut.setAmplitude, mockDevice.getAmplitude, expectValid=False) + 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): - checkNumericalParameter([-1, -10, 17, 20, None], uut.setFunction, mockDevice.getFunction, expectValid=False) + 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) |