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)
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)
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_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