To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit bbc85442 authored by alisec's avatar alisec
Browse files

added raises annotations and increased coverage

parent a12b72da
Pipeline #52519 failed with stages
...@@ -250,6 +250,7 @@ class PfeifferTPG(SingleCommDevice): ...@@ -250,6 +250,7 @@ class PfeifferTPG(SingleCommDevice):
Send identification request TID to sensors on all channels. Send identification request TID to sensors on all channels.
:raises SerialCommunicationIOError: when communication port is not opened :raises SerialCommunicationIOError: when communication port is not opened
:raises PfeifferTPGError: if command fails
""" """
try: try:
...@@ -274,6 +275,7 @@ class PfeifferTPG(SingleCommDevice): ...@@ -274,6 +275,7 @@ class PfeifferTPG(SingleCommDevice):
Set the unit in which the measurements are shown on the display. Set the unit in which the measurements are shown on the display.
:raises SerialCommunicationIOError: when communication port is not opened :raises SerialCommunicationIOError: when communication port is not opened
:raises PfeifferTPGError: if command fails
""" """
if not isinstance(unit, self.PressureUnits): if not isinstance(unit, self.PressureUnits):
...@@ -296,6 +298,7 @@ class PfeifferTPG(SingleCommDevice): ...@@ -296,6 +298,7 @@ class PfeifferTPG(SingleCommDevice):
:return: measured value as float if measurement successful, :return: measured value as float if measurement successful,
sensor status as string if not sensor status as string if not
:raises SerialCommunicationIOError: when communication port is not opened :raises SerialCommunicationIOError: when communication port is not opened
:raises PfeifferTPGError: if command fails
""" """
if not 1 <= channel <= self.number_of_sensors: if not 1 <= channel <= self.number_of_sensors:
...@@ -328,6 +331,7 @@ class PfeifferTPG(SingleCommDevice): ...@@ -328,6 +331,7 @@ class PfeifferTPG(SingleCommDevice):
:return: list of measured values as float if measurements successful, :return: list of measured values as float if measurements successful,
and or sensor status as strings if not and or sensor status as strings if not
:raises SerialCommunicationIOError: when communication port is not opened :raises SerialCommunicationIOError: when communication port is not opened
:raises PfeifferTPGError: if command fails
""" """
try: try:
...@@ -350,6 +354,7 @@ class PfeifferTPG(SingleCommDevice): ...@@ -350,6 +354,7 @@ class PfeifferTPG(SingleCommDevice):
:param fsr: list of full scale range values, like [0, 1, 3, 3, 2, 0] :param fsr: list of full scale range values, like [0, 1, 3, 3, 2, 0]
:raises SerialCommunicationIOError: when communication port is not opened :raises SerialCommunicationIOError: when communication port is not opened
:raises PfeifferTPGError: if command fails
""" """
wrong_values = [v for v in fsr wrong_values = [v for v in fsr
...@@ -378,6 +383,7 @@ class PfeifferTPG(SingleCommDevice): ...@@ -378,6 +383,7 @@ class PfeifferTPG(SingleCommDevice):
:return: list of full scale range values, like [0, 1, 3, 3, 2, 0] :return: list of full scale range values, like [0, 1, 3, 3, 2, 0]
:raises SerialCommunicationIOError: when communication port is not opened :raises SerialCommunicationIOError: when communication port is not opened
:raises PfeifferTPGError: if command fails
""" """
try: try:
...@@ -406,6 +412,7 @@ class PfeifferTPG(SingleCommDevice): ...@@ -406,6 +412,7 @@ class PfeifferTPG(SingleCommDevice):
:param fsr: full scale range values in mbar, for example [0.01, 1000] :param fsr: full scale range values in mbar, for example [0.01, 1000]
:raises SerialCommunicationIOError: when communication port is not opened :raises SerialCommunicationIOError: when communication port is not opened
:raises PfeifferTPGError: if command fails
""" """
wrong_values = [v for v in fsr if v not in self.config.model.full_scale_ranges] wrong_values = [v for v in fsr if v not in self.config.model.full_scale_ranges]
...@@ -434,6 +441,7 @@ class PfeifferTPG(SingleCommDevice): ...@@ -434,6 +441,7 @@ class PfeifferTPG(SingleCommDevice):
:return: full scale range values in mbar, like [0.01, 1, 0.1, 1000, 50000, 10] :return: full scale range values in mbar, like [0.01, 1, 0.1, 1000, 50000, 10]
:raises SerialCommunicationIOError: when communication port is not opened :raises SerialCommunicationIOError: when communication port is not opened
:raises PfeifferTPGError: if command fails
""" """
try: try:
......
...@@ -46,6 +46,17 @@ def started_pfeiffer_tpg(com_config, dev_config): ...@@ -46,6 +46,17 @@ def started_pfeiffer_tpg(com_config, dev_config):
def test_pfeiffer_tpg_instantiation(com_config, dev_config): def test_pfeiffer_tpg_instantiation(com_config, dev_config):
pg = dev.PfeifferTPG(com_config, dev_config) pg = dev.PfeifferTPG(com_config, dev_config)
assert pg is not None assert pg is not None
assert pg.unit == "mbar"
# another valid config
config_dict = dict(dev_config)
config_dict['model'] = 'TPGx6x'
dev.PfeifferTPG(com_config, config_dict)
# wrong config
config_dict['model'] = 'wrong_name'
with pytest.raises(ValueError):
dev.PfeifferTPG(com_config, config_dict)
def test_com_send_command(com_config): def test_com_send_command(com_config):
...@@ -54,6 +65,7 @@ def test_com_send_command(com_config): ...@@ -54,6 +65,7 @@ def test_com_send_command(com_config):
com.put_text(chr(6)) com.put_text(chr(6))
com.send_command('this is the command') com.send_command('this is the command')
assert com.get_written() == 'this is the command' assert com.get_written() == 'this is the command'
com.put_text('not an acknowledgement')
with pytest.raises(dev.PfeifferTPGError): with pytest.raises(dev.PfeifferTPGError):
com.send_command('this command is not acknowledged') com.send_command('this command is not acknowledged')
com.close() com.close()
...@@ -67,6 +79,7 @@ def test_com_query(com_config): ...@@ -67,6 +79,7 @@ def test_com_query(com_config):
assert com.query('this is the query') == 'this is the answer' assert com.query('this is the query') == 'this is the answer'
assert com.get_written() == 'this is the query' assert com.get_written() == 'this is the query'
assert com.get_written() == chr(5) assert com.get_written() == chr(5)
com.put_text('not an acknowledgement')
with pytest.raises(dev.PfeifferTPGError): with pytest.raises(dev.PfeifferTPGError):
com.query('this query is not acknowledged') com.query('this query is not acknowledged')
com.put_text(chr(6)) com.put_text(chr(6))
...@@ -118,7 +131,7 @@ def test_pfeiffer_com_error(com_config, dev_config): ...@@ -118,7 +131,7 @@ def test_pfeiffer_com_error(com_config, dev_config):
def test_identify_sensors(started_pfeiffer_tpg): def test_identify_sensors(started_pfeiffer_tpg):
com, pg = started_pfeiffer_tpg com, pg = started_pfeiffer_tpg
# test 2 possible answers + 1 unexpected answer: # example with 3 sensors
com.put_text(chr(6)) com.put_text(chr(6))
com.put_text(','.join([dev.PfeifferTPG.SensorTypes.PKR.name, com.put_text(','.join([dev.PfeifferTPG.SensorTypes.PKR.name,
dev.PfeifferTPG.SensorTypes.CMR.name, dev.PfeifferTPG.SensorTypes.CMR.name,
...@@ -130,6 +143,10 @@ def test_identify_sensors(started_pfeiffer_tpg): ...@@ -130,6 +143,10 @@ def test_identify_sensors(started_pfeiffer_tpg):
assert pg.sensors[0] == dev.PfeifferTPG.SensorTypes.PKR.name assert pg.sensors[0] == dev.PfeifferTPG.SensorTypes.PKR.name
assert pg.sensors[1] == dev.PfeifferTPG.SensorTypes.CMR.name assert pg.sensors[1] == dev.PfeifferTPG.SensorTypes.CMR.name
assert pg.sensors[2] == dev.PfeifferTPG.SensorTypes.IKR.name assert pg.sensors[2] == dev.PfeifferTPG.SensorTypes.IKR.name
# wrong answer from device
com.put_text('this will make the command fail')
with pytest.raises(dev.PfeifferTPGError):
pg.identify_sensors()
def test_set_display_unit(started_pfeiffer_tpg): def test_set_display_unit(started_pfeiffer_tpg):
...@@ -140,6 +157,10 @@ def test_set_display_unit(started_pfeiffer_tpg): ...@@ -140,6 +157,10 @@ def test_set_display_unit(started_pfeiffer_tpg):
# valid PressureUnits argument # valid PressureUnits argument
com.put_text(chr(6)) com.put_text(chr(6))
pg.set_display_unit(pg.PressureUnits.Pascal) pg.set_display_unit(pg.PressureUnits.Pascal)
# valid PressureUnits argument but no acknowledgment from device
com.put_text('not an acknowledgment')
with pytest.raises(dev.PfeifferTPGError):
pg.set_display_unit(pg.PressureUnits.Pascal)
# invalid str argument # invalid str argument
with pytest.raises(ValueError): with pytest.raises(ValueError):
pg.set_display_unit("Not an accepted unit") pg.set_display_unit("Not an accepted unit")
...@@ -177,6 +198,13 @@ def test_measure(started_pfeiffer_tpg): ...@@ -177,6 +198,13 @@ def test_measure(started_pfeiffer_tpg):
com.put_text(f"{dev.PfeifferTPG.SensorStatus.Identification_error.value},1.234E-02") com.put_text(f"{dev.PfeifferTPG.SensorStatus.Identification_error.value},1.234E-02")
assert pg.measure(2) == (dev.PfeifferTPG.SensorStatus.Identification_error.name, assert pg.measure(2) == (dev.PfeifferTPG.SensorStatus.Identification_error.name,
1.234e-2) 1.234e-2)
# wrong channel
with pytest.raises(ValueError):
pg.measure(12)
# no acknowledgment from device
com.put_text('not an acknowledgment')
with pytest.raises(dev.PfeifferTPGError):
pg.measure(1)
def test_measure_all(started_pfeiffer_tpg): def test_measure_all(started_pfeiffer_tpg):
...@@ -189,6 +217,10 @@ def test_measure_all(started_pfeiffer_tpg): ...@@ -189,6 +217,10 @@ def test_measure_all(started_pfeiffer_tpg):
1.234e-2), 1.234e-2),
(dev.PfeifferTPG.SensorStatus.Ok.name, 1.234e-2)] (dev.PfeifferTPG.SensorStatus.Ok.name, 1.234e-2)]
assert com.get_written() == 'PRX' assert com.get_written() == 'PRX'
# no acknowledgment from device
com.put_text('not an acknowledgment')
with pytest.raises(dev.PfeifferTPGError):
pg.measure_all()
def test_set_full_scale_unitless(started_pfeiffer_tpg): def test_set_full_scale_unitless(started_pfeiffer_tpg):
...@@ -196,6 +228,18 @@ def test_set_full_scale_unitless(started_pfeiffer_tpg): ...@@ -196,6 +228,18 @@ def test_set_full_scale_unitless(started_pfeiffer_tpg):
com.put_text(chr(6)) com.put_text(chr(6))
pg.set_full_scale_unitless([1, 2]) pg.set_full_scale_unitless([1, 2])
assert com.get_written() == 'FSR,1,2' assert com.get_written() == 'FSR,1,2'
# no acknowledgment from device
com.put_text('not an acknowledgment')
with pytest.raises(dev.PfeifferTPGError):
pg.set_full_scale_unitless([1, 2])
# wrong values
com.put_text(chr(6))
with pytest.raises(ValueError):
pg.set_full_scale_unitless([12, 24])
# wrong number of values
com.put_text(chr(6))
with pytest.raises(ValueError):
pg.set_full_scale_unitless([12, 24, 32])
def test_get_full_scale_unitless(started_pfeiffer_tpg): def test_get_full_scale_unitless(started_pfeiffer_tpg):
...@@ -204,6 +248,15 @@ def test_get_full_scale_unitless(started_pfeiffer_tpg): ...@@ -204,6 +248,15 @@ def test_get_full_scale_unitless(started_pfeiffer_tpg):
com.put_text('2,0') com.put_text('2,0')
assert pg.get_full_scale_unitless() == [2, 0] assert pg.get_full_scale_unitless() == [2, 0]
assert com.get_written() == 'FSR' assert com.get_written() == 'FSR'
# no acknowledgment from device
com.put_text('not an acknowledgment')
with pytest.raises(dev.PfeifferTPGError):
pg.get_full_scale_unitless()
# wrong answer from device
com.put_text(chr(6))
com.put_text('12,24')
with pytest.raises(dev.PfeifferTPGError):
pg.get_full_scale_unitless()
def test_set_full_scale_mbar(started_pfeiffer_tpg): def test_set_full_scale_mbar(started_pfeiffer_tpg):
...@@ -212,6 +265,18 @@ def test_set_full_scale_mbar(started_pfeiffer_tpg): ...@@ -212,6 +265,18 @@ def test_set_full_scale_mbar(started_pfeiffer_tpg):
pg.set_full_scale_mbar([100, 1]) pg.set_full_scale_mbar([100, 1])
fsr = pg.config.model.full_scale_ranges fsr = pg.config.model.full_scale_ranges
assert com.get_written() == f'FSR,{fsr[100]},{fsr[1]}' assert com.get_written() == f'FSR,{fsr[100]},{fsr[1]}'
# no acknowledgment from device
com.put_text('not an acknowledgment')
with pytest.raises(dev.PfeifferTPGError):
pg.set_full_scale_mbar([100, 1])
# wrong values
com.put_text(chr(6))
with pytest.raises(ValueError):
pg.set_full_scale_mbar([12, 24])
# wrong number of values
com.put_text(chr(6))
with pytest.raises(ValueError):
pg.set_full_scale_mbar([12, 24, 32])
def test_get_full_scale_mbar(started_pfeiffer_tpg): def test_get_full_scale_mbar(started_pfeiffer_tpg):
...@@ -221,3 +286,12 @@ def test_get_full_scale_mbar(started_pfeiffer_tpg): ...@@ -221,3 +286,12 @@ def test_get_full_scale_mbar(started_pfeiffer_tpg):
fsr_rev = pg.config.model.full_scale_ranges_reversed fsr_rev = pg.config.model.full_scale_ranges_reversed
assert pg.get_full_scale_mbar() == [fsr_rev[2], fsr_rev[0]] assert pg.get_full_scale_mbar() == [fsr_rev[2], fsr_rev[0]]
assert com.get_written() == 'FSR' assert com.get_written() == 'FSR'
# no acknowledgment from device
com.put_text('not an acknowledgment')
with pytest.raises(dev.PfeifferTPGError):
pg.get_full_scale_mbar()
# wrong answer from device
com.put_text(chr(6))
com.put_text('12,24')
with pytest.raises(dev.PfeifferTPGError):
pg.get_full_scale_mbar()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment