Exemplo n.º 1
0
    def __init__(self, loop=None):
        self._notifications = Notifications(loop=loop)
        self._unsubscribe = []
        self._unsubscribe += [
            subscribe(Session.TOPIC, self._notifications.on_notify)
        ]
        self._unsubscribe += [
            subscribe(CalibrationManager.TOPIC, self._notifications.on_notify)
        ]

        self.session_manager = SessionManager(loop=loop)
        self.calibration_manager = CalibrationManager(loop=loop)
Exemplo n.º 2
0
    def run(self):
        def on_command(message):
            if message['$'] == 'before':
                self.log_append()
            if message['name'] == types.PAUSE:
                self.set_state('paused')
            if message['name'] == types.RESUME:
                self.set_state('running')

        self._reset()

        _unsubscribe = subscribe(types.COMMAND, on_command)
        self.startTime = now()
        self.set_state('running')

        try:
            self.resume()
            self._pre_run_hooks()
            if self._is_json_protocol:
                execute_protocol(self._protocol)
            else:
                exec(self._protocol, {})
            self.set_state('finished')
            robot.home()
        except Exception as e:
            log.exception("Exception during run:")
            self.error_append(e)
            self.set_state('error')
            raise e
        finally:
            _unsubscribe()

        return self
Exemplo n.º 3
0
    def clear_commands(self):
        self._commands.clear()
        if self._unsubscribe_commands:
            self._unsubscribe_commands()

        def on_command(message):
            payload = message.get('payload')
            text = payload.get('text')
            if text is None:
                return

            if message['$'] == 'before':
                self._commands.append(text.format(**payload))

        self._unsubscribe_commands = subscribe(commands.types.COMMAND,
                                               on_command)
Exemplo n.º 4
0
def test_add_listener():
    stack = []
    calls = []

    def on_notify(message):
        assert message['name'] == 'command'
        payload = message['payload']
        description = payload['description']

        if message['$'] == 'before':
            stack.append(message)
            calls.append({'level': len(stack), 'description': description})
        else:
            stack.pop()

    unsubscribe = subscribe('command', on_notify)

    A(0, 1)
    B(2)
    C(3, 4)

    expected = [{
        'level': 1,
        'description': '0 1 foo'
    }, {
        'level': 2,
        'description': '0'
    }, {
        'level': 1,
        'description': '2'
    }, {
        'level': 1,
        'description': '3 4 bar'
    }, {
        'level': 2,
        'description': '0'
    }]

    assert calls == expected

    unsubscribe()
    A(0, 2)

    assert calls == expected, 'No calls expected after unsubscribe()'
Exemplo n.º 5
0
    def _simulate(self):
        self._reset()

        stack = []
        res = []
        commands = []

        self._containers.clear()
        self._instruments.clear()
        self._modules.clear()
        self._interactions.clear()

        def on_command(message):
            payload = message['payload']
            description = payload.get('text', '').format(
                **payload
            )

            if message['$'] == 'before':
                level = len(stack)

                stack.append(message)
                commands.append(payload)

                res.append(
                    {
                        'level': level,
                        'description': description,
                        'id': len(res)})
            else:
                stack.pop()

        unsubscribe = subscribe(types.COMMAND, on_command)

        try:
            # ensure actual pipettes are cached before driver is disconnected
            robot.cache_instrument_models()

            # TODO (artyom, 20171005): this will go away
            # once robot / driver simulation flow is fixed
            robot.disconnect()
            if self._is_json_protocol:
                execute_protocol(self._protocol)
            else:
                exec(self._protocol, {})
        finally:
            # physically attached pipettes are re-cached during robot.connect()
            # which is important, because during a simulation, the robot could
            # think that it holds a pipette model that it actually does not
            robot.connect()
            unsubscribe()

            instruments, containers, modules, interactions = _accumulate(
                [_get_labware(command) for command in commands])

            self._containers.extend(_dedupe(containers))
            self._instruments.extend(_dedupe(instruments))
            self._modules.extend(_dedupe(modules))
            self._interactions.extend(_dedupe(interactions))

        return res