Skip to content

Commit b101025

Browse files
committed
coverage for lsp
1 parent b3e828a commit b101025

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

tests/test_lsp.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,54 @@ async def test_execute_command_query(mock_language_server, mock_config):
122122
mock_language_server.progress.end.assert_called()
123123

124124

125+
@pytest.mark.asyncio
126+
async def test_execute_command_query_default_proj_root(
127+
mock_language_server, mock_config
128+
):
129+
with (
130+
patch(
131+
"vectorcode.lsp_main.parse_cli_args", new_callable=AsyncMock
132+
) as mock_parse_cli_args,
133+
patch("vectorcode.lsp_main.get_client", new_callable=AsyncMock),
134+
patch("vectorcode.lsp_main.get_collection", new_callable=AsyncMock),
135+
patch(
136+
"vectorcode.lsp_main.build_query_results", new_callable=AsyncMock
137+
) as mock_get_query_result_files,
138+
patch("os.path.isfile", return_value=True),
139+
patch("vectorcode.lsp_main.try_server", return_value=True),
140+
patch("builtins.open", MagicMock()) as mock_open,
141+
patch("vectorcode.lsp_main.cached_project_configs", {}),
142+
):
143+
from vectorcode.lsp_main import cached_project_configs
144+
145+
global DEFAULT_PROJECT_ROOT
146+
147+
mock_config.project_root = None
148+
cached_project_configs.clear()
149+
mock_parse_cli_args.return_value = mock_config
150+
mock_get_query_result_files.return_value = ["/test/file.txt"]
151+
152+
# Configure the MagicMock object to return a string when read() is called
153+
mock_file = MagicMock()
154+
mock_file.__enter__.return_value.read.return_value = "{}" # Return valid JSON
155+
mock_open.return_value = mock_file
156+
157+
# Ensure parsed_args.project_root is not None
158+
DEFAULT_PROJECT_ROOT = "/test/project"
159+
160+
# Add a mock config to cached_project_configs
161+
cached_project_configs["/test/project"] = mock_config
162+
163+
# Mock the merge_from method
164+
mock_config.merge_from = AsyncMock(return_value=mock_config)
165+
166+
result = await execute_command(mock_language_server, ["query", "test"])
167+
168+
assert isinstance(result, list)
169+
mock_language_server.progress.begin.assert_called()
170+
mock_language_server.progress.end.assert_called()
171+
172+
125173
@pytest.mark.asyncio
126174
async def test_execute_command_ls(mock_language_server, mock_config):
127175
mock_config.action = CliAction.ls

0 commit comments

Comments
 (0)