Skip to content

Commit be8055f

Browse files
committed
Add broad spectrum tests for python
1 parent d9cd5f2 commit be8055f

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

.github/workflows/pr-check.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ jobs:
111111
run: python -m pip install -U pip wheel nox
112112
shell: bash
113113

114+
- name: Generate Test Data
115+
run: python -m generator --plugin testdata
116+
114117
- name: Run tests
115118
run: python -m nox --session tests
116119
shell: bash
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
import json
5+
import pathlib
6+
from typing import Generator, List, Union
7+
8+
import pytest
9+
10+
import lsprotocol.converters as cv
11+
import lsprotocol.types as lsp
12+
13+
TEST_DATA_ROOT = pathlib.Path(__file__).parent.parent.parent / "packages" / "testdata"
14+
15+
16+
def get_all_json_files(root: Union[pathlib.Path, str]) -> List[pathlib.Path]:
17+
root_path = pathlib.Path(root)
18+
return list(root_path.glob("**/*.json"))
19+
20+
21+
converter = cv.get_converter()
22+
23+
24+
@pytest.mark.parametrize("json_file", get_all_json_files(TEST_DATA_ROOT))
25+
def test_generated_data(json_file: str) -> None:
26+
type_name, result_type, _ = json_file.name.split("-", 2)
27+
lsp_type = getattr(lsp, type_name)
28+
data = json.loads(json_file.read_text(encoding="utf-8"))
29+
30+
try:
31+
converter.structure(data, lsp_type)
32+
assert result_type == "True", "Expected error, but succeeded structuring"
33+
except Exception as e:
34+
assert result_type == "False", "Expected success, but failed structuring"

0 commit comments

Comments
 (0)