File: test_typing.py

package info (click to toggle)
python-inline-snapshot 0.23.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,116 kB
  • sloc: python: 6,888; makefile: 34; sh: 28
file content (56 lines) | stat: -rw-r--r-- 883 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import sys

import pytest


@pytest.fixture(params=["mypy", "pyright"])
def check_typing(pytester, request):
    prog = request.param

    def f(code):
        pytester.makefile(".py", test_something=code)
        pytester.makefile(
            ".toml",
            pyproject="""

[tool.pyright]
typeCheckingMode = 'strict'

[tool.mypy]
strict=true

        """,
        )

        result = pytester.run(sys.executable, "-m", prog, "test_something.py")

        print(result.stdout)
        assert result.ret == 0

    yield f


def test_typing_args(check_typing):
    check_typing(
        """
from inline_snapshot import snapshot
snapshot([])
snapshot({})
    """
    )


def test_typing_call(check_typing):
    check_typing(
        """
from inline_snapshot import snapshot,Snapshot

def f(s:Snapshot[int])->None:
    assert s==5

f(5)
f(snapshot())
f(snapshot(5))

    """
    )