def test_GIVEN_user_function_engineering_correction_which_throws_WHEN_set_value_on_axis_THEN_0_correction(self): def _test_correction(setpoint): raise TypeError() engineering_correction = UserFunctionCorrection(_test_correction) result = engineering_correction.to_axis(0) assert_that(result, is_(close_to(0, FLOAT_TOLERANCE)))
def test_GIVEN_user_function_engineering_correction_which_adds_no_correction_WHEN_set_value_on_axis_THEN_value_is_same_as_set(self): def _test_correction(setpoint): return 0 value = 1 expected_correction = value engineering_correction = UserFunctionCorrection(_test_correction) result = engineering_correction.to_axis(value) assert_that(result, is_(close_to(expected_correction, FLOAT_TOLERANCE)))
def test_GIVEN_user_function_engineering_correction_which_adds_a_correction_of_the_setpoint_on_WHEN_set_value_on_axis_THEN_value_is_double_what_was_set(self): def _test_correction(setpoint): """Correction is the same as the setpoint so it doubles the correction""" return setpoint value = 1 expected_correction = value*2 engineering_correction = UserFunctionCorrection(_test_correction) result = engineering_correction.to_axis(value) assert_that(result, is_(close_to(expected_correction, FLOAT_TOLERANCE)))
def test_GIVEN_user_function_engineering_correction_which_adds_a_correction_of_the_setpoint_on_WHEN_get_value_from_axis_THEN_value_is_that_value_minus_the_setpoint(self): def _test_correction(setpoint): """Correction is the same as the setpoint so it doubles the correction""" return setpoint setpoint = 3 axis_readback = 1 expected_correction = axis_readback - setpoint engineering_correction = UserFunctionCorrection(_test_correction) result = engineering_correction.from_axis(axis_readback, setpoint) assert_that(result, is_(close_to(expected_correction, FLOAT_TOLERANCE)))
def test_GIVEN_user_function_engineering_correction_which_adds_setpoint_and_beamline_param_WHEN_set_value_on_axis_THEN_value_is_twice_value_plus_beamline_parameter_value(self): def _test_correction(setpoint, beamline_parameter): return setpoint + beamline_parameter parameter_value = 2 comp = Component("param_comp", setup=PositionAndAngle(0, 0, 90)) beamline_parameter = AxisParameter("param", comp, ChangeAxis.POSITION) beamline_parameter.sp = parameter_value value = 1 expected_correction = value * 2 + parameter_value engineering_correction = UserFunctionCorrection(_test_correction, beamline_parameter) result = engineering_correction.to_axis(value) assert_that(result, is_(close_to(expected_correction, FLOAT_TOLERANCE)))
def test_GIVEN_beam_line_where_autosave_and_engineering_correction_on_displacement_WHEN_init_THEN_beamline_is_at_given_place(self, param_float_autosave): expected_setpoint = 1.0 multiple = 2.0 param_float_autosave.read_parameter.return_value = expected_setpoint offset = expected_setpoint / multiple comp = Component("comp", PositionAndAngle(0.0, 0, 90)) param = AxisParameter("param", comp, ChangeAxis.POSITION, autosave=True) axis = create_mock_axis("MOT:MTR0101", offset + expected_setpoint, 1) driver = IocDriver(comp, ChangeAxis.POSITION, axis, engineering_correction=UserFunctionCorrection(lambda sp: sp / multiple)) nr_mode = BeamlineMode("NR", [param.name], {}) bl = Beamline([comp], [param], [driver], [nr_mode]) bl.active_mode = nr_mode.name result = comp.beam_path_set_point.axis[ChangeAxis.POSITION].get_displacement() assert_that(result, is_(close_to(expected_setpoint, 1e-6)))