Skip to content

Commit

Permalink
Tests fixed for pint 0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
tfarago committed Sep 9, 2013
1 parent 01785b9 commit 688c781
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
19 changes: 10 additions & 9 deletions concert/devices/motors/dummy.py
Expand Up @@ -2,7 +2,6 @@
import random
from concert.quantities import q
from concert.devices.motors import base
from concert.devices.base import LinearCalibration


class Motor(base.Motor):
Expand All @@ -17,8 +16,10 @@ def __init__(self, calibration=None, position=None, hard_limits=None):
self.lower, self.upper = hard_limits
else:
self.lower, self.upper = -100, 100
self.lower = self.lower * q.count
self.upper = self.upper * q.count

if position:
if position is not None:
self._position = position
else:
self._position = random.uniform(self.lower, self.upper) * q.count
Expand All @@ -31,12 +32,12 @@ def _stop_real(self):

def _set_position(self, position):
if position < self.lower:
self._position = self.lower * q.count
self._position = self.lower
elif not position < self.upper:
# We do this funny comparison because pint is able to compare
# "position < something" but not the other way around. See
# https://github.com/hgrecco/pint/issues/40
self._position = self.upper * q.count
self._position = self.upper
else:
self._position = position

Expand All @@ -51,13 +52,13 @@ class ContinuousMotor(base.ContinuousMotor):
def __init__(self, position_calibration, velocity_calibration):
super(ContinuousMotor, self).__init__(position_calibration,
velocity_calibration)
self._position_hard_limits = -10, 10
self._velocity_hard_limits = -100, 100
self._position = 0
self._velocity = 0
self._position_hard_limits = -10 * q.count, 10 * q.count
self._velocity_hard_limits = -100 * q.count, 100 * q.count
self._position = 0 * q.count
self._velocity = 0 * q.count

def _stop_real(self):
self._velocity = 0
self._velocity = 0 * q.count

def _set_position(self, position):
self._position = position
Expand Down
22 changes: 13 additions & 9 deletions concert/tests/integration/optimization/test_dummyfocusing.py
Expand Up @@ -48,7 +48,7 @@ def setUp(self):
algorithms.halver,
(1 * q.mm,),
{"epsilon": self.epsilon,
"max_iterations": 1000})
"max_iterations": 3000})
self.position_eps = 1e-1 * q.mm
self.gradient_cmp_eps = 1e-1

Expand Down Expand Up @@ -79,38 +79,42 @@ def test_huge_step_in_limits(self):

@slow
def test_maximum_out_of_limits_right(self):
self.feedback.max_position = (self.motor.upper + 50) * q.mm
self.feedback.max_position = (self.motor.upper + 50 * q.count) \
* q.mm / q.count

self.focuser.run().wait()
self.check(self.motor.upper * q.mm)
self.check(self.motor.upper * q.mm / q.count)

@slow
def test_maximum_out_of_limits_left(self):
self.feedback.max_position = (self.motor.lower - 50) * q.mm
self.feedback.max_position = (self.motor.lower - 50 * q.count) \
* q.mm / q.count
self.focuser.run().wait()
self.check(self.motor.lower * q.mm)
self.check(self.motor.lower * q.mm / q.count)

@slow
def test_huge_step_out_of_limits_right(self):
# Right.
self.feedback.max_position = (self.motor.upper + 50) * q.mm
self.feedback.max_position = (self.motor.upper + 50 * q.count) \
* q.mm / q.count

focuser = Maximizer(self.motor["position"], self.feedback,
algorithms.halver,
(self.motor.position, 1000 * q.mm, self.epsilon),
{"max_iterations": 1000})
focuser.run().wait()
self.check(self.motor.upper * q.mm)
self.check(self.motor.upper * q.mm / q.count)

@slow
def test_huge_step_out_of_limits_left(self):
focuser = Maximizer(self.motor["position"], self.feedback,
algorithms.halver,
(self.motor.position, 1000 * q.mm, self.epsilon),
{"max_iterations": 1000})
self.feedback.max_position = (self.motor.lower - 50) * q.mm
self.feedback.max_position = (self.motor.lower - 50 * q.count) \
* q.mm / q.count
focuser.run().wait()
self.check(self.motor.lower * q.mm)
self.check(self.motor.lower * q.mm / q.count)

@slow
def test_identical_gradients(self):
Expand Down
Expand Up @@ -15,9 +15,10 @@ class TestDummyAlignment(ConcertTest):
def setUp(self):
super(TestDummyAlignment, self).setUp()
calibration = LinearCalibration(q.count / q.deg, 0 * q.deg)
self.x_motor = Motor(calibration=calibration)
self.y_motor = Motor(calibration=calibration)
self.z_motor = Motor(calibration=calibration)
hard_limits = (-np.Inf * q.count, np.Inf * q.count)
self.x_motor = Motor(calibration=calibration, hard_limits=hard_limits)
self.y_motor = Motor(calibration=calibration, hard_limits=hard_limits)
self.z_motor = Motor(calibration=calibration, hard_limits=hard_limits)

self.x_motor.position = 0 * q.deg
self.z_motor.position = 0 * q.deg
Expand Down

0 comments on commit 688c781

Please sign in to comment.