Skip to content

Commit 462d014

Browse files
committed
Fix async ruby tests
1 parent cafa1ab commit 462d014

File tree

2 files changed

+76
-124
lines changed

2 files changed

+76
-124
lines changed

tests/multilspy/test_multilspy_ruby.py

Lines changed: 15 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,19 @@
1010
from multilspy.multilspy_types import Position, CompletionItemKind
1111
from tests.test_utils import create_test_context
1212
from pathlib import PurePath
13+
from tests.multilspy.test_sync_multilspy_ruby import EXPECTED_RESULT
1314

1415

15-
async def test_multilspy_ruby_carbonyl():
16+
@pytest.mark.asyncio
17+
async def test_multilspy_ruby_rubyland():
1618
"""
17-
Test the working of multilspy with ruby repository - rails/rails
19+
Test the working of multilspy with ruby repository - rubyland
1820
"""
1921
code_language = Language.RUBY
2022
params = {
2123
"code_language": code_language,
22-
"repo_url": "https://github.com/rails/rails/",
23-
"repo_commit": "abb7035e08c07bb4e2941c1c27003609ce81e77b"
24+
"repo_url": "https://github.com/jrochkind/rubyland/",
25+
"repo_commit": "c243ee2533a5822f5699a2475e492927ace039c7"
2426
}
2527
with create_test_context(params) as context:
2628
lsp = LanguageServer.create(context.config, context.logger, context.source_directory)
@@ -29,21 +31,21 @@ async def test_multilspy_ruby_carbonyl():
2931
# The server process is started when the context manager is entered and is terminated when the context manager is exited.
3032
# The context manager is an asynchronous context manager, so it must be used with async with.
3133
async with lsp.start_server():
32-
result = await lsp.request_definition(str(PurePath("activemodel/lib/active_model.rb")), 132, 18)
34+
result = await lsp.request_definition(str(PurePath("app/controllers/feed_controller.rb")), 11, 23)
3335

3436
assert isinstance(result, list)
35-
assert len(result) == 1
36-
item = result[0]
37-
assert item["relativePath"] == str(PurePath("actionview/lib/action_view.rb"))
37+
assert len(result) == 2
38+
item = result[1]
39+
assert item["relativePath"] == str(PurePath("app/models/feed.rb"))
3840
assert item["range"] == {
39-
"start": {"line": 43, "character": 11},
40-
"end": {"line": 43, "character": 19},
41+
"start": {"line": 0, "character": 0},
42+
"end": {"line": 42, "character": 3},
4143
}
4244

43-
result = await lsp.request_references(str(PurePath("activemodel/lib/active_model.rb")), 43, 15)
45+
result = await lsp.request_references(str(PurePath("app/models/feed.rb")), 0, 7)
4446

4547
assert isinstance(result, list)
46-
assert len(result) == 2
48+
assert len(result) == 8
4749

4850
for item in result:
4951
del item["uri"]
@@ -52,58 +54,5 @@ async def test_multilspy_ruby_carbonyl():
5254
case = unittest.TestCase()
5355
case.assertCountEqual(
5456
result,
55-
[
56-
{
57-
"relativePath": str(PurePath("activemodel/lib/active_model.rb")),
58-
"range": {
59-
"start": {"line": 132, "character": 13},
60-
"end": {"line": 132, "character": 21},
61-
},
62-
},
63-
{
64-
"relativePath": str(PurePath("actionview/lib/action_view.rb")),
65-
"range": {
66-
"start": {"line": 16, "character": 13},
67-
"end": {"line": 16, "character": 21},
68-
},
69-
},
70-
],
57+
EXPECTED_RESULT,
7158
)
72-
73-
# @pytest.mark.asyncio
74-
# async def test_multilspy_rust_completions_mediaplayer() -> None:
75-
# """
76-
# Test the working of multilspy with Rust repository - mediaplayer
77-
# """
78-
# code_language = Language.RUST
79-
# params = {
80-
# "code_language": code_language,
81-
# "repo_url": "https://github.com/LakshyAAAgrawal/MediaPlayer_example/",
82-
# "repo_commit": "ba27bb16c7ba1d88808300364af65eb69b1d84a8",
83-
# }
84-
85-
# with create_test_context(params) as context:
86-
# lsp = LanguageServer.create(context.config, context.logger, context.source_directory)
87-
# filepath = "src/playlist.rs"
88-
# # All the communication with the language server must be performed inside the context manager
89-
# # The server process is started when the context manager is entered and is terminated when the context manager is exited.
90-
# async with lsp.start_server():
91-
# with lsp.open_file(filepath):
92-
# deleted_text = lsp.delete_text_between_positions(
93-
# filepath, Position(line=10, character=40), Position(line=12, character=4)
94-
# )
95-
# assert (
96-
# deleted_text
97-
# == """reset();
98-
# media_player1 = media_player;
99-
# """
100-
# )
101-
102-
# response = await lsp.request_completions(filepath, 10, 40, allow_incomplete=True)
103-
104-
# response = [item for item in response if item['kind'] != CompletionItemKind.Snippet]
105-
106-
# for item in response:
107-
# item['completionText'] = item['completionText'][:item['completionText'].find('(')]
108-
109-
# assert set([item['completionText'] for item in response]) == {'reset', 'into', 'try_into', 'prepare'}

tests/multilspy/test_sync_multilspy_ruby.py

Lines changed: 61 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,66 @@
99
from tests.test_utils import create_test_context
1010
from pathlib import PurePath
1111

12+
EXPECTED_RESULT = [
13+
{
14+
"range": {
15+
"start": {"line": 11, "character": 20},
16+
"end": {"line": 11, "character": 24},
17+
},
18+
"relativePath": "app/controllers/feed_controller.rb",
19+
},
20+
{
21+
"range": {
22+
"start": {"line": 27, "character": 46},
23+
"end": {"line": 27, "character": 50},
24+
},
25+
"relativePath": "app/controllers/feed_controller.rb",
26+
},
27+
{
28+
"range": {
29+
"start": {"line": 0, "character": 6},
30+
"end": {"line": 0, "character": 10},
31+
},
32+
"relativePath": "app/models/feed.rb",
33+
},
34+
{
35+
"range": {
36+
"start": {"line": 13, "character": 74},
37+
"end": {"line": 13, "character": 78},
38+
},
39+
"relativePath": "app/updaters/feed_updater.rb",
40+
},
41+
{
42+
"range": {
43+
"start": {"line": 52, "character": 4},
44+
"end": {"line": 52, "character": 8},
45+
},
46+
"relativePath": "app/updaters/feed_updater.rb",
47+
},
48+
{
49+
"range": {
50+
"start": {"line": 10, "character": 20},
51+
"end": {"line": 10, "character": 24},
52+
},
53+
"relativePath": "app/updaters/updater.rb",
54+
},
55+
{
56+
"range": {
57+
"start": {"line": 14, "character": 20},
58+
"end": {"line": 14, "character": 24},
59+
},
60+
"relativePath": "app/updaters/updater.rb",
61+
},
62+
{
63+
"range": {
64+
"start": {"line": 0, "character": 6},
65+
"end": {"line": 0, "character": 10},
66+
},
67+
"relativePath": "db/migrate/20161029161855_feed.rb",
68+
},
69+
]
70+
71+
1272
def test_multilspy_ruby_rubyland() -> None:
1373
"""
1474
Test the working of multilspy with ruby repository - rubyland
@@ -47,62 +107,5 @@ def test_multilspy_ruby_rubyland() -> None:
47107
case = unittest.TestCase()
48108
case.assertCountEqual(
49109
result,
50-
[
51-
{
52-
"range": {
53-
"start": {"line": 11, "character": 20},
54-
"end": {"line": 11, "character": 24},
55-
},
56-
"relativePath": "app/controllers/feed_controller.rb",
57-
},
58-
{
59-
"range": {
60-
"start": {"line": 27, "character": 46},
61-
"end": {"line": 27, "character": 50},
62-
},
63-
"relativePath": "app/controllers/feed_controller.rb",
64-
},
65-
{
66-
"range": {
67-
"start": {"line": 0, "character": 6},
68-
"end": {"line": 0, "character": 10},
69-
},
70-
"relativePath": "app/models/feed.rb",
71-
},
72-
{
73-
"range": {
74-
"start": {"line": 13, "character": 74},
75-
"end": {"line": 13, "character": 78},
76-
},
77-
"relativePath": "app/updaters/feed_updater.rb",
78-
},
79-
{
80-
"range": {
81-
"start": {"line": 52, "character": 4},
82-
"end": {"line": 52, "character": 8},
83-
},
84-
"relativePath": "app/updaters/feed_updater.rb",
85-
},
86-
{
87-
"range": {
88-
"start": {"line": 10, "character": 20},
89-
"end": {"line": 10, "character": 24},
90-
},
91-
"relativePath": "app/updaters/updater.rb",
92-
},
93-
{
94-
"range": {
95-
"start": {"line": 14, "character": 20},
96-
"end": {"line": 14, "character": 24},
97-
},
98-
"relativePath": "app/updaters/updater.rb",
99-
},
100-
{
101-
"range": {
102-
"start": {"line": 0, "character": 6},
103-
"end": {"line": 0, "character": 10},
104-
},
105-
"relativePath": "db/migrate/20161029161855_feed.rb",
106-
},
107-
]
110+
EXPECTED_RESULT,
108111
)

0 commit comments

Comments
 (0)