File: test_exit.py

package info (click to toggle)
lsprotocol 2025.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,408 kB
  • sloc: python: 7,567; cs: 1,225; sh: 15; makefile: 4
file content (41 lines) | stat: -rw-r--r-- 1,061 bytes parent folder | download | duplicates (3)
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
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import json

import hamcrest
import jsonrpc
import pytest
from cattrs.errors import ClassValidationError


@pytest.mark.parametrize(
    "data, expected",
    [
        (
            {"method": "exit", "jsonrpc": "2.0"},
            json.dumps({"method": "exit", "jsonrpc": "2.0"}),
        ),
        (
            {"method": "exit", "params": None, "jsonrpc": "2.0"},
            json.dumps({"method": "exit", "jsonrpc": "2.0"}),
        ),
    ],
)
def test_exit_serialization(data, expected):
    data_str = json.dumps(data)
    parsed = jsonrpc.from_json(data_str)
    actual_str = jsonrpc.to_json(parsed)
    hamcrest.assert_that(actual_str, hamcrest.is_(expected))


@pytest.mark.parametrize(
    "data",
    [
        json.dumps({}),  # missing method and jsonrpc
        json.dumps({"method": "invalid"}),  # invalid method type
    ],
)
def test_exit_invalid(data):
    with pytest.raises((ClassValidationError, KeyError)):
        jsonrpc.from_json(data)