def test_enable_enabled_session(session: Session):
    try:
        session.enable_event(EventType.service_request)
    except EventNotDisabledError:
        pass
    with pytest.raises(EventNotDisabledError):
        session.enable_event(EventType.service_request)
Example #2
0
    def new_session(self, session: Session = None) -> int:

        new_session_idx = len(self._sessions) + 1

        if session is None:
            session = Session(new_session_idx, "MOCK0::name::INSTR")

        session.session_index = new_session_idx
        self._sessions[session.session_index] = session
        return new_session_idx
def test_unsupported_event_errors(session: Session):
    unsupported_event = EventType.tcpip_connect
    with pytest.raises(EventNotSupportedError):
        session.enable_event(unsupported_event)
    with pytest.raises(EventNotSupportedError):
        session.disable_event(unsupported_event)
    with pytest.raises(EventNotSupportedError):
        session.wait_for_event(unsupported_event, timeout=timedelta(0))
    with pytest.raises(EventNotSupportedError):
        session.set_event(unsupported_event)
    with pytest.raises(EventNotSupportedError):
        session.discard_events(unsupported_event)
Example #4
0
    def open(
            self,
            manager_session_idx: int,
            resource_name: str,
            access_mode=constants.AccessModes.no_lock,
            open_timeout=constants.VI_TMO_IMMEDIATE
    ) -> Tuple[int, STATUS_CODE]:

        if resource_name not in resources:
            raise ValueError(f"Unknown resource {resource_name}")

        device = resources[resource_name]
        session = Session(manager_session_idx, resource_name)
        session.device = device
        new_session_index = self.new_session(session)
        return new_session_index, constants.StatusCode.success
def test_disable_event(session: Session):
    # Make sure event is disabled
    try:
        session.disable_event(EventType.service_request)
    except EventNotEnabledError:
        pass
    with pytest.raises(EventNotEnabledError):
        session.set_event(EventType.service_request)
    with pytest.raises(EventNotEnabledError):
        session.discard_events(EventType.service_request)
    with pytest.raises(EventNotEnabledError):
        session.disable_event(EventType.service_request)
    with pytest.raises(EventNotEnabledError):
        try:
            session.wait_for_event(EventType.service_request,
                                   timeout=timedelta(0))
        except EventTimeoutError:
            # If we do get here ignore exception so assert catches missed exception
            pass
def session() -> Session:
    # Set supported events for testing
    Session._SUPPORTED_EVENTS = [
        EventType.service_request,
        EventType.pxi_interrupt,
        EventType.gpib_talk,
    ]
    return Session(
        resource_manager_session=0,
        resource_name='MOCK0::mock5::INSTR',
    )
    dev = Mocker5()
    session.device = dev
def test_multiple_events(session: Session):
    for cur_event in session._SUPPORTED_EVENTS:
        logging.getLogger().debug(session._events_enabled)
        try:
            session.enable_event(cur_event)
        except EventNotDisabledError:
            pass
    # Verify that all events enabled
    for cur_event in session._SUPPORTED_EVENTS:
        with pytest.raises(EventNotDisabledError):
            session.enable_event(cur_event)

    enabled_events = list(session._SUPPORTED_EVENTS)
    # Disable each event
    while enabled_events:
        cur_event = enabled_events.pop(0)
        session.disable_event(cur_event)
        # Make sure other events are still enabled
        for verify_enable_event in enabled_events:
            with pytest.raises(EventNotDisabledError):
                session.enable_event(verify_enable_event)
def test_discard_event(session: Session):
    # Make sure event is enabled
    try:
        session.enable_event(EventType.service_request)
    except EventNotDisabledError:
        pass
    # Check that there are no events in queue
    with pytest.raises(EventTimeoutError):
        session.wait_for_event(EventType.service_request, timeout=timedelta(0))
    session.discard_events(EventType.service_request)
    # Check there there are no events in queue
    with pytest.raises(EventTimeoutError):
        session.wait_for_event(EventType.service_request, timeout=timedelta(0))
    session.set_event(EventType.service_request)
    # Check that there is an event to get
    session.wait_for_event(EventType.service_request, timeout=timedelta(0))
    # Check there there are no events in queue
    with pytest.raises(EventTimeoutError):
        session.wait_for_event(EventType.service_request, timeout=timedelta(0))
def test_session(session: Session):
    session.enable_event(EventType.service_request)
    session.set_event(EventType.service_request)
    session.wait_for_event(EventType.service_request, timeout=timedelta(0))
    session.set_event(EventType.service_request)
    assert (not session._events[EventType.service_request].empty())
    session.discard_events(EventType.service_request)
    assert (session._events[EventType.service_request].empty())
    session.disable_event(EventType.service_request)
Example #10
0
def test_session():
    Session(0, "TCPIP0::mock:INSTR")