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 7602bf71 authored by mikolajr's avatar mikolajr
Browse files

Merge branch '34-increase-tests-code-coverage-for-crylas-devices' into 'devel'

Resolve "Increase tests code coverage for CryLas devices"

Closes #34

See merge request !34
parents 5011ec34 a8449810
Pipeline #53143 passed with stages
in 3 minutes and 1 second
...@@ -327,7 +327,7 @@ class CryLasLaser(SingleCommDevice): ...@@ -327,7 +327,7 @@ class CryLasLaser(SingleCommDevice):
self._poll_until_ready, self._polling_stop_event self._poll_until_ready, self._polling_stop_event
) )
def _wait_for_pollling_result(self): def _wait_for_polling_result(self):
""" """
Wait for until polling function returns a result. Wait for until polling function returns a result.
...@@ -345,7 +345,7 @@ class CryLasLaser(SingleCommDevice): ...@@ -345,7 +345,7 @@ class CryLasLaser(SingleCommDevice):
""" """
# use the event to stop the thread # use the event to stop the thread
self._polling_stop_event.set() self._polling_stop_event.set()
return self._wait_for_pollling_result() return self._wait_for_polling_result()
def _poll_until_ready(self, stop_event) -> None: def _poll_until_ready(self, stop_event) -> None:
""" """
...@@ -401,7 +401,7 @@ class CryLasLaser(SingleCommDevice): ...@@ -401,7 +401,7 @@ class CryLasLaser(SingleCommDevice):
if not self._is_polling(): if not self._is_polling():
self._start_polling() self._start_polling()
logging.info("Waiting until the laser is ready...") logging.info("Waiting until the laser is ready...")
self._wait_for_pollling_result() self._wait_for_polling_result()
else: else:
logging.info("No need waiting, the laser is already ready.") logging.info("No need waiting, the laser is already ready.")
......
...@@ -281,6 +281,7 @@ def test_laser_stop(started_laser): ...@@ -281,6 +281,7 @@ def test_laser_stop(started_laser):
def test_laser_on(started_laser, laser_config): def test_laser_on(started_laser, laser_config):
com, las = started_laser com, las = started_laser
# normal case
com.put_text(las.AnswersStatus.READY.value) com.put_text(las.AnswersStatus.READY.value)
com.put_text(las.AnswersStatus.ACTIVE.value) com.put_text(las.AnswersStatus.ACTIVE.value)
com.put_text("") com.put_text("")
...@@ -288,9 +289,20 @@ def test_laser_on(started_laser, laser_config): ...@@ -288,9 +289,20 @@ def test_laser_on(started_laser, laser_config):
las.laser_on() las.laser_on()
assert com.get_written() == "LASER ON" assert com.get_written() == "LASER ON"
assert las.laser_status == las.LaserStatus.READ_ACTIVE assert las.laser_status == las.LaserStatus.READ_ACTIVE
# case laser not ready
las.laser_status = las.LaserStatus.UNREADY_INACTIVE las.laser_status = las.LaserStatus.UNREADY_INACTIVE
with pytest.raises(dev.CryLasLaserNotReadyError): with pytest.raises(dev.CryLasLaserNotReadyError):
las.laser_on() las.laser_on()
# case laser already on
las.laser_status = las.LaserStatus.READ_ACTIVE
com.put_text("Laser is already on")
las.laser_on()
# case command fails
las.laser_status = las.LaserStatus.READY_INACTIVE
com.put_text("The command is not working")
with pytest.raises(dev.CryLasLaserError):
las.laser_on()
# teardown
com.put_text(las.AnswersStatus.INACTIVE.value) com.put_text(las.AnswersStatus.INACTIVE.value)
com.put_text(las.AnswersShutter.CLOSED.value) com.put_text(las.AnswersShutter.CLOSED.value)
las.stop() las.stop()
...@@ -339,31 +351,54 @@ def test_laser_on(started_laser, laser_config): ...@@ -339,31 +351,54 @@ def test_laser_on(started_laser, laser_config):
def test_laser_off(started_laser): def test_laser_off(started_laser):
com, las = started_laser com, las = started_laser
# normal case
las.laser_status = las.LaserStatus.READ_ACTIVE las.laser_status = las.LaserStatus.READ_ACTIVE
com.put_text(las.AnswersStatus.INACTIVE.value) com.put_text(las.AnswersStatus.INACTIVE.value)
las.laser_off() las.laser_off()
assert com.get_written() == "LASER OFF" assert com.get_written() == "LASER OFF"
assert las.laser_status == las.LaserStatus.READY_INACTIVE assert las.laser_status == las.LaserStatus.READY_INACTIVE
# case laser already off
las.laser_status = las.LaserStatus.READY_INACTIVE
com.put_text("Laser is already off")
las.laser_off()
# case command fails
las.laser_status = las.LaserStatus.READ_ACTIVE
com.put_text("The command is not working")
with pytest.raises(dev.CryLasLaserError):
las.laser_off()
# teardown
com.put_text(las.AnswersStatus.INACTIVE.value) com.put_text(las.AnswersStatus.INACTIVE.value)
com.put_text(las.AnswersShutter.CLOSED.value) com.put_text(las.AnswersShutter.CLOSED.value)
def test_laser_open_shutter(started_laser): def test_laser_open_shutter(started_laser):
com, las = started_laser com, las = started_laser
# normal case
com.put_text(las.AnswersShutter.OPENED.value) com.put_text(las.AnswersShutter.OPENED.value)
las.open_shutter() las.open_shutter()
assert com.get_written() == "Shutter 1" assert com.get_written() == "Shutter 1"
assert las.shutter_status == las.ShutterStatus.OPENED assert las.shutter_status == las.ShutterStatus.OPENED
# case command fails
com.put_text("The command is not working")
with pytest.raises(dev.CryLasLaserError):
las.open_shutter()
# teardown
com.put_text(las.AnswersStatus.INACTIVE.value) com.put_text(las.AnswersStatus.INACTIVE.value)
com.put_text(las.AnswersShutter.CLOSED.value) com.put_text(las.AnswersShutter.CLOSED.value)
def test_laser_close_shutter(started_laser): def test_laser_close_shutter(started_laser):
com, las = started_laser com, las = started_laser
# normal case
com.put_text(las.AnswersShutter.CLOSED.value) com.put_text(las.AnswersShutter.CLOSED.value)
las.close_shutter() las.close_shutter()
assert com.get_written() == "Shutter 0" assert com.get_written() == "Shutter 0"
assert las.shutter_status == las.ShutterStatus.CLOSED assert las.shutter_status == las.ShutterStatus.CLOSED
# case command fails
com.put_text("The command is not working")
with pytest.raises(dev.CryLasLaserError):
las.close_shutter()
# teardown
com.put_text(las.AnswersStatus.INACTIVE.value) com.put_text(las.AnswersStatus.INACTIVE.value)
com.put_text(las.AnswersShutter.CLOSED.value) com.put_text(las.AnswersShutter.CLOSED.value)
...@@ -393,6 +428,11 @@ def test_laser_set_init_shutter_status(laser_com_config, laser_config): ...@@ -393,6 +428,11 @@ def test_laser_set_init_shutter_status(laser_com_config, laser_config):
laser_config["init_shutter_status"] = dev.CryLasLaserConfig.ShutterStatus.OPENED laser_config["init_shutter_status"] = dev.CryLasLaserConfig.ShutterStatus.OPENED
las = dev.CryLasLaser(com, laser_config) las = dev.CryLasLaser(com, laser_config)
com.open() com.open()
# test when command succeeds and there is nothing to do
com.put_text(las.AnswersShutter.OPENED.value)
las.set_init_shutter_status()
# test when command succeeds and the laser should be opened
com.put_text(las.AnswersShutter.CLOSED.value)
com.put_text(las.AnswersShutter.OPENED.value) com.put_text(las.AnswersShutter.OPENED.value)
las.set_init_shutter_status() las.set_init_shutter_status()
# teardown # teardown
...@@ -468,6 +508,10 @@ def test_laser_update_repetition_rate(started_laser): ...@@ -468,6 +508,10 @@ def test_laser_update_repetition_rate(started_laser):
com.put_text("Impuls=disabled, extern Trigger") com.put_text("Impuls=disabled, extern Trigger")
las.update_repetition_rate() las.update_repetition_rate()
assert las.repetition_rate == las.RepetitionRates.HARDWARE assert las.repetition_rate == las.RepetitionRates.HARDWARE
com.put_text('no answer to query')
with pytest.raises(dev.CryLasLaserError):
las.update_repetition_rate()
com.put_text('Impuls=enabled but no number provided')
with pytest.raises(dev.CryLasLaserError): with pytest.raises(dev.CryLasLaserError):
las.update_repetition_rate() las.update_repetition_rate()
# teardown # teardown
...@@ -521,6 +565,14 @@ def test_laser_set_repetition_rate(started_laser): ...@@ -521,6 +565,14 @@ def test_laser_set_repetition_rate(started_laser):
# check value Error # check value Error
with pytest.raises(ValueError): with pytest.raises(ValueError):
las.set_repetition_rate(30) las.set_repetition_rate(30)
# command fails
com.put_text("This did not work")
with pytest.raises(dev.CryLasLaserError):
las.set_repetition_rate(10)
# hardware trigger
com.put_text("No answer is expected in this case")
las.set_repetition_rate(0)
# teardown
com.put_text(las.AnswersStatus.INACTIVE.value) com.put_text(las.AnswersStatus.INACTIVE.value)
com.put_text(las.AnswersShutter.CLOSED.value) com.put_text(las.AnswersShutter.CLOSED.value)
...@@ -543,6 +595,11 @@ def test_laser_set_pulse_energy(started_laser): ...@@ -543,6 +595,11 @@ def test_laser_set_pulse_energy(started_laser):
with pytest.raises(dev.CryLasLaserError): with pytest.raises(dev.CryLasLaserError):
las.set_pulse_energy(val) las.set_pulse_energy(val)
assert com.get_written() == "BOO SE {}".format(cmd_val) assert com.get_written() == "BOO SE {}".format(cmd_val)
# case command fails
com.put_text("The command failed")
with pytest.raises(dev.CryLasLaserError):
las.set_pulse_energy(val)
# teardown
com.put_text(las.AnswersStatus.INACTIVE.value) com.put_text(las.AnswersStatus.INACTIVE.value)
com.put_text(las.AnswersShutter.CLOSED.value) com.put_text(las.AnswersShutter.CLOSED.value)
...@@ -654,6 +711,7 @@ def test_attenuator_set_attenuation(started_attenuator): ...@@ -654,6 +711,7 @@ def test_attenuator_set_attenuation(started_attenuator):
com, att = started_attenuator com, att = started_attenuator
com.put_bytes(bytes([0, 0])) com.put_bytes(bytes([0, 0]))
att.set_attenuation(50) att.set_attenuation(50)
assert att.attenuation == 50
com.put_bytes(bytes([1, 0])) com.put_bytes(bytes([1, 0]))
with pytest.raises(dev.CryLasAttenuatorError): with pytest.raises(dev.CryLasAttenuatorError):
att.set_attenuation(50) att.set_attenuation(50)
...@@ -687,6 +745,7 @@ def test_attenuator_set_transmission(started_attenuator): ...@@ -687,6 +745,7 @@ def test_attenuator_set_transmission(started_attenuator):
com, att = started_attenuator com, att = started_attenuator
com.put_bytes(bytes([0, 0])) com.put_bytes(bytes([0, 0]))
att.set_transmission(50) att.set_transmission(50)
assert att.transmission == 50
com.put_bytes(bytes([1, 0])) com.put_bytes(bytes([1, 0]))
with pytest.raises(dev.CryLasAttenuatorError): with pytest.raises(dev.CryLasAttenuatorError):
att.set_transmission(50) att.set_transmission(50)
......
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