Skip to content

Commit

Permalink
Fix GH tests (#952)
Browse files Browse the repository at this point in the history
Summary:

Fixes OSS tests I broke :(

Differential Revision: D67107107
  • Loading branch information
connernilsen authored and facebook-github-bot committed Dec 12, 2024
1 parent b862790 commit ef2d5b5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 261 deletions.
259 changes: 0 additions & 259 deletions client/commands/tests/language_server_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1642,265 +1642,6 @@ async def test_did_change__basic(self) -> None:
expectations,
)

@setup.async_test
async def test_did_change__with_type_errors(self) -> None:
unsaved_file_content = "# some example code"
tracked_path = Path("/tracked.py")
for telemetry in (
features.TelemetryAvailability.ENABLED,
features.TelemetryAvailability.DISABLED,
):
querier = server_setup.MockDaemonQuerier(
mock_type_errors={
tracked_path: [
error.Error(
line=1,
column=1,
stop_line=2,
stop_column=2,
path=Path("/tracked.py"),
code=42,
name="name",
description="description",
),
]
}
)
setup = server_setup.create_pyre_language_server_api_setup(
opened_documents={
tracked_path: state.OpenedDocumentState(
code=unsaved_file_content,
)
},
querier=querier,
server_options=server_setup.create_server_options(
language_server_features=features.LanguageServerFeatures(
unsaved_changes=features.UnsavedChangesAvailability.ENABLED,
telemetry=telemetry,
),
),
)
api = setup.api
output_writer = setup.output_writer
await api.process_did_change_request(
parameters=lsp.DidChangeTextDocumentParameters(
text_document=lsp.TextDocumentIdentifier(
uri=lsp.DocumentUri.from_file_path(tracked_path).unparse(),
),
content_changes=[lsp.ContentChange(text=unsaved_file_content)],
),
)
# When unsaved changes is not enabled, we should send no requests.
self.assertEqual(
querier.requests,
[
{"path": tracked_path, "code": unsaved_file_content},
],
)
expect_diagnostics = self._expect_diagnostics(
uri="file:///tracked.py",
diagnostics=[
lsp.Diagnostic(
range=lsp.LspRange(
start=lsp.LspPosition(line=0, character=1),
end=lsp.LspPosition(line=1, character=2),
),
message="description",
severity=lsp.DiagnosticSeverity.ERROR,
code="pyre (documentation link)",
source="Pyre",
code_description=lsp.CodeDescription(
href="https://pyre-check.org/docs/errors/#42-missing-overload-implementation"
),
)
],
)
if telemetry.is_enabled():
expectations = [
self._expect_telemetry_event(
operation="didChange",
result=None,
),
expect_diagnostics,
self._expect_telemetry_event(
operation="typeErrors",
result=None,
),
]
else:
expectations = [expect_diagnostics]
self._assert_output_messages(
output_writer,
expectations,
)

@setup.async_test
async def test_did_change__no_type_errors(self) -> None:
tracked_path = Path("/tracked.py")
for telemetry in (
features.TelemetryAvailability.ENABLED,
features.TelemetryAvailability.DISABLED,
):
querier = server_setup.MockDaemonQuerier(
mock_type_errors={},
)
setup = server_setup.create_pyre_language_server_api_setup(
opened_documents={
tracked_path: state.OpenedDocumentState(
code=server_setup.DEFAULT_FILE_CONTENTS
)
},
querier=querier,
server_options=server_setup.create_server_options(
language_server_features=features.LanguageServerFeatures(
unsaved_changes=features.UnsavedChangesAvailability.ENABLED,
telemetry=telemetry,
),
),
)
api = setup.api
output_writer = setup.output_writer
await api.process_did_change_request(
parameters=lsp.DidChangeTextDocumentParameters(
text_document=lsp.TextDocumentIdentifier(
uri=lsp.DocumentUri.from_file_path(tracked_path).unparse(),
),
content_changes=[
lsp.ContentChange(text=server_setup.DEFAULT_FILE_CONTENTS)
],
),
)
# When unsaved changes is not enabled, we should send no requests.
self.assertEqual(
querier.requests,
[
{"path": tracked_path, "code": server_setup.DEFAULT_FILE_CONTENTS},
],
)
expect_diagnostics = self._expect_diagnostics(
uri="file:///tracked.py",
diagnostics=[],
)
if telemetry.is_enabled():
expectations = [
self._expect_telemetry_event(
operation="didChange",
result=None,
),
expect_diagnostics,
self._expect_telemetry_event(
operation="typeErrors",
result=None,
),
]
else:
expectations = [expect_diagnostics]
self._assert_output_messages(
output_writer,
expectations,
)

@setup.async_test
async def test_did_change__debounce(self) -> None:
unsaved_file_content_list = [f"# some example code {i}" for i in range(3)]
tracked_path = Path("/tracked.py")
querier = server_setup.MockDaemonQuerier(
mock_type_errors={
tracked_path: [
error.Error(
line=1,
column=1,
stop_line=2,
stop_column=2,
path=Path("/tracked.py"),
code=42,
name="name",
description="description",
),
]
}
)
setup = server_setup.create_pyre_language_server_api_setup(
opened_documents={
tracked_path: state.OpenedDocumentState(
code=unsaved_file_content_list[0],
)
},
querier=querier,
server_options=server_setup.create_server_options(
language_server_features=features.LanguageServerFeatures(
unsaved_changes=features.UnsavedChangesAvailability.ENABLED,
type_errors=features.TypeErrorsAvailability.ENABLED,
telemetry=features.TelemetryAvailability.ENABLED,
),
),
)
api = setup.api
output_writer = setup.output_writer
for i in range(len(unsaved_file_content_list)):
await api.process_did_change_request(
parameters=lsp.DidChangeTextDocumentParameters(
text_document=lsp.TextDocumentIdentifier(
uri=lsp.DocumentUri.from_file_path(tracked_path).unparse(),
),
content_changes=[
lsp.ContentChange(text=unsaved_file_content_list[i])
],
),
)
setup.server_state.status_tracker.set_status(
state.ConnectionStatus.INCREMENTAL_CHECK
)
self.assertEqual(
querier.requests,
[
# we expect to be able to send only the first request, since the
# remaining requests will put the server in a non-ready state
{"path": tracked_path, "code": unsaved_file_content_list[0]}
],
)
expect_diagnostics = self._expect_diagnostics(
uri="file:///tracked.py",
diagnostics=[
lsp.Diagnostic(
range=lsp.LspRange(
start=lsp.LspPosition(line=0, character=1),
end=lsp.LspPosition(line=1, character=2),
),
message="description",
severity=lsp.DiagnosticSeverity.ERROR,
code="pyre (documentation link)",
source="Pyre",
code_description=lsp.CodeDescription(
href="https://pyre-check.org/docs/errors/#42-missing-overload-implementation"
),
)
],
)
expectations = [
self._expect_telemetry_event(
operation="didChange",
result=None,
),
expect_diagnostics,
self._expect_telemetry_event(
operation="typeErrors",
result=None,
),
self._expect_telemetry_event(
operation="didChange",
result=None,
),
self._expect_telemetry_event(
operation="didChange",
result=None,
),
]
self._assert_output_messages(
output_writer,
expectations,
)


class HoverTest(ApiTestCase):
@setup.async_test
Expand Down
4 changes: 2 additions & 2 deletions client/language_server/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class LanguageServerFeatures:
GlobalLazyTypeErrorsAvailability.ENABLED
)
per_target_type_errors: PerTargetTypeErrorsAvailability = (
PerTargetTypeErrorsAvailability.ENABLED
PerTargetTypeErrorsAvailability.DISABLED
)
unsaved_changes: UnsavedChangesAvailability = UnsavedChangesAvailability.DISABLED
telemetry: TelemetryAvailability = TelemetryAvailability.DISABLED
Expand All @@ -132,7 +132,7 @@ class LanguageServerFeatures:
inlay_hint: InlayHintAvailability = InlayHintAvailability.DISABLED
formatting: FormattingAvailability = FormattingAvailability.DISABLED
python_auto_targets: PythonAutoTargetsAvailability = (
PythonAutoTargetsAvailability.ENABLED
PythonAutoTargetsAvailability.DISABLED
)
use_system_pyautotargets: SystemPyAutoTargetsAvailability = (
SystemPyAutoTargetsAvailability.from_enabled(False)
Expand Down

0 comments on commit ef2d5b5

Please sign in to comment.