Commit c2017e42 authored by Matias Guijarro's avatar Matias Guijarro
Browse files

tests: added tests for Axis .enable()/.disable()

parent 1729589b
......@@ -1067,15 +1067,16 @@ def test_invalid_config(beacon):
invalid_cfg["velocity"] = 1
with pytest.raises(RuntimeError) as exc:
invalid_mot.position # lazy init
invalid_mot.enable() # lazy init
assert "acceleration" in str(exc.value)
invalid_cfg["acceleration"] = 1
with pytest.raises(RuntimeError) as exc:
invalid_mot.position # lazy init
invalid_mot.enable() # lazy init
assert "steps_per_unit" in str(exc.value)
invalid_cfg["steps_per_unit"] = 1
invalid_mot.enable()
assert invalid_mot.position == 0
......
......@@ -7,6 +7,7 @@
import sys
import os
import pytest
from unittest import mock
from bliss.config import channels
from bliss.config.static import get_config
......@@ -76,3 +77,68 @@ def test_motor_shared(beacon):
roby2 = config.get("roby")
roby2.__info__()
roby1.stop()
def test_axis_disable_broken_init(default_session):
def faulty_initialize(*args, **kwargs):
raise RuntimeError("FAILED TO INITIALIZE")
with mock.patch(
"bliss.controllers.motors.mockup.Mockup.initialize_axis",
wraps=faulty_initialize,
):
roby = default_session.config.get("roby")
with pytest.raises(RuntimeError):
roby.state
assert roby.disabled
# try to enable while motor cannot be initialized still
with pytest.raises(RuntimeError):
roby.enable()
assert roby.disabled
assert roby.disabled
# motor stays disabled until .enable() is called
# all calls doing a lazy init will fail immediately
# without accessing hw
roby.enable()
assert "READY" in roby.state
assert not roby.disabled
def test_broken_controller_init(default_session):
def faulty_initialize(*args, **kwargs):
raise RuntimeError("FAILED TO INITIALIZE")
with mock.patch(
"bliss.controllers.motors.mockup.Mockup.initialize", wraps=faulty_initialize
):
with pytest.raises(RuntimeError):
default_session.config.get("roby")
with pytest.raises(RuntimeError, match="Controller is disabled"):
default_session.config.get("roby")
with mock.patch(
"bliss.controllers.motors.mockup.Mockup.initialize_hardware",
wraps=faulty_initialize,
):
roby = default_session.config.get("roby")
assert roby
with pytest.raises(RuntimeError):
roby.position # will call initialize_hardware => will fail
# axis roby stays disabled
# controller stays disabled
# roby and robu are on the same controller ;
# controller is disabled because hardware init failed
with pytest.raises(RuntimeError, match="Controller is disabled"):
default_session.config.get("robu")
with pytest.raises(RuntimeError, match="Axis roby is disabled"):
# axis is already disabled
roby.position
with pytest.raises(RuntimeError, match="Controller is disabled"):
roby.enable()
......@@ -9,10 +9,10 @@
- plugin: emotion
class: DummyCtrl
package: test_motor_initialization
package: test_initialization
axes:
- name: dummy_axis_1
steps_per_unit: 1
velocity: 1
acceleration: 1
\ No newline at end of file
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