1+ import sqlalchemy
2+ import psycopg2
3+
4+ from sqlalchemy .engine import Engine
5+ from sqlalchemy import create_engine
6+ from sqlalchemy import text
7+
8+ import sys
9+
10+ QUERY_RESPONSE = [
11+ {"create table test (pk int, \" value\" int, primary key(pk))" : []},
12+ {"describe test" : [
13+ ('pk' , 'integer' , 'NO' , 'PRI' , None , '' ),
14+ ('value' , 'integer' , 'YES' , '' , None , '' )
15+ ]},
16+ {"insert into test (pk, value) values (0,0)" : ()},
17+ {"select * from test" : [(0 , 0 )]},
18+ {"select dolt_add('-A');" : [(['0' ],)]},
19+ {"select dolt_commit('-m', 'my commit')" : [('' ,)]},
20+ {"select COUNT(*) FROM dolt_log" : [(3 ,)]},
21+ {"select dolt_checkout('-b', 'mybranch')" : [(['0' , "Switched to branch 'mybranch'" ],)]},
22+ {"insert into test (pk, value) values (1,1)" : []},
23+ {"select dolt_commit('-a', '-m', 'my commit2')" : [('' ,)]},
24+ {"select dolt_checkout('main')" : [(['0' , "Switched to branch 'main'" ],)]},
25+ {"select dolt_merge('mybranch')" : [('' ,1 ,0 ,)]},
26+ {"select COUNT(*) FROM dolt_log" : [(4 ,)]},
27+ ]
28+
29+
30+ def main ():
31+ user = sys .argv [1 ]
32+ port = int (sys .argv [2 ])
33+
34+ conn_string_base = "postgresql+psycopg2://"
35+
36+ engine = create_engine (conn_string_base +
37+ "{user}:password@127.0.0.1:{port}/postgres" .format (user = user ,
38+ port = port )
39+ )
40+
41+ with engine .connect () as con :
42+ for query_response in QUERY_RESPONSE :
43+ query = list (query_response .keys ())[0 ]
44+ exp_results = query_response [query ]
45+
46+ result_proxy = con .execute (text (query ))
47+
48+ try :
49+ results = result_proxy .fetchall ()
50+ if (results != exp_results ) and ("dolt_commit" not in query ) and ("dolt_merge" not in query ):
51+ print ("Query:" )
52+ print (query )
53+ print ("Expected:" )
54+ print (exp_results )
55+ print ("Received:" )
56+ print (results )
57+ sys .exit (1 )
58+ # You can't call fetchall on an insert
59+ # so we'll just ignore the exception
60+ except sqlalchemy .exc .ResourceClosedError :
61+ pass
62+
63+ con .close ()
64+ sys .exit (0 )
65+
66+
67+ main ()
0 commit comments