class TestPositioners(TestCase): def setUp(self): super(TestPositioners, self).setUp() self.positioner = Positioner() self.positioner.position = ORIGIN self.positioner.orientation = ROT_ORIGIN def test_position(self): position = (1.0, 2.0, 3.0) * q.um self.positioner.position = position assert_almost_equal(position, self.positioner.position) # Test non-existent axis del self.positioner.translators['x'] with self.assertRaises(PositionerError): self.positioner.set_position(position).join() # The remaining axes must work position = (0.0, 1.0, 2.0) * q.mm self.positioner.position = position assert_almost_equal(position[1:], self.positioner.position[1:]) # Also nan must work position = (np.nan, 1.0, 2.0) * q.mm self.positioner.position = position assert_almost_equal(position, self.positioner.position) # Also 0 in the place of no axis must work self.positioner.position = (0.0, 1.0, 2.0) * q.mm assert_almost_equal(position, self.positioner.position) def test_orientation(self): orientation = (1.0, 2.0, 3.0) * q.rad self.positioner.orientation = orientation assert_almost_equal(orientation, self.positioner.orientation) # Degrees must be accepted self.positioner.orientation = (2.0, 3.0, 4.0) * q.deg # Test non-existent axis del self.positioner.rotators['x'] with self.assertRaises(PositionerError): self.positioner.set_orientation(orientation).join() # Also nan must work orientation = (np.nan, 1.0, 2.0) * q.rad self.positioner.orientation = orientation assert_almost_equal(orientation, self.positioner.orientation) # Also 0 in the place of no axis must work self.positioner.orientation = (0.0, 1.0, 2.0) * q.rad assert_almost_equal(orientation, self.positioner.orientation) def test_move(self): position = (1.0, 2.0, 3.0) * q.mm self.positioner.move(position).join() assert_almost_equal(position, self.positioner.position) def test_rotate(self): orientation = (1.0, 2.0, 3.0) * q.rad self.positioner.rotate(orientation).join() assert_almost_equal(orientation, self.positioner.orientation) def test_right(self): self.positioner.right(1 * q.mm).join() assert_almost_equal((1.0, 0.0, 0.0) * q.mm, self.positioner.position) def test_left(self): self.positioner.left(1 * q.mm).join() assert_almost_equal((-1.0, 0.0, 0.0) * q.mm, self.positioner.position) def test_up(self): self.positioner.up(1 * q.mm).join() assert_almost_equal((0.0, 1.0, 0.0) * q.mm, self.positioner.position) def test_down(self): self.positioner.down(1 * q.mm).join() assert_almost_equal((0.0, -1.0, 0.0) * q.mm, self.positioner.position) def test_forward(self): self.positioner.forward(1 * q.mm).join() assert_almost_equal((0.0, 0.0, 1.0) * q.mm, self.positioner.position) def test_back(self): self.positioner.back(1 * q.mm).join() assert_almost_equal((0.0, 0.0, -1.0) * q.mm, self.positioner.position)
def setUp(self): super(TestPositioners, self).setUp() self.positioner = Positioner() self.positioner.position = ORIGIN self.positioner.orientation = ROT_ORIGIN