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 7fa1884

Browse files
Added optional tests for type stub adherence
Adds mypy dependencny to github tests
1 parent cc6445e commit 7fa1884

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,33 @@ def test_int64(provider):
287287
res = cur.execute("SELECT * FROM data")
288288
assert [(1, 1099511627776)] == res.fetchall()
289289

290+
def test_type_adherence(capsys):
291+
try:
292+
from mypy.stubtest import test_stubs, parse_options
293+
except (ImportError, ModuleNotFoundError):
294+
# skip test if mypy not installed
295+
pytest.skip("Cant test type stubs without mypy installed")
296+
297+
# run mypy stubtest tool. Equivalent to running the following the terminal
298+
"""
299+
stubtest --concise libsql_experimental | \
300+
grep -v 'which is incompatible with stub argument type'
301+
"""
302+
test_stubs(parse_options(["--concise", "libsql_experimental"]))
303+
cap = capsys.readouterr()
304+
305+
# this is part of error reported if is default parameter is ellipsis
306+
# `arg: type = ...` which is a nicer way to hide implementation from user
307+
# than having the more "correct" `arg: type | None = None` everywhere
308+
ellipsis_err = "which is incompatible with stub argument type"
309+
310+
lines = cap.out.split("\n")
311+
lines = filter(lambda x: ellipsis_err not in x, lines) # filter false positives from ellipsis
312+
lines = filter(lambda x: len(x) != 0, lines) # filter empty lines
313+
314+
# there will always be one error which i dont know how to get rid of
315+
# `libsql_experimental.libsql_experimental failed to find stubs`
316+
assert len(list(lines)) == 1
290317

291318
def connect(provider, database, isolation_level="DEFERRED", autocommit=-1):
292319
if provider == "libsql-remote":

0 commit comments

Comments
(0)

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