|
2 | 2 |
|
3 | 3 | from sqlmesh.core.context import Context |
4 | 4 | from sqlmesh.lsp.context import LSPContext, ModelTarget |
| 5 | +from sqlmesh.lsp.main import ContextLoaded, NoContext, SQLMeshLanguageServer |
5 | 6 | from sqlmesh.lsp.uri import URI |
6 | 7 |
|
7 | 8 |
|
@@ -61,3 +62,32 @@ def test_lsp_context_run_test(): |
61 | 62 | # Check that the result is not None and has the expected properties |
62 | 63 | assert result is not None |
63 | 64 | assert result.success is True |
| 65 | + |
| 66 | + |
| 67 | +def test_context_get_or_load_from_no_context_with_specified_paths(): |
| 68 | + server = SQLMeshLanguageServer(context_class=Context) |
| 69 | + server.server.show_message = lambda *args, **kwargs: None |
| 70 | + server.specified_paths = [Path("examples/sushi")] |
| 71 | + |
| 72 | + assert isinstance(server.context_state, NoContext) |
| 73 | + |
| 74 | + lsp_context = server._context_get_or_load() |
| 75 | + |
| 76 | + assert isinstance(lsp_context, LSPContext) |
| 77 | + assert isinstance(server.context_state, ContextLoaded) |
| 78 | + assert server.context_state.lsp_context is lsp_context |
| 79 | + |
| 80 | + |
| 81 | +def test_context_get_or_load_from_no_context_via_workspace_folder(): |
| 82 | + server = SQLMeshLanguageServer(context_class=Context) |
| 83 | + server.server.show_message = lambda *args, **kwargs: None |
| 84 | + server.specified_paths = None |
| 85 | + server.workspace_folders = [Path.cwd() / "examples" / "sushi"] |
| 86 | + |
| 87 | + assert isinstance(server.context_state, NoContext) |
| 88 | + |
| 89 | + lsp_context = server._context_get_or_load() |
| 90 | + |
| 91 | + assert isinstance(lsp_context, LSPContext) |
| 92 | + assert isinstance(server.context_state, ContextLoaded) |
| 93 | + assert server.context_state.lsp_context is lsp_context |
0 commit comments