@@ -183,6 +183,34 @@ def test_int64(provider):
183
183
res = cur .execute ("SELECT * FROM data" )
184
184
assert [(1 ,1099511627776 )] == res .fetchall ()
185
185
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
+
186
214
def connect (provider , database , isolation_level = 'DEFERRED' ):
187
215
if provider == "libsql-remote" :
188
216
from urllib import request
0 commit comments