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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import hamcrest
import pytest
from cattrs import ClassValidationError
from lsprotocol import converters as cv
from lsprotocol import types as lsp
TEST_DATA = [
{
"id": 1,
"result": [{"name": "test", "kind": 1, "location": {"uri": "test"}}],
"jsonrpc": "2.0",
},
{
"id": 1,
"result": [
{
"name": "test",
"kind": 1,
"location": {
"uri": "test",
"range": {
"start": {"line": 1, "character": 1},
"end": {"line": 1, "character": 1},
},
},
}
],
"jsonrpc": "2.0",
},
{
"id": 1,
"result": [{"name": "test", "kind": 1, "location": {"uri": "test"}, "data": 1}],
"jsonrpc": "2.0",
},
{
"id": 1,
"result": [
{
"name": "test",
"kind": 1,
"location": {
"uri": "test",
"range": {
"start": {"line": 1, "character": 1},
"end": {"line": 1, "character": 1},
},
},
"deprecated": True,
}
],
"jsonrpc": "2.0",
},
]
BAD_TEST_DATA = [
{
"id": 1,
"result": [
{
"name": "test",
"kind": 1,
"location": {"uri": "test"},
"deprecated": True,
}
],
"jsonrpc": "2.0",
},
]
@pytest.mark.parametrize("data", TEST_DATA)
def test_workspace_symbols(data):
converter = cv.get_converter()
obj = converter.structure(data, lsp.WorkspaceSymbolResponse)
hamcrest.assert_that(obj, hamcrest.instance_of(lsp.WorkspaceSymbolResponse))
hamcrest.assert_that(
converter.unstructure(obj, lsp.WorkspaceSymbolResponse),
hamcrest.is_(data),
)
@pytest.mark.parametrize("data", BAD_TEST_DATA)
def test_workspace_symbols_bad(data):
converter = cv.get_converter()
with pytest.raises(ClassValidationError):
obj = converter.structure(data, lsp.WorkspaceSymbolResponse)
hamcrest.assert_that(obj, hamcrest.instance_of(lsp.WorkspaceSymbolResponse))
|