Ejemplo n.º 1
0
 def get_important_received_items(
     self, transcript: Transcript
 ) -> Iterable[Mapping[str, Any]]:
     for entry in transcript.values():
         received = entry.received or None
         if received is None:
             continue
         method = received.get("method") or ""
         if method == "window/progress" or method == "window/actionRequired":
             continue
         yield received
Ejemplo n.º 2
0
 def throw_on_skip(self, transcript: Transcript):
     failure_messages = [
         "Server busy",
         "timed out",
     ]
     for entry in transcript.values():
         received = entry.received
         if received is None:
             continue
         if received.get("error"):
             message = received["error"]["message"]
             for failure_message in failure_messages:
                 if failure_message in message:
                     raise unittest.SkipTest(message)
Ejemplo n.º 3
0
    def _flag_unhandled_notifications(
        self,
        handled_entries: AbstractSet[str],
        variables: VariableMap,
        transcript: Transcript,
        lsp_id_map: _LspIdMap,
    ) -> Iterable["_ErrorDescription"]:
        for transcript_id, entry in transcript.items():
            if transcript_id in handled_entries:
                continue

            received = entry.received
            if received is None:
                continue

            if entry.sent is not None:
                # We received a request and responded to it.
                continue

            method = received["method"]
            params = received["params"]
            payload = self._pretty_print_snippet(received)
            if "id" in received:
                description = f"""\
An unexpected request of type {method!r} was sent by the language server.
Here is the request payload:

{payload}
"""
                at_nocommit = "@" + "nocommit"
                remediation = f"""\
1) If this was unexpected, then the language server is buggy and should be
fixed.

2) To handle this request, add this directive to your test to wait for it and
respond to it before proceeding:

    .{self.wait_for_server_request.__name__}(
        method={method!r},
        params={params!r},
        result={{
            "{at_nocommit}": "fill in request data here",
        }},
    )
"""
            else:
                if any(
                    isinstance(message, _WaitForNotificationSpec)
                    and message.method == method
                    and interpolate_variables(
                        payload=message.params, variables=variables
                    )
                    == params
                    for message in self._messages
                ):
                    # This was a notification we we explicitly waiting for, so skip
                    # it.
                    continue

                uninterpolated_params = uninterpolate_variables(
                    payload=params, variables=variables
                )
                description = f"""\
An unexpected notification of type {method!r} was sent by the language server.
Here is the notification payload:

{payload}
"""
                remediation = f"""\
1) If this was unexpected, then the language server is buggy and should be
fixed.

2) If all notifications of type {method!r} should be ignored, add this directive
anywhere in your test:

    .{self.ignore_notifications.__name__}(method={method!r})

3) If this single instance of the notification was expected, add this directive
to your test to wait for it before proceeding:

    .{self.wait_for_notification.__name__}(
        method={method!r},
        params={uninterpolated_params!r},
    )
"""

            previous_request = self._find_previous_request(
                transcript, lsp_id_map, current_id=transcript_id
            )
            if previous_request is not None:
                request_context = self._get_context_for_traceback(
                    previous_request.traceback
                )
            else:
                request_context = "<no previous request was found>"
            context = f"""\
This was the most recent request issued from the language client before it
received the notification:

{request_context}"""

            yield _ErrorDescription(
                description=description, context=context, remediation=remediation
            )
Ejemplo n.º 4
0
 def _find_ignored_transcript_ids(self,
                                  transcript: Transcript) -> Iterable[str]:
     for transcript_id, entry in transcript.items():
         if (entry.received is not None and entry.received.get("method")
                 in self._ignored_notification_methods):
             yield transcript_id