Skip to content

Commit

Permalink
feat: Add tests for type info
Browse files Browse the repository at this point in the history
  • Loading branch information
last-partizan committed May 18, 2022
1 parent 1d4352f commit 0b584be
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 8 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ jobs:
steps:
- uses: actions/checkout@v2

# Install pyright
- uses: actions/setup-node@v2
with:
node-version: '16'

- name: Install pyright
run: npm install -g pyright@1.1.223

# Conda install
- name: Install conda v3.7
uses: conda-incubator/setup-miniconda@v2
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ setup_requires =
pytest-runner
install_requires =
makefun>=1.5.0
typing_extensions;python_version>='3.6'
# note: do not use double quotes in these, this triggers a weird bug in PyCharm in debug mode only
funcsigs;python_version<'3.3'
enum34;python_version<'3.4'
tests_require =
pytest
pytest_cases
syrupy;python_version>'3.6'
# for some reason these pytest dependencies were not declared in old versions of pytest
six;python_version<'3.6'
attr;python_version<'3.6'
Expand Down
7 changes: 2 additions & 5 deletions src/decopatch/main.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
from typing import Any, Callable, Optional, Protocol, TypeVar, overload

from typing_extensions import ParamSpec

from decopatch.utils_disambiguation import FirstArgDisambiguation
from decopatch.utils_modes import SignatureInfo

try:
from typing import ParamSpec
except ImportError:
from typing_extensions import ParamSpec

P = ParamSpec("P")
F = TypeVar("F", bound=Callable[..., Any])

Expand Down
Empty file added tests/pyright/__init__.py
Empty file.
40 changes: 40 additions & 0 deletions tests/pyright/__snapshots__/test_typing.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# name: test_typing
<class 'list'> [
<class 'dict'> {
'message': '
No overloads for "function_decorator" match the provided arguments
  Argument types: (Literal[True])
',
'range': <class 'dict'> {
'end': <class 'dict'> {
'character': 47,
'line': 10,
},
'start': <class 'dict'> {
'character': 9,
'line': 10,
},
},
'rule': 'reportGeneralTypeIssues',
'severity': 'error',
},
<class 'dict'> {
'message': '
Argument of type "Literal[2]" cannot be assigned to parameter "scope" of type "str" in function "__call__"
  "Literal[2]" is incompatible with "str"
',
'range': <class 'dict'> {
'end': <class 'dict'> {
'character': 26,
'line': 30,
},
'start': <class 'dict'> {
'character': 25,
'line': 30,
},
},
'rule': 'reportGeneralTypeIssues',
'severity': 'error',
},
]
---
18 changes: 18 additions & 0 deletions tests/pyright/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import json
import subprocess


def run_pyright(filename):
result = subprocess.run(
["pyright", "--outputjson", filename],
capture_output=True,
text=True,
)
assert result.stdout, result.stderr
output = json.loads(result.stdout)

def clean_row(data):
del data["file"]
return data

return [clean_row(row) for row in output["generalDiagnostics"]]
3 changes: 0 additions & 3 deletions tests/test_typing.py → tests/pyright/test_file.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# This is test file for typing,
# No automatic testing is used at the moment. Just use your type checker and see if it works.
# Pytest here is used to make sure that runtime behavir matches with type checker expecter errors.
from typing import Any, Callable

import pytest
Expand Down
12 changes: 12 additions & 0 deletions tests/pyright/test_typing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pytest
import sys
from .base import run_pyright


@pytest.mark.skipif(
sys.version_info < (3, 7),
reason="Requires Python 3.7+",
)
def test_typing(snapshot):
actual = run_pyright("tests/pyright/test_file.py")
assert actual == snapshot

0 comments on commit 0b584be

Please sign in to comment.