1
+ import sys
2
+ from subprocess import PIPE , Popen
3
+ from traceback import print_exc
4
+
5
+ import duckdb
1
6
import pandas as pd
7
+ from pytest import importorskip , mark , raises
2
8
from sqlalchemy import text
3
- from sqlalchemy .engine import Engine
9
+ from sqlalchemy .engine import Engine , create_engine
10
+ from sqlalchemy .exc import ProgrammingError
11
+
12
+ SEGFAULT = - 6
13
+ SUCCESS = 0
4
14
5
15
6
16
def test_integration (engine : Engine ) -> None :
@@ -12,3 +22,44 @@ def test_integration(engine: Engine) -> None:
12
22
execute ("register" , params ) # type: ignore[operator]
13
23
14
24
conn .execute (text ("select * from test_df" ))
25
+
26
+
27
+ @mark .remote_data
28
+ @mark .skipif (
29
+ "dev" in duckdb .__version__ , reason = "md extension not available for dev builds" # type: ignore[attr-defined]
30
+ )
31
+ def test_motherduck () -> None :
32
+ importorskip ("duckdb" , "0.7.1" )
33
+
34
+ # we're running this test in a sub process due to occasional segfaults in the motherduck extension
35
+
36
+ proc = Popen ([sys .executable , __file__ ], stderr = PIPE , stdout = PIPE , text = True )
37
+ wait = proc .wait (5000 )
38
+ assert wait == SUCCESS or wait == SEGFAULT , (proc .stdout , proc .stderr )
39
+
40
+
41
+ def hook () -> None :
42
+ try :
43
+ _test_motherduck ()
44
+ except Exception :
45
+ print_exc ()
46
+ sys .exit (- 1 )
47
+ else :
48
+ sys .exit (0 )
49
+
50
+
51
+ def _test_motherduck () -> None :
52
+ engine = create_engine (
53
+ "duckdb:///md:motherdb" ,
54
+ connect_args = {"config" : {"motherduck_token" : "motherduckdb_token" }},
55
+ )
56
+
57
+ with raises (
58
+ ProgrammingError ,
59
+ match = "Jwt is not in the form of Header.Payload.Signature with two dots and 3 sections" ,
60
+ ):
61
+ engine .connect ()
62
+
63
+
64
+ if __name__ == "__main__" :
65
+ _test_motherduck ()
0 commit comments