File: test_pyright.py

package info (click to toggle)
python-msgspec 0.19.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,356 kB
  • sloc: javascript: 23,944; ansic: 20,540; python: 20,465; makefile: 29; sh: 19
file content (35 lines) | stat: -rw-r--r-- 985 bytes parent folder | download
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
import os
import re
import subprocess

import pytest

pytestmark = pytest.mark.pyright

pyright = pytest.importorskip("pyright")

PATH = os.path.join(os.path.dirname(__file__), "basic_typing_examples.py")


def test_pyright():
    with open(PATH, "r") as fil:
        ex_lines = fil.readlines()

    result = pyright.run(PATH, stdout=subprocess.PIPE)
    if result.returncode != 0:
        assert False, f"Unexpected pyright error:\n{result.stdout}"
    for line in result.stdout.decode().splitlines():
        try:
            _, lineno, _, msg = line.split(":", 3)
        except ValueError:
            continue
        lineno = int(lineno)
        pat = re.search("[\"'](.*)[\"']", msg)
        typ = pat.groups()[0]
        check = ex_lines[lineno - 1].split("#")[1].strip()
        try:
            exec(check, {"typ": typ})
        except Exception:
            assert (
                False
            ), f"Failed check at {PATH}:{lineno}: {check!r}, where 'typ' is {typ!r}"