Commit e18a7ecb authored by alisec's avatar alisec
Browse files

increased coverage

parent 00394596
......@@ -279,6 +279,7 @@ def test_laser_stop(started_laser):
def test_laser_on(started_laser, laser_config):
com, las = started_laser
# normal case
com.put_text(las.AnswersStatus.READY.value)
com.put_text(las.AnswersStatus.ACTIVE.value)
com.put_text("")
......@@ -286,9 +287,20 @@ def test_laser_on(started_laser, laser_config):
las.laser_on()
assert com.get_written() == "LASER ON"
assert las.laser_status == las.LaserStatus.READ_ACTIVE
# case laser not ready
las.laser_status = las.LaserStatus.UNREADY_INACTIVE
with pytest.raises(dev.CryLasLaserNotReadyError):
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.AnswersShutter.CLOSED.value)
las.stop()
......@@ -337,31 +349,54 @@ def test_laser_on(started_laser, laser_config):
def test_laser_off(started_laser):
com, las = started_laser
# normal case
las.laser_status = las.LaserStatus.READ_ACTIVE
com.put_text(las.AnswersStatus.INACTIVE.value)
las.laser_off()
assert com.get_written() == "LASER OFF"
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.AnswersShutter.CLOSED.value)
def test_laser_open_shutter(started_laser):
com, las = started_laser
# normal case
com.put_text(las.AnswersShutter.OPENED.value)
las.open_shutter()
assert com.get_written() == "Shutter 1"
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.AnswersShutter.CLOSED.value)
def test_laser_close_shutter(started_laser):
com, las = started_laser
# normal case
com.put_text(las.AnswersShutter.CLOSED.value)
las.close_shutter()
assert com.get_written() == "Shutter 0"
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.AnswersShutter.CLOSED.value)
......@@ -391,6 +426,11 @@ def test_laser_set_init_shutter_status(laser_com_config, laser_config):
laser_config["init_shutter_status"] = dev.CryLasLaserConfig.ShutterStatus.OPENED
las = dev.CryLasLaser(com, laser_config)
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)
las.set_init_shutter_status()
# teardown
......@@ -466,6 +506,10 @@ def test_laser_update_repetition_rate(started_laser):
com.put_text("Impuls=disabled, extern Trigger")
las.update_repetition_rate()
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):
las.update_repetition_rate()
# teardown
......@@ -519,6 +563,14 @@ def test_laser_set_repetition_rate(started_laser):
# check value Error
with pytest.raises(ValueError):
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.AnswersShutter.CLOSED.value)
......@@ -541,6 +593,11 @@ def test_laser_set_pulse_energy(started_laser):
with pytest.raises(dev.CryLasLaserError):
las.set_pulse_energy(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.AnswersShutter.CLOSED.value)
......@@ -652,6 +709,7 @@ def test_attenuator_set_attenuation(started_attenuator):
com, att = started_attenuator
com.put_bytes(bytes([0, 0]))
att.set_attenuation(50)
assert att.attenuation == 50
com.put_bytes(bytes([1, 0]))
with pytest.raises(dev.CryLasAttenuatorError):
att.set_attenuation(50)
......@@ -685,6 +743,7 @@ def test_attenuator_set_transmission(started_attenuator):
com, att = started_attenuator
com.put_bytes(bytes([0, 0]))
att.set_transmission(50)
assert att.transmission == 50
com.put_bytes(bytes([1, 0]))
with pytest.raises(dev.CryLasAttenuatorError):
att.set_transmission(50)
......
Supports Markdown
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