Skip to content

Commit

Permalink
Protect pyright against 3.7 & prepare for #999
Browse files Browse the repository at this point in the history
Co-authored-by: layday <layday@protonmail.com>
  • Loading branch information
hynek and layday committed Aug 18, 2022
1 parent cb047e1 commit 49ec731
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions tests/test_pyright.py
Expand Up @@ -4,39 +4,52 @@
import os.path
import shutil
import subprocess
import sys

import pytest

import attr
import attrs


_found_pyright = shutil.which("pyright")
pytestmark = [
pytest.mark.skipif(
sys.version_info < (3, 7), reason="Requires Python 3.7+."
),
pytest.mark.skipif(
shutil.which("pyright") is None, reason="Requires pyright."
),
]


@attr.s(frozen=True)
@attrs.frozen
class PyrightDiagnostic:
severity = attr.ib()
message = attr.ib()
severity: str
message: str


@pytest.mark.skipif(not _found_pyright, reason="Requires pyright.")
def test_pyright_baseline():
"""The __dataclass_transform__ decorator allows pyright to determine
attrs decorated class types.
"""

test_file = os.path.dirname(__file__) + "/dataclass_transform_example.py"

def parse_pyright_output(test_file):
pyright = subprocess.run(
["pyright", "--outputjson", str(test_file)], capture_output=True
)

pyright_result = json.loads(pyright.stdout)

diagnostics = {
return {
PyrightDiagnostic(d["severity"], d["message"])
for d in pyright_result["generalDiagnostics"]
}


def test_pyright_baseline():
"""
The __dataclass_transform__ decorator allows pyright to determine attrs
decorated class types.
"""

test_file = os.path.dirname(__file__) + "/dataclass_transform_example.py"

diagnostics = parse_pyright_output(test_file)

# Expected diagnostics as per pyright 1.1.135
expected_diagnostics = {
PyrightDiagnostic(
Expand Down

0 comments on commit 49ec731

Please sign in to comment.