Commit 13c2d364 authored by Matias Guijarro's avatar Matias Guijarro
Browse files

test for issue 1788, adapt mockup controller and tests to previous

changes
parent be50f041
......@@ -623,6 +623,20 @@ class FaultyMockup(Mockup):
else:
return Mockup.state(self, axis)
def _check_hw_limits(self, axis):
ll, hl = self._Mockup__hw_limit
pos = super().read_position(axis)
if pos <= ll:
return AxisState("READY", "LIMNEG")
elif pos >= hl:
return AxisState("READY", "LIMPOS")
if self._hw_state.OFF:
return AxisState("OFF")
else:
s = AxisState(self._hw_state)
s.set("READY")
return s
def start_one(self, motion, **kw):
self.state_msg_index = 0
if self.bad_start:
......
......@@ -314,18 +314,17 @@ def test_hardware_limits(roby):
with pytest.raises(RuntimeError):
roby.move(3)
assert roby.position == 2
assert pytest.approx(roby.position) == 2
# move hit limit because of backlash
with pytest.raises(RuntimeError):
roby.move(0)
assert pytest.approx(roby.position) == 0
roby.move(1)
assert roby.position == 1
with pytest.raises(RuntimeError):
roby.move(-3)
assert roby.position == 0
finally:
roby.controller.set_hw_limits(roby, None, None)
......@@ -456,11 +455,27 @@ def test_backlash(roby):
roby.move(-10)
def test_interrupted_backlash(roby):
roby.move(-1, wait=False)
roby._group_move._backlash_started_event.wait()
# have to kill twice because backlash move is protected
roby._group_move._move_task.kill(KeyboardInterrupt, block=False)
roby._group_move._move_task.kill(KeyboardInterrupt, block=False)
with pytest.raises(KeyboardInterrupt):
roby.wait_move()
# backlash move is interrupted before it finishes
assert roby.position < -1
assert "READY" in roby.state
def test_backlash2(roby):
roby.move(10, wait=False)
roby.move(1, wait=False)
assert roby.backlash_move == 0
roby.wait_move()
assert roby.position == 10
assert roby.position == 1
def test_backlash3(roby):
......@@ -491,12 +506,17 @@ def test_backlash4(roby):
def test_backlash_stop(roby):
roby.move(-10, wait=False)
assert roby.backlash_move == -12
pos = roby._hw_position
roby.stop()
t = time.time()
roby.acctime = 0.1
roby.move(-1000, wait=False)
assert roby.backlash_move == -1002
time.sleep(0.2)
# calculate stop position
roby.stop(wait=False)
stop_pos = roby._hw_position - roby.acceleration * 0.5 * roby.acctime ** 2
roby.wait_move()
assert pytest.approx(roby.dial, 1e-1) == pos + roby.backlash
assert pytest.approx(roby.dial, 1e-1) == stop_pos + roby.backlash
assert roby._set_position == roby.dial
assert roby.state.READY
......
......@@ -46,8 +46,8 @@ def test_state_failure(bad_motor, monkeypatch):
state_index = bad_motor.controller.state_msg_index
assert str(exc.value) == "BAD STATE 1"
assert len(infos) == 3
assert str(infos[0][1]) == "BAD STATE %d" % (state_index - 2)
assert len(infos) == 1
assert str(infos[0][1]) == "BAD STATE %d" % state_index
assert "FAULT" in bad_motor.state
with pytest.raises(RuntimeError):
......
......@@ -130,7 +130,7 @@ def test_wm_exception(default_session, capsys):
def test_sta_normal(default_session, capsys):
bad = default_session.config.get("bad")
bad.controller.bad_position = False
bad.controller.bad_state = False
sta()
captured = capsys.readouterr()
......@@ -153,7 +153,7 @@ def test_sta_slits(s1hg, capsys):
def test_sta_exception(default_session, capsys):
bad = default_session.config.get("bad")
bad.controller.bad_position = True
bad.controller.bad_state = True
sta()
captured = capsys.readouterr()
......@@ -166,13 +166,13 @@ def test_sta_exception(default_session, capsys):
errmsg = "Traceback (most recent call last):\n"
assert errmsg in captured.err
errmsg = "RuntimeError: Error on motor 'bad': BAD POSITION\n"
errmsg = "RuntimeError: Error on motor 'bad': BAD STATE"
assert errmsg in captured.err
def test_stm_normal(default_session, capsys):
bad = default_session.config.get("bad")
bad.controller.bad_position = False
bad.controller.bad_state = False
stm("bad")
captured = capsys.readouterr()
......@@ -185,7 +185,7 @@ def test_stm_normal(default_session, capsys):
def test_stm_exception(default_session, capsys):
bad = default_session.config.get("bad")
bad.controller.bad_position = True
bad.controller.bad_state = True
stm("bad")
captured = capsys.readouterr()
......@@ -198,7 +198,7 @@ def test_stm_exception(default_session, capsys):
errmsg = "Traceback (most recent call last):\n"
assert errmsg in captured.err
errmsg = "RuntimeError: Error on motor 'bad': BAD POSITION\n"
errmsg = "RuntimeError: Error on motor 'bad': BAD STATE"
assert errmsg in captured.err
......
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