Commit 4c1e91df authored by Matias Guijarro's avatar Matias Guijarro

moved motor hardware (IcePAP, PI, Galil etc) tests to motors_hw

new pytest-based tests in motors/
moved TestLogging to misc/
moved TestLinkam to temperature/
moved TestTcpComm to comm/
parent 2eae59f9
......@@ -259,10 +259,10 @@ class Mockup(Controller):
ON / OFF
"""
def set_on(self, axis):
self._hw_status = "READY"
self._hw_status.set("READY")
def set_off(self, axis):
self._hw_status = "OFF"
self._hw_status.set("OFF")
"""
Hard limits
......
# -*- coding: utf-8 -*-
#
# This file is part of the bliss project
#
# Copyright (c) 2016 Beamline Control Unit, ESRF
# Distributed under the GNU LGPLv3. See LICENSE for more info.
import pytest
import time
from bliss.common import event
from bliss.common.standard import Group
def test_group_move(robz, roby):
robz_pos = robz.position()
roby_pos = roby.position()
grp = Group(robz, roby)
assert grp.state() == "READY"
target_robz = robz_pos + 50
target_roby = roby_pos + 50
grp.move(robz, target_robz, roby, target_roby, wait=False)
assert grp.state() == "MOVING"
#assert robz.state() == "MOVING"
#assert roby.state() == "MOVING"
grp.wait_move()
assert robz.state() == "READY"
assert roby.state() == "READY"
assert grp.state() == "READY"
def test_stop(roby, robz):
grp = Group(robz, roby)
grp.move(robz, 1, roby, 1)
assert robz.state() == "READY"
assert roby.state() == "READY"
assert grp.state() == "READY"
grp.move({robz: 0, roby: 0}, wait=False)
assert grp.state() == "MOVING"
grp.stop()
assert grp.state() == "READY"
assert robz.state() == "READY"
assert roby.state() == "READY"
def test_ctrlc(roby, robz):
grp = Group(robz, roby)
assert robz.state() == "READY"
assert roby.state() == "READY"
assert grp.state() == "READY"
grp.move({robz: -10, roby: -10}, wait=False)
time.sleep(0.01)
grp._Group__move_task.kill(KeyboardInterrupt, block=False)
with pytest.raises(KeyboardInterrupt):
grp.wait_move()
assert grp.state() == "READY"
assert robz.state() == "READY"
assert grp.state() == "READY"
def test_position_reading(beacon, robz, roby):
grp = Group(robz, roby)
positions_dict = grp.position()
for axis, axis_pos in positions_dict.iteritems():
group_axis = beacon.get(axis.name)
assert axis == group_axis
assert axis.position() == axis_pos
def test_move_done(roby, robz):
grp = Group(robz, roby)
res = {"ok": False}
def callback(move_done, res=res):
if move_done:
res["ok"] = True
roby_pos = roby.position()
robz_pos = robz.position()
event.connect(grp, "move_done", callback)
grp.rmove({robz: 2, roby: 3})
assert res["ok"] == True
assert robz.position() == robz_pos+2
assert roby.position() == roby_pos+3
def test_bad_startall(robz, robz2):
# robz and robz2 are on the same controller
grp = Group(robz, robz2)
try:
robz.controller.set_error(True)
with pytest.raises(RuntimeError):
grp.move({ robz: 1, robz2: 2 })
assert grp.state() == 'READY'
assert robz.position() == 0
assert robz2.position() == 0
finally:
robz.controller.set_error(False)
def test_hardlimits_set_pos(robz, robz2):
assert robz._set_position() == 0
grp = Group(robz, robz2)
robz.controller.set_hw_limits(robz,-2,2)
robz2.controller.set_hw_limits(robz2,-2,2)
with pytest.raises(RuntimeError):
grp.move({robz:3,robz2:1})
assert robz._set_position() == robz.position()
def test_hw_control(robz, robz2):
grp = Group(robz, robz2)
grp.move({ robz: 2, robz2: 2 }, wait=False)
assert robz._hw_control == True
assert robz2._hw_control == True
grp.wait_move()
assert robz._hw_control == False
assert robz2._hw_control == False
# -*- coding: utf-8 -*-
#
# This file is part of the bliss project
#
# Copyright (c) 2016 Beamline Control Unit, ESRF
# Distributed under the GNU LGPLv3. See LICENSE for more info.
import unittest
import sys
import os
sys.path.insert(
0,
os.path.abspath(
os.path.join(
os.path.dirname(__file__),
os.path.pardir, os.path.pardir)))
import bliss
from bliss.common.axis import Axis
import bliss
import bliss.controllers.motor_settings
from bliss.common.axis import Axis
from bliss.common import event
from bliss.common import log
from bliss.config.motors import set_backend
from bliss.config import settings
class TestEncoder(unittest.TestCase):
def setUp(self):
set_backend("beacon")
bliss.config.motors.clear_cfg()
bliss.controllers.motor_settings.wait_settings_writing()
def test_get_axis(self):
ba1 = bliss.get_axis("ba1")
self.assertTrue(ba1)
def test_custom_attribute_read(self):
ba1 = bliss.get_axis("ba1")
ba2 = bliss.get_axis("ba2")
self.assertEqual(ba1.custom_get_forty_two(), 42)
self.assertAlmostEquals(ba1.get_cust_attr_float(), 3.14, places=3)
self.assertAlmostEquals(ba2.get_cust_attr_float(), 6.28, places=3)
def test_custom_attribute_rw(self):
ba1 = bliss.get_axis("ba1")
self.assertEqual(ba1.get_voltage(), 110)
ba1.set_voltage(380)
self.assertEqual(ba1.get_voltage(), 380)
ba1.set_voltage(110)
self.assertEqual(ba1.get_voltage(), 110)
def test_custom_park(self):
ba1 = bliss.get_axis("ba1")
ba1.custom_park()
def test_custom_get_forty_two(self):
ba1 = bliss.get_axis("ba1")
self.assertEqual(ba1.custom_get_forty_two(), 42)
def test_custom_get_twice(self):
ba1 = bliss.get_axis("ba1")
self.assertEqual(ba1.CustomGetTwice(42), 84)
def test_custom_get_chapi(self):
ba1 = bliss.get_axis("ba1")
self.assertEqual(ba1.custom_get_chapi("chapi"), "chapo")
self.assertEqual(ba1.custom_get_chapi("titi"), "toto")
self.assertEqual(ba1.custom_get_chapi("roooh"), "bla")
def test_custom_send_command(self):
ba1 = bliss.get_axis("ba1")
ba1.custom_send_command("SALUT sent")
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestEncoder)
unittest.TextTestRunner(verbosity=1).run(suite)
This diff is collapsed.
# -*- coding: utf-8 -*-
#
# This file is part of the bliss project
#
# Copyright (c) 2016 Beamline Control Unit, ESRF
# Distributed under the GNU LGPLv3. See LICENSE for more info.
import unittest
import sys
import os
sys.path.insert(
0,
os.path.abspath(
os.path.join(
os.path.dirname(__file__),
os.path.pardir, os.path.pardir)))
import bliss
import bliss.config.motors
from bliss.common.axis import Axis, READY
from bliss.common import log
from bliss.config import settings
#log.level(log.DEBUG)
class TestBeaconSlits(unittest.TestCase):
def setUp(self):
bliss.config.motors.set_backend("beacon")
bliss.config.motors.clear_cfg()
bliss.controllers.motor_settings.wait_settings_writing()
for axis_name in ('s1f','s1b','s1u','s1d','s1hg','s1vg','s1ho','s1vo'):
settings.HashSetting("axis.%s" % axis_name).clear()
def testTags(self):
s1ho = bliss.get_axis("s1ho")
controller = s1ho.controller
for tag, axis_name in {"front": "s1f",
"back": "s1b",
"up": "s1u",
"down": "s1d",
"hgap": "s1hg",
"hoffset": "s1ho",
"vgap": "s1vg",
"voffset": "s1vo"}.iteritems():
self.assertEquals(controller._tagged[tag][0].name, axis_name)
def testRealTags(self):
s1ho = bliss.get_axis("s1ho")
controller = s1ho.controller
self.assertEquals(
[x.name for x in controller._tagged["real"]],
["s1f", "s1b", "s1u", "s1d"])
def testHasTag(self):
self.assertTrue(bliss.get_axis("s1ho").has_tag("hoffset"))
self.assertFalse(bliss.get_axis("s1ho").has_tag("vgap"))
self.assertFalse(bliss.get_axis("s1vg").has_tag("real"))
self.assertTrue(bliss.get_axis("s1u").has_tag("real"))
def testRealsList(self):
s1ho = bliss.get_axis("s1ho")
controller = s1ho.controller
self.assertEquals(len(controller.reals), 4)
self.assertTrue(all([isinstance(x, Axis) for x in controller.reals]))
def testPseudosList(self):
s1ho = bliss.get_axis("s1ho")
controller = s1ho.controller
self.assertEquals(len(controller.pseudos), 4)
self.assertTrue(all([isinstance(x, Axis) for x in controller.pseudos]))
def testPseudoAxisAreExported(self):
self.assertTrue(all((bliss.get_axis("s1vg"),
bliss.get_axis("s1vo"),
bliss.get_axis("s1hg"),
bliss.get_axis("s1ho"))))
def testRealAxisIsRightObject(self):
s1f = bliss.get_axis('s1f')
m0 = bliss.get_axis('m0')
s1ho = bliss.get_axis("s1ho")
controller = s1ho.controller
self.assertEquals(s1f.controller, m0.controller)
self.assertEquals(s1f, controller.axes['s1f'])
def testPseudoAxisState(self):
self.testPseudoAxisAreExported()
s1ho = bliss.get_axis("s1ho")
controller = s1ho.controller
self.assertTrue(
all([axis.state() == 'READY' for axis in controller.pseudos]))
def testPseudoAxisPosition(self):
self.testPseudoAxisAreExported()
s1f = bliss.get_axis("s1f")
s1b = bliss.get_axis("s1b")
s1u = bliss.get_axis("s1u")
s1d = bliss.get_axis("s1d")
s1f.position(0)
s1b.position(1)
s1u.position(0)
s1d.position(1)
self.assertEquals(bliss.get_axis("s1vg").position(), 1)
self.assertEquals(bliss.get_axis("s1vo").position(), -0.5)
self.assertEquals(bliss.get_axis("s1hg").position(), 1)
self.assertEquals(bliss.get_axis("s1ho").position(), 0.5)
def testPseudoAxisMove(self):
s1b = bliss.get_axis("s1b")
s1f = bliss.get_axis("s1f")
s1hg = bliss.get_axis("s1hg")
s1f.move(0)
s1b.move(0)
hgap = 0.5
s1hg.move(hgap)
self.assertAlmostEquals(hgap, s1hg.position(), places=6)
def testPseudoAxisMove2(self):
s1ho = bliss.get_axis("s1ho")
s1b = bliss.get_axis("s1b")
s1f = bliss.get_axis("s1f")
s1hg = bliss.get_axis("s1hg")
s1f.move(0)
s1b.move(0)
s1hg.move(.5)
hgap = s1hg.position()
s1ho.move(2)
self.assertEquals(s1b.state(), READY)
self.assertEquals(s1f.state(), READY)
self.assertAlmostEquals(hgap, s1hg.position(), places=4)
self.assertEquals(s1b.position(), 2 + (hgap / 2.0))
self.assertEquals(s1f.position(), (hgap / 2.0) - 2)
def testPseudoAxisScan(self):
s1ho = bliss.get_axis("s1ho")
s1b = bliss.get_axis("s1b")
s1f = bliss.get_axis("s1f")
s1hg = bliss.get_axis("s1hg")
s1f.move(0)
s1b.move(0)
hgap = 0.5
s1hg.move(hgap)
# scan the slits under the motors resolution
ho_step = (1.0/s1b.steps_per_unit) / 10.0
for i in range(100):
s1ho.rmove(ho_step)
self.assertAlmostEquals(hgap, s1hg.position(), places=4)
def testSetPosition(self):
s1ho = bliss.get_axis("s1ho")
s1b = bliss.get_axis("s1b")
s1f = bliss.get_axis("s1f")
s1hg = bliss.get_axis("s1hg")
s1b.move(0); s1f.move(0);
s1hg.move(4)
self.assertAlmostEquals(2, s1b.position(), places=4)
self.assertAlmostEquals(2, s1f.position(), places=4)
self.assertAlmostEquals(0, s1ho.position(), places=4)
s1hg.position(0)
s1hg.move(1)
self.assertAlmostEquals(2.5, s1b.position(), places=4)
self.assertAlmostEquals(2.5, s1f.position(), places=4)
self.assertAlmostEquals(1, s1hg.position(), places=4)
self.assertAlmostEquals(0, s1ho.position(), places=4)
if __name__ == '__main__':
unittest.main()
# -*- coding: utf-8 -*-
#
# This file is part of the bliss project
#
# Copyright (c) 2016 Beamline Control Unit, ESRF
# Distributed under the GNU LGPLv3. See LICENSE for more info.
import unittest
import sys
import os
sys.path.insert(
0,
os.path.abspath(
os.path.join(
os.path.dirname(__file__),
os.path.pardir, os.path.pardir)))
import bliss
config_xml = """
<config>
<controller class="mockup" name="test">
<host value="mydummyhost1"/>
<port value="5000"/>
<axis name="robz">
<!-- degrees per second -->
<velocity value="100"/>
<acceleration value="1"/>
<default_voltage value="110"/>
<default_cust_attr value="3.14"/>
</axis>
<axis name="roby">
<!-- degrees per second -->
<velocity value="100"/>
<acceleration value="1"/>
<default_voltage value="220"/>
<default_cust_attr value="6.28"/>
</axis>
</controller>
</config>
"""
class TestCustomAttributes(unittest.TestCase):
def setUp(self):
bliss.load_cfg_fromstring(config_xml)
def test_get_axis(self):
robz = bliss.get_axis("robz")
self.assertTrue(robz)
def test_custom_attribute_read(self):
roby = bliss.get_axis("roby")
robz = bliss.get_axis("robz")
self.assertAlmostEquals(roby.get_cust_attr_float(), 6.28, places=3)
self.assertAlmostEquals(robz.get_cust_attr_float(), 3.14, places=3)
def test_custom_attribute_rw(self):
robz = bliss.get_axis("robz")
self.assertEqual(robz.get_voltage(), 110)
robz.set_voltage(380)
self.assertEqual(robz.get_voltage(), 380)
robz.set_voltage(110)
self.assertEqual(robz.get_voltage(), 110)
if __name__ == '__main__':
unittest.main()
# -*- coding: utf-8 -*-
#
# This file is part of the bliss project
#
# Copyright (c) 2016 Beamline Control Unit, ESRF
# Distributed under the GNU LGPLv3. See LICENSE for more info.
import unittest
import sys
import os
sys.path.insert(
0,
os.path.abspath(
os.path.join(
os.path.dirname(__file__),
os.path.pardir, os.path.pardir)))
import bliss
config_xml = """
<config>
<controller class="mockup" name="test">
<host value="mydummyhost1"/>
<port value="5000"/>
<axis name="robz">
<!-- degrees per second -->
<velocity value="100"/>
<acceleration value="1"/>
</axis>
</controller>
<controller class="mockup">
<host value="mydummyhost2"/>
<port value="5000"/>
<axis name="roby">
<backlash value="2"/>
<steps_per_unit value="10"/>
<velocity value="2500"/>
<acceleration value="1"/>
</axis>
</controller>
</config>
"""
class TestMockupController(unittest.TestCase):
def setUp(self):
bliss.load_cfg_fromstring(config_xml)
def test_get_axis(self):
robz = bliss.get_axis("robz")
self.assertTrue(robz)
def test_get_custom_methods_list(self):
robz = bliss.get_axis("robz")
self.assertEqual(robz.custom_methods_list, [('Set_Closed_Loop', ('bool', 'None')), ('custom_command_no_types', (None, None)), ('custom_get_chapi', ('str', 'str')), ('custom_get_forty_two', ('None', 'int')), ('CustomGetTwice', ('int', 'int')), ('custom_park', (None, None)), ('custom_send_command', ('str', 'None')), ('custom_set_measured_noise', ('float', 'None')), ('get_cust_attr_float', ('None', 'float')), ('get_voltage', ('None', 'int')), ('set_cust_attr_float', ('float', 'None')), ('set_voltage', ('int', 'None'))])
#print "\ncustom functions :",
#for (fname, types) in robz.custom_methods_list:
# print fname, types, " ",
def test_custom_park(self):
robz = bliss.get_axis("robz")
robz.custom_park()
def test_custom_get_forty_two(self):
robz = bliss.get_axis("robz")
self.assertEqual(robz.custom_get_forty_two(), 42)
def test_custom_get_twice(self):
robz = bliss.get_axis("robz")
self.assertEqual(robz.CustomGetTwice(42), 84)
def test_custom_get_chapi(self):
robz = bliss.get_axis("robz")
self.assertEqual(robz.custom_get_chapi("chapi"), "chapo")
self.assertEqual(robz.custom_get_chapi("titi"), "toto")
self.assertEqual(robz.custom_get_chapi("roooh"), "bla")
def test_custom_send_command(self):
robz = bliss.get_axis("robz")
robz.custom_send_command("SALUT sent")
if __name__ == '__main__':
unittest.main()
# -*- coding: utf-8 -*-
#
# This file is part of the bliss project
#
# Copyright (c) 2016 Beamline Control Unit, ESRF
# Distributed under the GNU LGPLv3. See LICENSE for more info.
import unittest
import sys
import os
sys.path.insert(
0,
os.path.abspath(
os.path.join(
os.path.dirname(__file__),
os.path.pardir, os.path.pardir)))
import bliss
from bliss.common.axis import Axis
#from bliss.common import log
#log.level(log.DEBUG)
config_xml = """
<config>
<controller class="mockup">
<encoder name="m0enc">
<steps_per_unit value="50"/>
<tolerance value="0.001"/>
</encoder>
<encoder name="tiltenc">
<steps_per_unit value="50"/>
</encoder>
<axis name="m0">