-
Notifications
You must be signed in to change notification settings - Fork 380
Expand file tree
/
Copy pathtest_reference_external_model.py
More file actions
38 lines (31 loc) · 1.44 KB
/
test_reference_external_model.py
File metadata and controls
38 lines (31 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from lsprotocol.types import Position
from sqlmesh.core.context import Context
from sqlmesh.core.linter.helpers import read_range_from_file
from sqlmesh.lsp.context import LSPContext, ModelTarget
from sqlmesh.lsp.helpers import to_sqlmesh_range
from sqlmesh.lsp.reference import get_references, LSPExternalModelReference
from sqlmesh.lsp.uri import URI
def test_reference() -> None:
context = Context(paths=["examples/sushi"])
lsp_context = LSPContext(context)
# Find model URIs
customers = next(
path
for path, info in lsp_context.map.items()
if isinstance(info, ModelTarget) and "sushi.customers" in info.names
)
# Position of reference in file sushi.customers for sushi.raw_demographics
position = Position(line=42, character=20)
references = get_references(lsp_context, URI.from_path(customers), position)
assert len(references) == 1
reference = references[0]
assert isinstance(reference, LSPExternalModelReference)
assert reference.uri.endswith("external_models.yaml")
source_range = read_range_from_file(customers, to_sqlmesh_range(reference.range))
assert source_range == "raw.demographics"
if reference.target_range is None:
raise AssertionError("Reference target range should not be None")
target_range = read_range_from_file(
URI(reference.uri).to_path(), to_sqlmesh_range(reference.target_range)
)
assert target_range == "raw.demographics"