示例#1
0
 def test_WHEN_motor_temperature_is_too_high_THEN_over_temperature_is_true(
         self):
     self.ca.assert_that_pv_is("TEMP:RANGECHECK", 0)
     with assert_log_messages(
             self._ioc,
             in_time=5,
             must_contain=ErrorStrings.MOTOR_TEMP_TOO_HIGH):
         self._lewis.backdoor_set_on_device("motor_temp", 46)
         self.ca.assert_that_pv_is("TEMP:RANGECHECK", 1)
示例#2
0
    def test_GIVEN_in_error_WHEN_error_string_changed_THEN_less_than_four_log_message_per_pv_logged_in_five_secs(
            self):
        self._lewis.backdoor_set_on_device("out_error", "OLD_ERROR")
        self._set_error_state(True)

        new_error = "A_NEW_ERROR"
        # Actually expect 3 messages but checking for 4 as a buffer see comment above
        with assert_log_messages(self._ioc, self.NUM_OF_PVS * 4, 5) as log:
            self._lewis.backdoor_set_on_device("out_error", new_error)

        self.assertTrue(any([new_error in _ for _ in log.messages[-3:]]))
    def test_GIVEN_setpoint_is_at_600Hz_and_device_already_running_WHEN_send_run_command_THEN_device_does_not_break(
            self):

        self._turn_on_bearings_and_run()

        self.ca.set_pv_value("SPEED:SP", 600)
        self.ca.assert_that_pv_is_number("SPEED", 600, tolerance=0.1)

        with assert_log_messages(self._ioc,
                                 in_time=2,
                                 must_contain=ErrorStrings.TURN_ON_AT_600HZ):
            self.ca.set_pv_value("COMMAND:SP", 3)  # Switch drive on and run
示例#4
0
    def test_WHEN_electronics_temperature_is_too_high_THEN_switch_drive_off_is_sent(
            self):
        # Reset last command so that we can tell that it's changed later on
        self._lewis.backdoor_set_on_device("last_command", "0000")
        self.ca.assert_that_pv_is("LASTCOMMAND", "0000")

        with assert_log_messages(
                self._ioc,
                in_time=5,
                must_contain=ErrorStrings.ELECTRONICS_TEMP_TOO_HIGH):
            # Temperature = 46, this is higher than the allowed value (45)
            self._lewis.backdoor_set_on_device("electronics_temp", 46)

            # Assert that "switch drive off" was sent
            self.ca.assert_that_pv_is("LASTCOMMAND", "0002")
    def test_WHEN_chopper_speed_is_too_high_THEN_switch_drive_off_is_sent(
            self):
        self._lewis.backdoor_set_on_device("magneticbearing", True)
        self.ca.assert_that_pv_is("STATUS.B3", "1")

        # Reset last command so that we can tell that it's changed later on
        self._lewis.backdoor_set_on_device("last_command", "0000")
        self.ca.assert_that_pv_is("LASTCOMMAND", "0000")

        with assert_log_messages(self._ioc,
                                 in_time=2,
                                 must_contain=ErrorStrings.SOFTWARE_OVERSPEED):
            # Speed = 610, this is higher than the maximum allowed speed (606)
            self._lewis.backdoor_set_on_device("speed", 610)

            # Assert that "switch drive off" was sent
            self.ca.assert_that_pv_is("LASTCOMMAND", "0002")
    def test_WHEN_chopper_speed_is_too_high_THEN_status_updates(self):

        too_fast = 700

        # Turn on magnetic bearings otherwise device will report it is broken
        self._lewis.backdoor_set_on_device("magneticbearing", True)
        self.ca.assert_that_pv_is("STATUS.B3", "1")

        with assert_log_messages(
                self._ioc,
                in_time=2,
                must_contain=ErrorStrings.CONTROLLER_OVERSPEED):
            self._lewis.backdoor_set_on_device("speed", too_fast)
            self.ca.assert_that_pv_is("STATUS.BA", "1")

        self._lewis.backdoor_set_on_device("speed", 0)
        self.ca.assert_that_pv_is("STATUS.BA", "0")
示例#7
0
    def test_WHEN_emulator_disconnected_THEN_data_in_alarm_and_valid_on_reconnect(
            self):
        self.ca.assert_that_pv_alarm_is_not("DATA",
                                            ChannelAccess.Alarms.INVALID)
        self.emulator.disconnect_device()
        self.ca.assert_that_pv_alarm_is("DATA", ChannelAccess.Alarms.INVALID)

        # Check we don't get excessive numbers of messages if we stay disconnected for 15s (up to 15 messages seems
        # reasonable - 1 per second on average)
        with assert_log_messages(self._ioc, number_of_messages=15):
            sleep(15)
            # Double-check we are still in alarm
            self.ca.assert_that_pv_alarm_is("DATA",
                                            ChannelAccess.Alarms.INVALID)

        self.emulator.reconnect_device()
        self.ca.assert_that_pv_alarm_is_not("DATA",
                                            ChannelAccess.Alarms.INVALID,
                                            timeout=5)
        self.ca.assert_that_pv_value_is_changing("DATA", 1)
    def test_GIVEN_magnetic_bearing_is_off_WHEN_chopper_speed_is_moving_THEN_switch_drive_on_and_stop_is_sent(
            self):

        # Magnetic bearings should have been turned off in setUp
        self.ca.assert_that_pv_is("STATUS.B3", "0")

        # Reset last command so that we can tell that it's changed later on
        self._lewis.backdoor_set_on_device("last_command", "0000")
        self.ca.assert_that_pv_is("LASTCOMMAND", "0000")

        with assert_log_messages(
                self._ioc,
                in_time=2,
                must_contain=ErrorStrings.CHOPPER_AT_SPEED_WITH_BEARINGS_OFF):
            # Speed = 7 because that's higher than the threshold in the IOC (5)
            # but lower than the threshold in the emulator (10)
            self._lewis.backdoor_set_on_device("speed", 7)

            # Assert that "switch drive on and stop" was sent
            self.ca.assert_that_pv_is("LASTCOMMAND", "0001")
    def test_GIVEN_autozero_voltages_are_out_of_range_WHEN_chopper_is_moving_THEN_range_check_fails(
            self):
        for number, position in itertools.product([1, 2], ["upper", "lower"]):
            self.ca.assert_that_pv_is("AUTOZERO:RANGECHECK", 0)

            with assert_log_messages(self._ioc,
                                     in_time=2,
                                     must_contain=ErrorStrings.
                                     CONTROLLER_AUTOZERO_OUT_OF_RANGE):
                # Set autozero voltage too high
                self._lewis.backdoor_set_on_device(
                    "autozero_{n}_{p}".format(n=number, p=position), 3.2)
                # Assert
                self.ca.assert_that_pv_is("AUTOZERO:RANGECHECK", 1)

            # Reset relevant autozero voltage back to zero
            self._lewis.backdoor_set_on_device(
                "autozero_{n}_{p}".format(n=number, p=position), 0)
            self.ca.assert_that_pv_is_number("AUTOZERO:{n}:{p}".format(
                n=number, p=position.upper()),
                                             0,
                                             tolerance=0.1)
    def test_GIVEN_autozero_voltages_are_out_of_range_WHEN_chopper_is_moving_THEN_switch_drive_on_and_stop_is_sent(
            self):
        for number, position in itertools.product([1, 2], ["upper", "lower"]):

            err = None
            for i in range(10):  # Try up to 10 times.
                try:
                    self._lewis.backdoor_run_function_on_device("reset")
                    # Assert that the last command is zero as expected
                    self.ca.assert_that_pv_is("LASTCOMMAND", "0000")
                    # Check that the last command is not being set to something else by the IOC
                    self.ca.assert_that_pv_value_is_unchanged("LASTCOMMAND",
                                                              wait=10)
                    break
                except AssertionError as e:
                    err = e
            else:  # no-break
                raise err

            with assert_log_messages(
                    self._ioc,
                    in_time=2,
                    must_contain=ErrorStrings.SOFTWARE_AUTOZERO_OUT_OF_RANGE):
                # Set autozero voltage too high and set device moving
                self._lewis.backdoor_set_on_device(
                    "autozero_{n}_{p}".format(n=number, p=position), 3.2)
                self._lewis.backdoor_set_on_device("speed", 7)

                # Assert that "switch drive on and stop" was sent
                self.ca.assert_that_pv_is("LASTCOMMAND", "0001")

            # Reset relevant autozero voltage back to zero
            self._lewis.backdoor_set_on_device(
                "autozero_{n}_{p}".format(n=number, p=position), 0)
            self.ca.assert_that_pv_is_number("AUTOZERO:{n}:{p}".format(
                n=number, p=position.upper()),
                                             0,
                                             tolerance=0.1)
示例#11
0
 def test_GIVEN_in_error_WHEN_error_cleared_THEN_less_than_two_log_message_per_pv_logged(
         self):
     self._set_error_state(True)
     # Actually expect 1 message but checking for 2 as a buffer see comment above
     with assert_log_messages(self._ioc, self.NUM_OF_PVS * 2):
         self._set_error_state(False)