Skip to content

Commit

Permalink
Add broad spectrum tests for python
Browse files Browse the repository at this point in the history
  • Loading branch information
karthiknadig committed Sep 15, 2023
1 parent d9cd5f2 commit be8055f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ jobs:
run: python -m pip install -U pip wheel nox
shell: bash

- name: Generate Test Data
run: python -m generator --plugin testdata

- name: Run tests
run: python -m nox --session tests
shell: bash
Expand Down
34 changes: 34 additions & 0 deletions tests/python/test_generated_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import json
import pathlib
from typing import Generator, List, Union

import pytest

import lsprotocol.converters as cv
import lsprotocol.types as lsp

TEST_DATA_ROOT = pathlib.Path(__file__).parent.parent.parent / "packages" / "testdata"


def get_all_json_files(root: Union[pathlib.Path, str]) -> List[pathlib.Path]:
root_path = pathlib.Path(root)
return list(root_path.glob("**/*.json"))


converter = cv.get_converter()


@pytest.mark.parametrize("json_file", get_all_json_files(TEST_DATA_ROOT))
def test_generated_data(json_file: str) -> None:
type_name, result_type, _ = json_file.name.split("-", 2)
lsp_type = getattr(lsp, type_name)
data = json.loads(json_file.read_text(encoding="utf-8"))

try:
converter.structure(data, lsp_type)
assert result_type == "True", "Expected error, but succeeded structuring"
except Exception as e:
assert result_type == "False", "Expected success, but failed structuring"

0 comments on commit be8055f

Please sign in to comment.