mirror of
https://github.com/tiennm99/serena.git
synced 2026-10-15 00:18:04 +00:00
Fix mypy issues in tests
This commit is contained in:
1 parent
177f0f46cb
commit
7513800a0f
7 files changed
+22
-17
No files matched your search
@@ -461,7 +461,6 @@ class TestSerenaAgent:
|
||||
needle = r'console.log("WebSocketManager initializing\nStatus OK");'
|
||||
repl = r'console.log("WebSocketManager initialized\nAll systems go!");'
|
||||
replace_content_tool = serena_agent.get_tool(ReplaceContentTool)
|
||||
mode: Literal["literal", "regex"]
|
||||
with project_file_modification_context(serena_agent, relative_path):
|
||||
result = replace_content_tool.apply(
|
||||
needle=re.escape(needle) if mode == "regex" else needle,
|
||||
|
||||
@@ -218,7 +218,7 @@ class EditingTest(ABC):
|
||||
with open(file_path, encoding="utf-8") as f:
|
||||
return f.read()
|
||||
|
||||
def run_test(self, content_after_ground_truth: str | SnapshotAssertion) -> None:
|
||||
def run_test(self, content_after_ground_truth: SnapshotAssertion) -> None:
|
||||
with self._setup() as symbol_retriever:
|
||||
content_before = self._read_file(self.rel_path)
|
||||
code_editor = LanguageServerCodeEditor(symbol_retriever)
|
||||
|
||||
@@ -2,6 +2,7 @@ import os
|
||||
import tempfile
|
||||
import threading
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
import pytest
|
||||
@@ -142,14 +143,14 @@ class TestFSharpLanguageServer:
|
||||
file_path = os.path.join("Program.fs")
|
||||
|
||||
# Use threading for cross-platform timeout (signal.SIGALRM is Unix-only)
|
||||
result = [None]
|
||||
exception = [None]
|
||||
result: dict[str, Any] = dict(value=None)
|
||||
exception: dict[str, Any] = dict(value=None)
|
||||
|
||||
def run_completion():
|
||||
try:
|
||||
result[0] = language_server.request_completions(file_path, 15, 10)
|
||||
result["value"] = language_server.request_completions(file_path, 15, 10)
|
||||
except Exception as e:
|
||||
exception[0] = e
|
||||
exception["value"] = e
|
||||
|
||||
thread = threading.Thread(target=run_completion, daemon=True)
|
||||
thread.start()
|
||||
@@ -160,10 +161,10 @@ class TestFSharpLanguageServer:
|
||||
# The important thing is that the language server doesn't crash
|
||||
return
|
||||
|
||||
if exception[0]:
|
||||
raise exception[0]
|
||||
if exception["value"]:
|
||||
raise exception["value"]
|
||||
|
||||
assert isinstance(result[0], list), "Completions should be a list"
|
||||
assert isinstance(result["value"], list), "Completions should be a list"
|
||||
|
||||
@pytest.mark.parametrize("language_server", [Language.FSHARP], indirect=True)
|
||||
def test_diagnostics(self, language_server: SolidLanguageServer) -> None:
|
||||
|
||||
@@ -12,13 +12,14 @@ from solidlsp.settings import SolidLSPSettings
|
||||
|
||||
@pytest.mark.groovy
|
||||
class TestGroovyLanguageServer:
|
||||
language_server: SolidLanguageServer | None = None
|
||||
test_repo_path: Path = Path(__file__).parent.parent.parent / "resources" / "repos" / "groovy" / "test_repo"
|
||||
|
||||
@classmethod
|
||||
def setup_class(cls):
|
||||
"""
|
||||
Set up test class with Groovy test repository.
|
||||
"""
|
||||
cls.test_repo_path = Path(__file__).parent.parent.parent / "resources" / "repos" / "groovy" / "test_repo"
|
||||
|
||||
if not cls.test_repo_path.exists():
|
||||
pytest.skip("Groovy test repository not found")
|
||||
|
||||
@@ -56,10 +57,11 @@ class TestGroovyLanguageServer:
|
||||
"""
|
||||
Clean up language server.
|
||||
"""
|
||||
if hasattr(cls, "language_server"):
|
||||
if cls.language_server is not None:
|
||||
cls.language_server.stop()
|
||||
|
||||
def test_find_symbol(self) -> None:
|
||||
assert self.language_server is not None
|
||||
symbols = self.language_server.request_full_symbol_tree()
|
||||
assert SymbolUtils.symbol_tree_contains_name(symbols, "Main"), "Main class not found in symbol tree"
|
||||
assert SymbolUtils.symbol_tree_contains_name(symbols, "Utils"), "Utils class not found in symbol tree"
|
||||
@@ -67,6 +69,7 @@ class TestGroovyLanguageServer:
|
||||
assert SymbolUtils.symbol_tree_contains_name(symbols, "ModelUser"), "ModelUser class not found in symbol tree"
|
||||
|
||||
def test_find_referencing_class_symbols(self) -> None:
|
||||
assert self.language_server is not None
|
||||
file_path = os.path.join("src", "main", "groovy", "com", "example", "Utils.groovy")
|
||||
refs = self.language_server.request_references(file_path, 3, 6)
|
||||
assert any("Main.groovy" in ref.get("relativePath", "") for ref in refs), "Utils should be referenced from Main.groovy"
|
||||
@@ -93,6 +96,7 @@ class TestGroovyLanguageServer:
|
||||
assert len(model_user_refs) >= 1, f"Model should be referenced from ModelUser.groovy at least 1 time, found {len(model_user_refs)}"
|
||||
|
||||
def test_overview_methods(self) -> None:
|
||||
assert self.language_server is not None
|
||||
symbols = self.language_server.request_full_symbol_tree()
|
||||
assert SymbolUtils.symbol_tree_contains_name(symbols, "Main"), "Main missing from overview"
|
||||
assert SymbolUtils.symbol_tree_contains_name(symbols, "Utils"), "Utils missing from overview"
|
||||
|
||||
@@ -137,7 +137,7 @@ class TestLuaLanguageServer:
|
||||
assert len(refs) >= 5, f"Should find at least 5 references to calculator.add, found {len(refs)}"
|
||||
|
||||
# Verify exact reference locations
|
||||
ref_files = {}
|
||||
ref_files: dict[str, list[int]] = {}
|
||||
for ref in refs:
|
||||
filename = ref.get("uri", "").split("/")[-1]
|
||||
if filename not in ref_files:
|
||||
@@ -193,7 +193,7 @@ class TestLuaLanguageServer:
|
||||
assert len(refs) >= 1, f"Should find at least 1 reference to utils.trim, found {len(refs)}"
|
||||
|
||||
# Verify exact reference locations
|
||||
ref_files = {}
|
||||
ref_files: dict[str, list[int]] = {}
|
||||
for ref in refs:
|
||||
filename = ref.get("uri", "").split("/")[-1]
|
||||
if filename not in ref_files:
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# type: ignore
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -89,7 +89,7 @@ class TestSwiftLanguageServerBasics:
|
||||
# First, let's check if Utils is used anywhere (it might not be in this simple test)
|
||||
# We'll test goto_definition on Utils struct itself
|
||||
symbols = language_server.request_document_symbols(utils_file).get_all_symbols_and_roots()
|
||||
utils_symbol = next((s for s in symbols[0] if s.get("name") == "Utils"), None)
|
||||
utils_symbol = next(s for s in symbols[0] if s.get("name") == "Utils")
|
||||
|
||||
sel_start = utils_symbol["selectionRange"]["start"]
|
||||
definitions = language_server.request_definition(utils_file, sel_start["line"], sel_start["character"])
|
||||
@@ -106,7 +106,7 @@ class TestSwiftLanguageServerBasics:
|
||||
file_path = os.path.join("src", "main.swift")
|
||||
symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()
|
||||
|
||||
calculator_symbol = next((s for s in symbols[0] if s.get("name") == "Calculator"), None)
|
||||
calculator_symbol = next(s for s in symbols[0] if s.get("name") == "Calculator")
|
||||
|
||||
sel_start = calculator_symbol["selectionRange"]["start"]
|
||||
references = language_server.request_references(file_path, sel_start["line"], sel_start["character"])
|
||||
@@ -128,7 +128,7 @@ class TestSwiftLanguageServerBasics:
|
||||
file_path = os.path.join("src", "main.swift")
|
||||
symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()
|
||||
|
||||
user_symbol = next((s for s in symbols[0] if s.get("name") == "User"), None)
|
||||
user_symbol = next(s for s in symbols[0] if s.get("name") == "User")
|
||||
|
||||
sel_start = user_symbol["selectionRange"]["start"]
|
||||
references = language_server.request_references(file_path, sel_start["line"], sel_start["character"])
|
||||
|
||||
Reference in new issue
Block a user