Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1b92e66

Browse files
Added optional tests for type stub adherence
Adds mypy dependency to github tests
1 parent 3b0b1ef commit 1b92e66

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

‎.github/workflows/pr-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ jobs:
3636
run: |
3737
python3 -m venv .env # maturin requires a virtualenv
3838
source .env/bin/activate
39-
pip3 install maturin pytest
39+
pip3 install maturin pytest mypy
4040
maturin develop
4141
pytest

‎tests/test_suite.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,34 @@ def test_int64(provider):
183183
res = cur.execute("SELECT * FROM data")
184184
assert [(1,1099511627776)] == res.fetchall()
185185

186+
def test_type_adherence(capsys):
187+
try:
188+
from mypy.stubtest import test_stubs, parse_options
189+
except (ImportError, ModuleNotFoundError):
190+
# skip test if mypy not installed
191+
pytest.skip("Cant test type stubs without mypy installed")
192+
193+
# run mypy stubtest tool. Equivalent to running the following the terminal
194+
"""
195+
stubtest --concise libsql_experimental | \
196+
grep -v 'which is incompatible with stub argument type'
197+
"""
198+
test_stubs(parse_options(["--concise", "libsql_experimental"]))
199+
cap = capsys.readouterr()
200+
201+
# this is part of error reported if is default parameter is ellipsis
202+
# `arg: type = ...` which is a nicer way to hide implementation from user
203+
# than having the more "correct" `arg: type | None = None` everywhere
204+
ellipsis_err = "which is incompatible with stub argument type"
205+
206+
lines = cap.out.split("\n")
207+
lines = filter(lambda x: ellipsis_err not in x, lines) # filter false positives from ellipsis
208+
lines = filter(lambda x: len(x) != 0, lines) # filter empty lines
209+
210+
# there will always be one error which i dont know how to get rid of
211+
# `libsql_experimental.libsql_experimental failed to find stubs`
212+
assert len(list(lines)) == 1
213+
186214
def connect(provider, database, isolation_level='DEFERRED'):
187215
if provider == "libsql-remote":
188216
from urllib import request

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /