33from sqlmesh .core .context import Context
44from sqlmesh .lsp .context import LSPContext , ModelTarget , AuditTarget
55from sqlmesh .lsp .reference import get_model_definitions_for_a_path , by_position
6+ from sqlmesh .lsp .uri import URI
67
78
89@pytest .mark .fast
@@ -11,21 +12,22 @@ def test_reference() -> None:
1112 lsp_context = LSPContext (context )
1213
1314 # Find model URIs
14- active_customers_uri = next (
15- uri
16- for uri , info in lsp_context .map .items ()
15+ active_customers_path = next (
16+ path
17+ for path , info in lsp_context .map .items ()
1718 if isinstance (info , ModelTarget ) and "sushi.active_customers" in info .names
1819 )
19- sushi_customers_uri = next (
20- uri
21- for uri , info in lsp_context .map .items ()
20+ sushi_customers_path = next (
21+ path
22+ for path , info in lsp_context .map .items ()
2223 if isinstance (info , ModelTarget ) and "sushi.customers" in info .names
2324 )
2425
26+ active_customers_uri = URI .from_path (active_customers_path )
2527 references = get_model_definitions_for_a_path (lsp_context , active_customers_uri )
2628
2729 assert len (references ) == 1
28- assert references [0 ].uri == sushi_customers_uri . value
30+ assert URI ( references [0 ].uri ) == URI . from_path ( sushi_customers_path )
2931
3032 # Check that the reference in the correct range is sushi.customers
3133 path = active_customers_uri .to_path ()
@@ -42,17 +44,18 @@ def test_reference_with_alias() -> None:
4244 context = Context (paths = ["examples/sushi" ])
4345 lsp_context = LSPContext (context )
4446
45- waiter_revenue_by_day_uri = next (
47+ waiter_revenue_by_day_path = next (
4648 uri
4749 for uri , info in lsp_context .map .items ()
4850 if isinstance (info , ModelTarget ) and "sushi.waiter_revenue_by_day" in info .names
4951 )
5052
51- references = get_model_definitions_for_a_path (lsp_context , waiter_revenue_by_day_uri )
53+ references = get_model_definitions_for_a_path (
54+ lsp_context , URI .from_path (waiter_revenue_by_day_path )
55+ )
5256 assert len (references ) == 3
5357
54- path = waiter_revenue_by_day_uri .to_path ()
55- with open (path , "r" ) as file :
58+ with open (waiter_revenue_by_day_path , "r" ) as file :
5659 read_file = file .readlines ()
5760
5861 assert references [0 ].uri .endswith ("orders.py" )
@@ -70,27 +73,25 @@ def test_standalone_audit_reference() -> None:
7073 lsp_context = LSPContext (context )
7174
7275 # Find the standalone audit URI
73- audit_uri = next (
76+ audit_path = next (
7477 uri
7578 for uri , info in lsp_context .map .items ()
7679 if isinstance (info , AuditTarget ) and info .name == "assert_item_price_above_zero"
7780 )
78-
7981 # Find the items model URI
80- items_uri = next (
82+ items_path = next (
8183 uri
8284 for uri , info in lsp_context .map .items ()
8385 if isinstance (info , ModelTarget ) and "sushi.items" in info .names
8486 )
8587
86- references = get_model_definitions_for_a_path (lsp_context , audit_uri )
88+ references = get_model_definitions_for_a_path (lsp_context , URI . from_path ( audit_path ) )
8789
8890 assert len (references ) == 1
89- assert references [0 ].uri == items_uri .value
91+ assert references [0 ].uri == URI . from_path ( items_path ) .value
9092
9193 # Check that the reference in the correct range is sushi.items
92- path = audit_uri .to_path ()
93- with open (path , "r" ) as file :
94+ with open (audit_path , "r" ) as file :
9495 read_file = file .readlines ()
9596 referenced_text = get_string_from_range (read_file , references [0 ].range )
9697 assert referenced_text == "sushi.items"
@@ -123,19 +124,20 @@ def test_filter_references_by_position() -> None:
123124 lsp_context = LSPContext (context )
124125
125126 # Use a file with multiple references (waiter_revenue_by_day)
126- waiter_revenue_by_day_uri = next (
127- uri
128- for uri , info in lsp_context .map .items ()
127+ waiter_revenue_by_day_path = next (
128+ path
129+ for path , info in lsp_context .map .items ()
129130 if isinstance (info , ModelTarget ) and "sushi.waiter_revenue_by_day" in info .names
130131 )
131132
132133 # Get all references in the file
133- all_references = get_model_definitions_for_a_path (lsp_context , waiter_revenue_by_day_uri )
134+ all_references = get_model_definitions_for_a_path (
135+ lsp_context , URI .from_path (waiter_revenue_by_day_path )
136+ )
134137 assert len (all_references ) == 3
135138
136139 # Get file contents to locate positions for testing
137- path = waiter_revenue_by_day_uri .to_path ()
138- with open (path , "r" ) as file :
140+ with open (waiter_revenue_by_day_path , "r" ) as file :
139141 read_file = file .readlines ()
140142
141143 # Test positions for each reference
0 commit comments