class OerconeTests(unittest.TestCase):
    """
    Tests for the Oercone IOC.
    """
    def setUp(self):
        self._lewis, self._ioc = get_running_lewis_and_ioc(IOCS[0]["emulator"], DEVICE_PREFIX)
        self.ca = ChannelAccess(device_prefix=DEVICE_PREFIX)

    def test_WHEN_device_is_started_THEN_it_is_not_disabled(self):
        self.ca.assert_that_pv_is("DISABLE", "COMMS ENABLED")

    @parameterized.expand(parameterized_list(TEST_PRESSURE_VALUES))
    @skip_if_recsim("Lewis backdoor not available in recsim")
    def test_WHEN_pressure_is_set_via_backdoor_THEN_readback_updates(self, _, pressure):
        self._lewis.backdoor_set_on_device("pressure", pressure)
        self.ca.assert_that_pv_is_number("PRESSURE", pressure)

    @skip_if_recsim("Lewis backdoor not available in recsim")
    def test_WHEN_measurement_units_is_set_via_backdoor_THEN_readback_updates(self):
        for units in Units:
            self._lewis.backdoor_run_function_on_device("backdoor_set_units", [units.value])
            expected_units = units.name
            self.ca.assert_that_pv_is("PRESSURE.EGU", expected_units)

    @parameterized.expand(parameterized_list(Units))
    def test_WHEN_units_setpoint_set_THEN_read_back_is_correct(self, _, units):
        self.ca.assert_setting_setpoint_sets_readback(units.name, "UNITS")
class Sans2dAperturesGuidesTests(unittest.TestCase):
    """
    Tests for the sans2d waveguides and apertures tank motor extensions.
    """

    def setUp(self):
        self.ca = ChannelAccess()

    @parameterized.expand(AXES_TO_STOP)
    def test_GIVEN_move_enabled_axis_moving_WHEN_stop_all_THEN_axis_stopped(self, axis):
        # Set interlock to enabled
        self.ca.set_pv_value("FINS_VAC:SIM:ADDR:1001", 64)
        self.ca.assert_that_pv_is("FINS_VAC:GALIL_INTERLOCK", "CAN MOVE")
        # Stop axis to prevent test instability (other tests may have left it moving)
        stop_axis_moving(axis)
        assert_axis_not_moving(axis)
        # Execute test
        for _ in range(3):
            set_axis_moving(axis)
            assert_axis_moving(axis)
            self.ca.set_pv_value("MOT:SANS2DAPWV:STOP_MOTORS:ALL", 1)
            assert_axis_not_moving(axis)

    @parameterized.expand(AXES_TO_STOP)
    def test_GIVEN_move_disabled_axis_moving_WHEN_stop_all_THEN_axis_not_stopped(self, axis):
        # Set interlock to disabled
        self.ca.set_pv_value("FINS_VAC:SIM:ADDR:1001", 0)
        self.ca.assert_that_pv_is("FINS_VAC:GALIL_INTERLOCK", "CANNOT MOVE")
        # Execute test
        for _ in range(3):
            set_axis_moving(axis)
            assert_axis_moving(axis)
            self.ca.set_pv_value("MOT:SANS2DAPWV:STOP_MOTORS:ALL", 1)
            assert_axis_moving(axis)
Example #3
0
class NeoceraTests(unittest.TestCase):
    """
    Tests for the Neocera.
    """
    def setUp(self):
        self._ioc = IOCRegister.get_running(DEVICE_PREFIX)
        self.ca = ChannelAccess(device_prefix=DEVICE_PREFIX)

    def test_WHEN_ioc_is_started_THEN_ioc_is_not_disabled(self):
        self.ca.assert_that_pv_is("DISABLE", "COMMS ENABLED")

    def test_WHEN_units_mode_is_set_THEN_units_mode_readback_is_the_value_just_set(
            self):
        for mode in ["Monitor", "Control"]:
            self.ca.assert_setting_setpoint_sets_readback(mode, "MODE")

    def test_WHEN_temperatue_setpoint_is_set_THEN_readback_updates_to_the_value_just_set(
            self):
        for sensor, value in itertools.product(SENSORS, TEST_VALUES):
            self.ca.assert_setting_setpoint_sets_readback(
                value,
                set_point_pv="{}:TEMP:SP".format(sensor),
                readback_pv="{}:TEMP:SP:RBV".format(sensor))

    def test_WHEN_pid_settings_are_set_THEN_readbacks_update_to_the_values_just_set(
            self):
        for sensor, value, control in itertools.product(
                SENSORS, TEST_VALUES, ["P", "I", "D"]):
            self.ca.assert_setting_setpoint_sets_readback(
                value, "{}:{}".format(sensor, control))
class InhibitrTests(unittest.TestCase):
    """
    Tests for the Inhibitr IOC.
    """
    def setUp(self):
        self._ioc = IOCRegister.get_running(IOC_PREFIX)
        self.ca = ChannelAccess(default_timeout=20)
        self.values = ["SIMPLE:VALUE1:SP", "SIMPLE:VALUE2:SP"]

        for pv in self.values:
            self.ca.assert_that_pv_exists(pv)

        self.reset_values_to_zero()

    def reset_values_to_zero(self):
        for val in self.values:
            self.ca.set_pv_value(val, 0)
            self.ca.assert_that_pv_is(val, 0)
        for val in self.values:
            self.ca.assert_that_pv_is(val + ".DISP", "0")

    def test_GIVEN_both_inputs_are_zero_WHEN_setting_either_input_THEN_this_is_allowed(
            self):
        for val in self.values:
            self.ca.assert_that_pv_is("{}.DISP".format(val), "0")

    @unstable_test()
    def test_GIVEN_one_input_is_one_WHEN_setting_other_value_to_one_THEN_this_is_not_allowed(
            self):
        self.ca.set_pv_value("SIMPLE:VALUE1:SP", 1)
        self.ca.assert_that_pv_is("SIMPLE:VALUE1:SP", 1)
        # When value1 is set to non-zero, the disallowed value of value2 should be 1
        # i.e 'Not allowed to set this value to non-zero'
        self.ca.assert_that_pv_is("SIMPLE:VALUE2:SP.DISP", "1")
Example #5
0
class Mk3chopperTests(unittest.TestCase):

    # Remote access modes
    LOCAL = "LOCAL"
    REMOTE = "REMOTE"
    COMP_MODE_PV = "COMP:MODE"

    def setUp(self):
        self._ioc = IOCRegister.get_running(DEVICE_PREFIX)
        # Comp mode is on a slow 10s read. Needs a longer timeout than default
        self.ca = ChannelAccess(device_prefix=DEVICE_PREFIX, default_timeout=30)
        self.ca.assert_that_pv_exists(self.COMP_MODE_PV)

    def test_WHEN_ioc_is_in_remote_mode_THEN_it_has_no_alarm(self):
        # In RECSIM, switch to remote explicitly. DEVSIM can only have remote mode so no switch needed
        if IOCRegister.uses_rec_sim:
            # Bug in CA channel. Reports invalid alarm severity if you set enum directly
            self.ca.set_pv_value("SIM:{}.VAL".format(self.COMP_MODE_PV), 1)
        self.ca.assert_that_pv_is(self.COMP_MODE_PV, self.REMOTE)
        self.ca.assert_that_pv_alarm_is(self.COMP_MODE_PV, ChannelAccess.Alarms.NONE)

    @skip_if_devsim("Can't switch to local mode in DEVSIM")
    def test_WHEN_ioc_is_in_local_mode_THEN_it_has_a_major_alarm(self):
        # Bug in CA channel. Reports invalid alarm severity if you set enum directly
        self.ca.set_pv_value("SIM:{}.VAL".format(self.COMP_MODE_PV), 0)
        self.ca.assert_that_pv_is(self.COMP_MODE_PV, self.LOCAL)
        self.ca.assert_that_pv_alarm_is(self.COMP_MODE_PV, ChannelAccess.Alarms.MAJOR)
Example #6
0
class FlipprpsTests(unittest.TestCase):
    """
    Tests for the Flipprps IOC.
    """
    def setUp(self):
        self._lewis, self._ioc = get_running_lewis_and_ioc(
            "flipprps", DEVICE_PREFIX)
        self.ca = ChannelAccess(device_prefix=DEVICE_PREFIX)
        self._lewis.backdoor_set_on_device("connected", True)

    @skip_if_recsim("Lewis backdoor commands not available in RecSim")
    def test_SET_polarity(self):
        self.ca.set_pv_value("POLARITY", "Down")
        self._lewis.assert_that_emulator_value_is("polarity", 0)
        self.ca.set_pv_value("POLARITY", "Up")
        self._lewis.assert_that_emulator_value_is("polarity", 1)

    def test_GET_id(self):
        self.ca.assert_that_pv_is("ID", "Flipper")

    @skip_if_recsim("Lewis backdoor commands not available in RecSim")
    def test_GIVEN_device_not_connected_THEN_id_is_in_alarm(self):
        self._lewis.backdoor_set_on_device("connected", False)
        self.ca.assert_that_pv_alarm_is("ID", self.ca.Alarms.INVALID, 20)

    @skip_if_recsim("Lewis backdoor commands not available in RecSim")
    def test_GIVEN_device_not_connected_THEN_polarity_raises_timeout_alarm_after_set(
            self):
        self._lewis.backdoor_set_on_device("connected", False)
        self.ca.set_pv_value("POLARITY", "Up")
        self.ca.assert_that_pv_alarm_is("POLARITY", self.ca.Alarms.INVALID)
Example #7
0
class SamposTests(unittest.TestCase):
    """
    Tests for the sampos IOC.
    """

    test_values = [0, 10]
    axes = ['X', 'Y', 'Z', 'W', 'S']

    def setUp(self):
        self._ioc = IOCRegister.get_running("SAMPOS")

        self.ca = ChannelAccess(20, device_prefix=DEVICE_PREFIX)
        self.ca.assert_that_pv_exists("DISABLE", timeout=30)

    def test_WHEN_ioc_is_started_THEN_ioc_is_not_disabled(self):
        self.ca.assert_that_pv_is("DISABLE", "COMMS ENABLED")

    def test_WHEN_values_are_set_THEN_readbacks_update(self):
        for axis in self.axes:
            for value in self.test_values:
                self.ca.assert_setting_setpoint_sets_readback(
                    value,
                    readback_pv="{}".format(axis),
                    set_point_pv="{}:SP".format(axis))

    def test_WHEN_values_are_set_THEN_setpoint_readbacks_update(self):
        for axis in self.axes:
            for value in self.test_values:
                self.ca.assert_setting_setpoint_sets_readback(
                    value,
                    readback_pv="{}:SP:RBV".format(axis),
                    set_point_pv="{}:SP".format(axis))
class InstEtcTests(unittest.TestCase):
    """
    Tests for instrument etc. ioc
    """
    def setUp(self):
        self._lewis, self._ioc = get_running_lewis_and_ioc(
            ioc_name=DEVICE_PREFIX)
        self.ca = ChannelAccess(device_prefix="PARS")

    @parameterized.expand([("I", 12), ("R", 12.34), ("S", "123abc")])
    def test_GIVEN_loaded_WHEN_set_and_read_user_integer_THEN_integer_is_set(
            self, test_type, value):
        for var_index in range(NUM_USER_VARS + 1):
            self.ca.assert_setting_setpoint_sets_readback(
                value, readback_pv="USER:{}{}".format(test_type, var_index))
        self.ca.assert_that_pv_does_not_exist("USER:I{}".format(NUM_USER_VARS +
                                                                1))

    def test_GIVEN_loaded_WHEN_get_max_user_record_THEN_max_is_returned(self):
        self.ca.assert_that_pv_is("USER:MAX", NUM_USER_VARS)

    def test_GIVEN_loaded_WHEN_get_max_user_buttons_THEN_max_is_returned(self):
        self.ca.assert_that_pv_is("USER:BUTTONS:MAX", NUM_USER_BUTTONS)

    def test_GIVEN_loaded_WHEN_set_and_read_button_THEN_running_set(self):
        for var_index in range(NUM_USER_BUTTONS + 1):
            self.ca.assert_setting_setpoint_sets_readback(
                "Running",
                readback_pv="USER:BUTTON{}:SP".format(var_index),
                set_point_pv="USER:BUTTON{}:SP".format(var_index))
        self.ca.assert_that_pv_does_not_exist(
            "USER:BUTTON{}".format(NUM_USER_VARS + 1))
class CP2800StatusTests(unittest.TestCase):
    def setUp(self):
        _, self._ioc = get_running_lewis_and_ioc(None, DEVICE_PREFIX)
        self.assertIsNotNone(self._ioc)
        self.ca = ChannelAccess(device_prefix=DEVICE_PREFIX)

    def test_GIVEN_compressor_elapsed_minutes_THEN_alarm_correct(self):
        tests = [
            (-1, self.ca.Alarms.MAJOR),
            (0, self.ca.Alarms.NONE),
            (1, self.ca.Alarms.NONE),
            (500001, self.ca.Alarms.MINOR),
            (1000001, self.ca.Alarms.MAJOR),
        ]
        for test in tests:
            elapsed_time, expected_alarm = test
            self.ca.set_pv_value("SIM:ELAPSED", elapsed_time)
            self.ca.assert_that_pv_alarm_is("ELAPSED", expected_alarm, 10)

    def test_GIVEN_compressor_state_on_or_off_THEN_readback_correct(self):
        states = [(1, "On"), (0, "Off")]
        for state in states:
            send_val, expected_response = state
            self.ca.set_pv_value("SIM:POWER", send_val)
            self.ca.assert_that_pv_is("POWER", expected_response)

    def test_GIVEN_error_value_THEN_readback_correct(self):
        self.ca.set_pv_value("SIM:ERR", 1)
        self.ca.assert_that_pv_is("ERR", 1, timeout=10)

    def test_GIVEN_negative_error_value_THEN_alarm_correct(self):
        self.ca.set_pv_value("SIM:ERR", -1)
        self.ca.assert_that_pv_alarm_is("ERR",
                                        self.ca.Alarms.MAJOR,
                                        timeout=10)
class Ag53220ATests(unittest.TestCase):
    """
    Tests for the Ag53220A IOC.
    """
    def setUp(self):
        self._lewis, self._ioc = get_running_lewis_and_ioc(
            "Ag53220A", DEVICE_PREFIX)
        self.ca = ChannelAccess(device_prefix=DEVICE_PREFIX)
        self.ca.assert_that_pv_exists("DISABLE", timeout=30)

    def test_WHEN_ioc_is_started_THEN_ioc_is_not_disabled(self):
        self.ca.assert_that_pv_is("DISABLE", "COMMS ENABLED")
Example #11
0
class Lksh336Tests(unittest.TestCase):
    """
    Tests for the Lksh336 IOC.
    """
    def setUp(self):
        self._lewis, self._ioc = get_running_lewis_and_ioc(
            "Lksh336", DEVICE_PREFIX)
        self.ca = ChannelAccess(device_prefix=DEVICE_PREFIX)

    def test_GIVEN_temp_set_WHEN_read_THEN_temp_is_as_expected(self):
        test_value = 10
        self.ca.set_pv_value("SIM:TEMP_A", test_value)
        self.ca.assert_that_pv_is("SIM:TEMP_A", test_value)
class CryvalveTests(unittest.TestCase):
    """
    Tests for the Cryvalve IOC.
    """
    def setUp(self):
        self._lewis, self._ioc = get_running_lewis_and_ioc("Cryvalve", DEVICE_PREFIX)
        self.ca = ChannelAccess(device_prefix=DEVICE_PREFIX)

    def test_GIVEN_value_is_open_WHEN_get_state_THEN_state_is_open(self):
        expected_value = "OPEN"
        self._ioc.set_simulated_value("SIM:STAT", expected_value)

        self.ca.assert_that_pv_is("STAT", expected_value)
class FermiChopperLifterTests(unittest.TestCase):
    """
    Tests for the fermi chopper lift.

    There isn't any logic to test in this IOC so this is really just a test that the DB records get loaded.
    """
    def setUp(self):
        self._ioc = IOCRegister.get_running("GALIL_01")
        self.ca = ChannelAccess(default_timeout=30)
        self.ca.assert_that_pv_exists("MOT:CHOPLIFT:STATUS", timeout=60)

    def test_WHEN_ioc_is_run_THEN_status_record_exists(self):
        # Simulated galil user variables are initialized to zero which maps to "Unknown".
        self.ca.assert_that_pv_is("MOT:CHOPLIFT:STATUS", "Unknown")
Example #14
0
class PowerStatusTests(unittest.TestCase):
    def setUp(self):
        self.ca = ChannelAccess(20, device_prefix=DEVICE_PREFIX)
        shared_setup(self.ca)

    def test_that_GIVEN_psu_off_WHEN_voltage_setpoint_changed_higher_than_threshold_THEN_psu_status_changes_on(
            self):
        # GIVEN
        # asserted in setUp
        # WHEN
        self.ca.set_pv_value("VOLT:SP", 100)

        # THEN
        self.ca.assert_that_pv_is("POWER:STAT", "ON")

    def test_that_GIVEN_psu_on_WHEN_voltage_setpoint_changed_lower_than_threshold_THEN_psu_status_changes_off(
            self):
        # GIVEN
        self.ca.set_pv_value("VOLT:SP", 10)
        self.ca.assert_that_pv_is("VOLT", 10)
        self.ca.assert_that_pv_is("POWER:STAT", "ON")

        # WHEN
        self.ca.set_pv_value("VOLT:SP", 0)

        # THEN
        self.ca.assert_that_pv_is("POWER:STAT", "OFF")
Example #15
0
class Hameg8123Tests(unittest.TestCase):
    """
    Tests for the Hameg8123 IOC.
    """
    def setUp(self):
        self._lewis, self._ioc = get_running_lewis_and_ioc(None, DEVICE_PREFIX)
        self.ca = ChannelAccess(device_prefix=DEVICE_PREFIX)

    def test_GIVEN_desired_impedence_WHEN_set_impedence_THEN_readback_and_measured_impedence_are_set_to_desired_impedence(self):

        expected_impedance = "50"

        self.ca.assert_setting_setpoint_sets_readback(expected_impedance, "CHAN_A:IMPEDANCE:SP:RBV", "CHAN_A:IMPEDANCE:SP")
        self.ca.assert_that_pv_is("CHAN_A:IMPEDANCE", expected_impedance)
Example #16
0
def reset_emulator():
    """ Resets the device"""
    lewis, ioc = get_running_lewis_and_ioc("ngpspsu", DEVICE_PREFIX)
    ca = ChannelAccess(20, device_prefix=DEVICE_PREFIX)

    _reset_device(ca)
    ca.assert_that_pv_is("STAT:POWER", "OFF")

    _reset_error(ca)
    ca.assert_that_pv_is("ERROR", "No error")

    _connect_device(lewis)

    return lewis, ioc, ca
class ChannelTests(unittest.TestCase):
    def setUp(self):
        self._lewis, self._ioc = get_running_lewis_and_ioc(
            "keithley_2700", DEVICE_PREFIX)
        self.ca = ChannelAccess(default_timeout=30,
                                device_prefix=DEVICE_PREFIX)
        self.ca.assert_that_pv_exists("IDN")
        self.ca.set_pv_value("BUFF:CLEAR:SP", "")
        self.ca.assert_that_pv_is("BUFF:AUTOCLEAR", "ON")
        if not IOCRegister.uses_rec_sim:
            self._lewis.backdoor_set_on_device("simulate_readings", False)

    @unstable_test()
    @skip_if_recsim("Cannot use lewis backdoor in recsim")
    def test_GIVEN_empty_buffer_WHEN_reading_inserted_THEN_channel_PVs_get_correct_values(
            self):
        _reset_drift_channels(self)
        reading = "+1386.05,+4000,101"
        expected_values = {
            'read': 1386.05,
            'time': 4000,
            'temp101': 47.424,
            'drift': 0,
        }
        # GIVEN
        self.ca.set_pv_value("BUFF:CLEAR:SP", "")
        # WHEN
        _insert_reading(self, [reading])
        # THEN
        self.ca.assert_that_pv_is_number("CHNL:101:READ",
                                         expected_values['read'],
                                         tolerance=READ_TOLERANCE)
        self.ca.assert_that_pv_is_number("CHNL:101:TIME",
                                         expected_values['time'],
                                         tolerance=TIME_TOLERANCE)
        self.ca.assert_that_pv_is_number("CHNL:101:TEMP",
                                         expected_values['temp101'],
                                         tolerance=TEMP_TOLERANCE)
        self.ca.assert_that_pv_is_number("CHNL:101:DRIFT",
                                         expected_values['drift'],
                                         tolerance=DRIFT_TOLERANCE)

    @skip_if_recsim("Alarm invalid in recsim")
    def test_GIVEN_temperature_out_of_bounds_THEN_alarm_is_major(self):
        #GIVEN
        reading = "+939,+10,101"
        _insert_reading(self, [reading])
        #THEN
        self.ca.assert_that_pv_alarm_is("CHNL:101:TEMP:CHECK",
                                        self.ca.Alarms.MAJOR)
Example #18
0
class VerticalJawsTests(unittest.TestCase):
    def set_motor_speeds(self):
        self.ca.set_pv_value(UNDERLYING_MTR_NORTH + ".VMAX", 20)
        self.ca.set_pv_value(UNDERLYING_MTR_NORTH + ".VELO", 20)
        self.ca.set_pv_value(UNDERLYING_MTR_SOUTH + ".VMAX", 20)
        self.ca.set_pv_value(UNDERLYING_MTR_SOUTH + ".VELO", 20)

    """
    Tests for vertical jaws
    """

    def setUp(self):
        self._ioc = IOCRegister.get_running("vertical_jaws")
        self.ca = ChannelAccess(default_timeout=30)

        self.set_motor_speeds()
        [self.ca.assert_that_pv_exists(mot) for mot in all_motors]

    @parameterized.expand(parameterized_list(TEST_POSITIONS))
    def test_WHEN_south_jaw_setpoint_changed_THEN_south_jaw_moves(
            self, _, value):
        self.ca.assert_setting_setpoint_sets_readback(value, MOTOR_S,
                                                      MOTOR_S_SP)

    @parameterized.expand(parameterized_list(TEST_POSITIONS))
    def test_WHEN_north_jaw_setpoint_changed_THEN_north_jaw_moves(
            self, _, value):
        self.ca.assert_setting_setpoint_sets_readback(value, MOTOR_N,
                                                      MOTOR_N_SP)

    def test_GIVEN_jaws_closed_at_centre_WHEN_gap_opened_THEN_north_and_south_jaws_move(
            self):
        # GIVEN
        self.ca.assert_that_pv_is("MOT:JAWS1:VGAP", 0)
        self.ca.assert_that_pv_is("MOT:JAWS1:VCENT", 0)
        # WHEN
        self.ca.set_pv_value("MOT:JAWS1:VGAP:SP", 10)
        # THEN
        self.ca.assert_that_pv_is(MOTOR_S, -5)
        self.ca.assert_that_pv_is(MOTOR_N, 5)

    def test_GIVEN_jaws_open_WHEN_jaws_closed_THEN_jaws_close(self):
        # GIVEN
        self.ca.set_pv_value("MOT:JAWS1:VGAP:SP", 10)
        # WHEN
        self.ca.set_pv_value("MOT:JAWS1:VGAP:SP", 0)
        # THEN
        self.ca.assert_that_pv_is("MOT:JAWS1:VGAP", 0)
Example #19
0
class tcIocTests(unittest.TestCase):
    def setUp(self):
        self._lewis, self._ioc = get_running_lewis_and_ioc(
            EMULATOR_NAME, DEVICE_PREFIX)

        self.ca = ChannelAccess(device_prefix=None)

    def test_WHEN_var_one_and_two_written_to_THEN_output_is_sum(self):
        self.ca.set_pv_value("ITEST1", 10)
        self.ca.set_pv_value("ITEST2", 20)
        self.ca.assert_that_pv_is("ISUM", 30)

    @parameterized.expand(parameterized_list(["ENUM_VALUE_0", "ENUM_VALUE_1"]))
    def test_WHEN_enum_written_to_THEN_enum_readback_is_correct(self, _, enum):
        self.ca.set_pv_value("ETESTENUM", enum)
        self.ca.assert_that_pv_is("ETESTENUMRBV", enum)
Example #20
0
class SkfG5ChopperTests(unittest.TestCase):
    """
    Tests for the SKF G5 Chopper Controller

    RECSIM is not currently compatible with Asyn, so the only possible test
    is to check for the presence of a specific PV and therefore that the
    DB file has loaded correctly.
    """
    def setUp(self):
        self._ioc = IOCRegister.get_running(DEVICE_PREFIX)

        self.ca = ChannelAccess(device_prefix=DEVICE_PREFIX)

    def test_GIVEN_state_WHEN_read_THEN_state_is_as_expected(self):
        expected_state = "Invalid"

        self.ca.assert_that_pv_is("STATE", expected_state)
Example #21
0
class Linkam95Tests(unittest.TestCase):
    """
    Tests for the Linkam95 IOC.
    """
    def setUp(self):
        self._lewis, self._ioc = get_running_lewis_and_ioc(
            EMULATOR_NAME, DEVICE_PREFIX)
        self.ca = ChannelAccess(device_prefix=DEVICE_PREFIX)

    def test_GIVEN_a_valid_temperature_to_set_WHEN_set_THEN_display_temperature_is_valid_temperature(
            self):

        expected_temp = 10

        self._lewis.backdoor_set_on_device("temperature", expected_temp)

        self.ca.assert_that_pv_is("TEMP", expected_temp)
Example #22
0
class Moxa1210Tests(unittest.TestCase):
    """
    Tests for the Moxa ioLogik e1210. (16x Discrete inputs)
    """

    def setUp(self):
        self._lewis, self._ioc = get_running_lewis_and_ioc("moxa12xx", DEVICE_PREFIX)

        self.ca = ChannelAccess(device_prefix=DEVICE_PREFIX)

        # Sends a backdoor command to the device to set a discrete input (DI) value

        self._lewis.backdoor_run_function_on_device("set_di", (0, [False]*16))

    def resetDICounter(self, channel):
        """
        Reset the counters for each DI (channel)

        Args:
            channel (int) : The DI (channel) counter to be reset

        We typically want to preserve our counter values for each channel even upon restart. For testing purposes
        this function will reset the counter values to 0. 
        """
        self.ca.set_pv_value("CH{:01d}:DI:CNT".format(channel), 0)

    @parameterized.expand([
        ("CH{:01d}".format(channel), channel) for channel in CHANNELS
    ])
    def test_WHEN_DI_input_is_switched_on_THEN_only_that_channel_readback_changes_to_state_just_set(self, _, channel):
        self._lewis.backdoor_run_function_on_device("set_di", (channel, (True,)))

        self.ca.assert_that_pv_is("CH{:d}:DI".format(channel), "High")

        # Test that all other channels are still off
        for test_channel in CHANNELS:
            if test_channel == channel:
                continue

            self.ca.assert_that_pv_is("CH{:1d}:DI".format(test_channel), "Low")

    @parameterized.expand([
        ("CH{:01d}:DI:CNT".format(channel), channel) for channel in CHANNELS
    ])
    def test_WHEN_di_input_is_triggered_a_number_of_times_THEN_di_counter_matches(self, channel_pv, channel):
        self.resetDICounter(channel)
        expected_count = 5

        for i in range(expected_count):
            # Toggle channel and ensure it's registered the trigger
            self._lewis.backdoor_run_function_on_device("set_di", (channel, (True,)))
            self._lewis.backdoor_run_function_on_device("set_di", (channel, (False,)))
            self.ca.assert_that_pv_is(channel_pv, i+1, timeout=5)

        self.ca.assert_that_pv_is(channel_pv, expected_count)
class DanfysikBase(object):
    """
    Tests for danfysik.
    """
    def setUp(self):
        self._lewis, self._ioc = get_running_lewis_and_ioc(
            EMULATOR_NAME, DEVICE_PREFIX)

        self.ca = ChannelAccess(device_prefix=DEVICE_PREFIX,
                                default_timeout=15)

        self._lewis.backdoor_run_function_on_device("reinitialise")
        self._lewis.backdoor_set_on_device("comms_initialized", True)

        # Used for daisy chained Danfysiks, default is a single Danfysik so we don't need an id
        self.id_prefixes = [""]

        self.current_readback_factor = 1

        self.set_autoonoff(False)

    def set_autoonoff(self, state):
        """
        Sets the status of the AUTOONOFF pv.

        Args:
            state (bool): True to enable AUTOONOFF, false otherwise
        """
        state_desc = "Enabled" if state else "Disabled"

        if self.ca.get_pv_value("AUTOONOFF") != state_desc:
            old_autoonoff_disp = int(self.ca.get_pv_value("AUTOONOFF.DISP"))
            self.ca.set_pv_value("AUTOONOFF.DISP",
                                 0,
                                 wait=True,
                                 sleep_after_set=0)
            self.ca.set_pv_value("AUTOONOFF", state, sleep_after_set=0)
            self.ca.assert_that_pv_is("AUTOONOFF", state_desc)
            self.ca.set_pv_value("AUTOONOFF.DISP",
                                 old_autoonoff_disp,
                                 sleep_after_set=0)
Example #24
0
class MezfliprTests(unittest.TestCase):
    def setUp(self):
        self._lewis, self._ioc = get_running_lewis_and_ioc(
            EMULATOR_NAME, DEVICE_PREFIX)

        self.ca = ChannelAccess(device_prefix=DEVICE_PREFIX)

    def test_WHEN_ioc_is_started_THEN_ioc_is_not_disabled(self):
        self.ca.assert_that_pv_is("DISABLE", "COMMS ENABLED")

    @skip_if_recsim("Disconnection simulation not implemented in recsim")
    def test_GIVEN_device_is_connected_THEN_can_read_id(self):
        self.ca.assert_that_pv_is("ID", "Flipper Control")
        self.ca.assert_that_pv_alarm_is("ID", self.ca.Alarms.NONE)

    @parameterized.expand(["ANALYSER", "POLARISER"])
    def test_GIVEN_amplitude_is_set_THEN_amplitude_can_be_read_back(
            self, flipper):
        for val in [0., 0.12, 2.99]:  # Amplitude should be limited to 3A
            self.ca.assert_setting_setpoint_sets_readback(
                val, readback_pv="{}:AMPLITUDE".format(flipper))

    @parameterized.expand(["ANALYSER", "POLARISER"])
    def test_GIVEN_compensation_is_set_THEN_compensation_can_be_read_back(
            self, flipper):
        for val in [0., 0.12, 5000.5]:
            self.ca.assert_setting_setpoint_sets_readback(
                val, readback_pv="{}:COMPENSATION".format(flipper))

    @parameterized.expand(["ANALYSER", "POLARISER"])
    def test_GIVEN_dt_is_set_THEN_dt_can_be_read_back(self, flipper):
        for val in [0., -0.12, -5000.5]:  # DT only accepts negative values.
            self.ca.assert_setting_setpoint_sets_readback(
                val, readback_pv="{}:DT".format(flipper))

    @parameterized.expand(["ANALYSER", "POLARISER"])
    def test_GIVEN_constant_is_set_THEN_constant_can_be_read_back(
            self, flipper):
        for val in [0., 0.12, 5000.5]:
            self.ca.assert_setting_setpoint_sets_readback(
                val, readback_pv="{}:CONSTANT".format(flipper))

    @parameterized.expand(["ANALYSER", "POLARISER"])
    def test_GIVEN_constant_is_set_THEN_constant_can_be_read_back(
            self, flipper):
        for filename in [r"C:\a.txt", r"C:\b.txt"]:
            self.ca.assert_setting_setpoint_sets_readback(
                filename, readback_pv="{}:FILENAME".format(flipper))

    @parameterized.expand([
        "Analyser Off Pol. Off",
        "Analyser Off Pol. On",
        "Analyser On Pol. Off",
        "Analyser On Pol. On",
    ])
    def test_GIVEN_toggle_state_is_set_THEN_toggle_state_can_be_read_back(
            self, toggle_state):
        self.ca.set_pv_value("TOGGLE:SP", toggle_state)
        self.ca.assert_that_pv_is("TOGGLE", toggle_state)
        self.ca.assert_that_pv_alarm_is("TOGGLE", self.ca.Alarms.NONE)
class Sans2dVacuumTankTest(unittest.TestCase):
    """
    Tests for the SANS2D vacuum tank, based on a FINS PLC.
    """
    def setUp(self):
        self._ioc = IOCRegister.get_running("FINS_01")
        self.ca = ChannelAccess(device_prefix=ioc_prefix)

    @parameterized.expand(parameterized_list([-5, 0, 3, 5, 7, 9, 16]))
    def test_WHEN_set_tank_status_to_unknown_value_THEN_error_status(
            self, _, status_rval):
        self.ca.set_pv_value("SIM:TANK:STATUS", status_rval)
        self.ca.assert_that_pv_is("TANK:STATUS", "ERROR: STATUS UNKNOWN")
        self.ca.assert_that_pv_alarm_is("TANK:STATUS", "MAJOR")

    @parameterized.expand([(1, "ATMOSPHERE"), (2, "VAC DOWN"),
                           (4, "AT VACUUM"), (8, "VENTING")])
    def test_WHEN_set_tank_status_to_known_value_THEN_no_error(
            self, status_rval, status_val):
        self.ca.set_pv_value("SIM:TANK:STATUS", status_rval)
        self.ca.assert_that_pv_is("TANK:STATUS", status_val)
        self.ca.assert_that_pv_alarm_is("TANK:STATUS", "NO_ALARM")
class EgxcolimTests(unittest.TestCase):
    """
    Tests for the egxcolim IOC.
    """

    directions = ["NORTH", "SOUTH"]
    axes = ["X"]

    def setUp(self):
        self._ioc = IOCRegister.get_running(DEVICE_PREFIX)

        self.ca = ChannelAccess(20, device_prefix=DEVICE_PREFIX)
        self.ca.assert_that_pv_exists("DISABLE", timeout=30)

    def test_WHEN_ioc_is_started_THEN_ioc_is_not_disabled(self):
        self.ca.assert_that_pv_is("DISABLE", "COMMS ENABLED")

    def test_WHEN_setpoint_is_set_THEN_readback_updates(self):
        for direction in self.directions:
            for axis in self.axes:
                self.ca.assert_setting_setpoint_sets_readback(
                    123, "{direction}:{axis}".format(direction=direction,
                                                     axis=axis))
class Tpg300Tests(unittest.TestCase):
    """
    Tests for the TPG300.
    """

    def setUp(self):
        self._lewis, self._ioc = get_running_lewis_and_ioc("tpg300", DEVICE_PREFIX)
        self.ca = ChannelAccess(20, device_prefix=DEVICE_PREFIX)

    def tearDown(self):
        self._connect_emulator()

    def _set_pressure(self, expected_pressure, channel):
        prop = "pressure_{}".format(channel.lower())
        pv = "SIM:PRESSURE"
        self._lewis.backdoor_set_on_device(prop, expected_pressure)
        self._ioc.set_simulated_value(pv, expected_pressure)

    def _set_units(self, unit):
        self._lewis.backdoor_run_function_on_device("backdoor_set_unit", [unit.value])
        self._ioc.set_simulated_value("SIM:UNITS", unit.name)

    def _connect_emulator(self):
        self._lewis.backdoor_run_function_on_device("connect")

    def _disconnect_emulator(self):
        self._lewis.backdoor_run_function_on_device("disconnect")

    def test_that_GIVEN_a_connected_emulator_WHEN_ioc_started_THEN_ioc_is_not_disabled(self):
        self.ca.assert_that_pv_is("DISABLE", "COMMS ENABLED")

    def test_that_GIVEN_a_connected_emulator_WHEN_units_are_set_THEN_unit_is_the_same_as_backdoor(self):
        for unit in Units:
            self._set_units(unit)

            expected_unit = unit.name
            self.ca.assert_that_pv_is("UNITS", expected_unit)

    def test_that_GIVEN_a_connected_emulator_and_pressure_value_WHEN_set_pressure_is_set_THEN_the_ioc_is_updated(self):
        for expected_pressure, channel in product(TEST_PRESSURES, CHANNELS):
            pv = "PRESSURE_{}".format(channel)
            self._set_pressure(expected_pressure, channel)
            self.ca.assert_that_pv_is(pv, expected_pressure)

    @skip_if_recsim("Recsim is unable to simulate a disconnected device")
    def test_that_GIVEN_a_disconnected_emulator_WHEN_getting_pressure_THEN_INVALID_alarm_shows(self):
        self._disconnect_emulator()

        for channel in CHANNELS:
            pv = "PRESSURE_{}".format(channel)
            self.ca.assert_that_pv_alarm_is(pv, self.ca.Alarms.INVALID)
Example #28
0
class GamryTests(unittest.TestCase):
    """
    Tests for the Gamry.
    """

    def setUp(self):
        self._lewis, self._ioc = get_running_lewis_and_ioc("gamry", DEVICE_PREFIX)
        self.assertIsNotNone(self._lewis)
        self.assertIsNotNone(self._ioc)

        self.ca = ChannelAccess(device_prefix=DEVICE_PREFIX)

    def test_GIVEN_start_charging_WHEN_charge_completed_THEN_charging_finished_received(self):
        self.ca.assert_that_pv_is("CHARGE:STAT", "Idle")
        self.ca.set_pv_value("CHARGE:SP", 1)
        self.ca.assert_that_pv_is("CHARGE:STAT", "Charging", timeout=2)
        self.ca.assert_that_pv_is("CHARGE:STAT", "Idle", timeout=10)
class GalilmulTests(unittest.TestCase):
    """
    Tests for loading multiple motor controllers into a single IOC
    """
    def setUp(self):
        self._ioc = IOCRegister.get_running(DEVICE_PREFIX)
        self.assertIsNotNone(self._ioc)

        self.ca = ChannelAccess(device_prefix=None, default_timeout=20)

    def test_GIVEN_ioc_started_THEN_pvs_for_all_motors_exist(self):
        for controller in ("01", "02"):
            for motor in ["{:02d}".format(mtr) for mtr in range(1, 8 + 1)]:
                self.ca.assert_that_pv_exists("MOT:MTR{}{}".format(
                    controller, motor))

    def test_GIVEN_ioc_started_THEN_axes_for_all_motors_exist(self):
        for controller in (1, 2):
            for motor in range(1, 8 + 1):
                self.ca.assert_that_pv_exists("GALILMUL_01:{}:AXIS{}".format(
                    controller, motor))

    def test_GIVEN_axis_moved_THEN_other_axes_do_not_move(self):
        # This is to check that axes are independent, i.e. they're not accidentally using the same underlying driver

        # Set all motors to zero
        for controller in ("01", "02"):
            for motor in ["{:02d}".format(mtr) for mtr in range(1, 8 + 1)]:
                self.ca.set_pv_value("MOT:MTR{}{}".format(controller, motor),
                                     0)
                self.ca.assert_that_pv_is(
                    "MOT:MTR{}{}".format(controller, motor), 0)

        # Move motor 0101
        self.ca.set_pv_value("MOT:MTR0101", 20)
        self.ca.assert_that_pv_is("MOT:MTR0101", 20)

        # Check all other motors are still at zero
        for controller in ("01", "02"):
            for motor in ["{:02d}".format(mtr) for mtr in range(1, 8 + 1)]:
                if controller == "01" and motor == "01":
                    continue
                self.ca.assert_that_pv_is(
                    "MOT:MTR{}{}".format(controller, motor), 0)
class Ag3631aTests(unittest.TestCase):
    """
    Tests for the AG3631A.
    """
    def setUp(self):
        self._ioc = IOCRegister.get_running(DEVICE_PREFIX)

        self.ca = ChannelAccess(20, DEVICE_PREFIX)
        self.ca.assert_that_pv_exists("DISABLE", timeout=30)

    def test_WHEN_ioc_is_started_THEN_ioc_is_not_disabled(self):
        self.ca.assert_that_pv_is("DISABLE", "COMMS ENABLED")

    def test_GIVEN_voltage_set_WHEN_read_THEN_voltage_is_as_set(self):
        set_voltage = 123.456
        self.ca.set_pv_value("VOLT:SP", set_voltage)
        self.ca.assert_that_pv_is("VOLT:SP", set_voltage)

        self.ca.assert_that_pv_is("VOLT", set_voltage)