Skip to content

Commit 4e58c4f

Browse files
fix: correctly mock stuff
1 parent 6d06737 commit 4e58c4f

2 files changed

Lines changed: 42 additions & 31 deletions

File tree

tests/test_transpiler.py

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import textwrap
12
import pytest
23
from pywire_language_server.transpiler import Transpiler
34

@@ -12,14 +13,14 @@ def test_transpile_simple_interpolation():
1213
# This assertion is vague, we'll refine it as we implement.
1314

1415
def test_transpile_python_section():
15-
source = """
16-
---
17-
x = 1
18-
def foo():
19-
pass
20-
---
21-
<h1>Hi</h1>
22-
"""
16+
source = textwrap.dedent("""
17+
---
18+
x = 1
19+
def foo():
20+
pass
21+
---
22+
<h1>Hi</h1>
23+
""").strip()
2324
transpiler = Transpiler(source)
2425
code, _ = transpiler.transpile()
2526

@@ -36,22 +37,24 @@ def test_transpile_directive():
3637
assert "'/home'" in code
3738

3839
def test_transpile_multiline_interpolation():
39-
source = """<div class={
40-
'active' if True
41-
else 'inactive'
42-
}></div>"""
40+
source = textwrap.dedent("""
41+
<div class={
42+
'active' if True
43+
else 'inactive'
44+
}></div>
45+
""").strip()
4346
transpiler = Transpiler(source)
4447
code, _ = transpiler.transpile()
4548

4649
assert "'active' if True" in code
4750
assert "else 'inactive'" in code
4851

4952
def test_transpile_wrappers():
50-
source = """
51-
<div $if={x > 1}></div>
52-
<div $for={i in items}></div>
53-
<div @click={do_something()}></div>
54-
"""
53+
source = textwrap.dedent("""
54+
<div $if={x > 1}></div>
55+
<div $for={i in items}></div>
56+
<div @click={do_something()}></div>
57+
""").strip()
5558
transpiler = Transpiler(source)
5659
code, _ = transpiler.transpile()
5760

@@ -63,16 +66,16 @@ def test_transpile_wrappers():
6366

6467
def test_explicit_property_mapping():
6568
"""Test that {count.value} maps 'count' correctly."""
66-
source = """
67-
---
68-
count = wire(0)
69-
---
70-
<p>{count.value}</p>
71-
"""
69+
source = textwrap.dedent("""
70+
---
71+
count = wire(0)
72+
---
73+
<p>{count.value}</p>
74+
""").strip()
7275
transpiler = Transpiler(source)
7376
code, source_map = transpiler.transpile()
7477

75-
usage_line = 4
78+
usage_line = 3
7679
usage_col_start = 4 # { is at 3, count at 4
7780

7881
gen_loc = source_map.to_generated(usage_line, usage_col_start)
@@ -87,19 +90,19 @@ def test_explicit_property_mapping():
8790

8891
def test_event_handler_mapping():
8992
"""Test @click={count.value += 1} mapping."""
90-
source = """
91-
---
92-
count = wire(0)
93-
---
94-
<button @click={count.value += 1}>Inc</button>
95-
"""
93+
source = textwrap.dedent("""
94+
---
95+
count = wire(0)
96+
---
97+
<button @click={count.value += 1}>Inc</button>
98+
""").strip()
9699
transpiler = Transpiler(source)
97100
code, source_map = transpiler.transpile()
98101

99102
# Usage: {count.value}
100103
# <button @click={count...
101104
# c is at 16.
102-
usage_line = 4
105+
usage_line = 3
103106
usage_col_start = 16
104107

105108
gen_loc = source_map.to_generated(usage_line, usage_col_start)

tests/test_ty_integration.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ async def test_completion_trigger_kind(mock_ls, mock_ty_client):
4242
server_module.virtual_manager = Mock()
4343
server_module.virtual_manager.root_path = "/workspace"
4444
server_module.virtual_manager.get_shadow_uri.return_value = "file:///shadow.py"
45+
server_module.virtual_manager.get_stub_uri.return_value = None
46+
server_module.virtual_manager._uri_to_path.return_value = "/workspace/test.wire"
4547

4648
# Mock document mapping
4749
uri = "file:///test.wire"
@@ -81,6 +83,8 @@ async def test_hover_formatting(mock_ls, mock_ty_client):
8183
server_module.virtual_manager = Mock()
8284
server_module.virtual_manager.root_path = "/workspace"
8385
server_module.virtual_manager.get_shadow_uri.return_value = "file:///shadow.py"
86+
server_module.virtual_manager.get_stub_uri.return_value = None
87+
server_module.virtual_manager._uri_to_path.return_value = "/workspace/test.wire"
8488

8589
uri = "file:///test.wire"
8690
text = """
@@ -123,6 +127,8 @@ async def test_hover_docstring_separation(mock_ls, mock_ty_client):
123127
server_module.virtual_manager = Mock()
124128
server_module.virtual_manager.root_path = "/workspace"
125129
server_module.virtual_manager.get_shadow_uri.return_value = "file:///shadow.py"
130+
server_module.virtual_manager.get_stub_uri.return_value = None
131+
server_module.virtual_manager._uri_to_path.return_value = "/workspace/test.wire"
126132

127133
# Test that we separate signature from docstring
128134
uri = "file:///test.wire"
@@ -269,6 +275,8 @@ async def test_definition_reference_fallback(mock_ls, mock_ty_client):
269275
server_module.virtual_manager = Mock()
270276
server_module.virtual_manager.root_path = "/workspace"
271277
server_module.virtual_manager.get_shadow_uri.return_value = "file:///shadow.py"
278+
server_module.virtual_manager.get_stub_uri.return_value = None
279+
server_module.virtual_manager._uri_to_path.return_value = "/workspace/test.wire"
272280

273281
uri = "file:///test.wire"
274282
text = """

0 commit comments

Comments
 (0)