Skip to content

Commit 8bb23c9

Browse files
committed
test: update smoke test to support store results
1 parent 5a4b1f8 commit 8bb23c9

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

tests/smoke.py

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
from wherobots.db.region import Region
1717
from wherobots.db.runtime import Runtime
1818
from wherobots.db.session_type import SessionType
19+
from wherobots.db.models import Store, StoreResult
20+
1921

2022
if __name__ == "__main__":
2123
parser = argparse.ArgumentParser()
@@ -24,6 +26,8 @@
2426
parser.add_argument("--region", help="Region to connect to (ie. aws-us-west-2)")
2527
parser.add_argument("--runtime", help="Runtime type (ie. tiny)")
2628
parser.add_argument("--version", help="Runtime version (ie. latest)")
29+
parser.add_argument("--force-new", action="store_true")
30+
parser.add_argument("--store", action="store_true")
2731
parser.add_argument(
2832
"--session-type",
2933
help="Type of session to create",
@@ -64,6 +68,7 @@
6468
api_key = None
6569
token = None
6670
headers = None
71+
store = None
6772

6873
if args.api_key_file:
6974
with open(args.api_key_file) as f:
@@ -75,6 +80,10 @@
7580
token = f.read().strip()
7681
headers = {"Authorization": f"Bearer {token}"}
7782

83+
if args.store:
84+
store = Store.for_download()
85+
logging.info("Will requests for results to be stored in cloud storage.")
86+
7887
if args.ws_url:
7988
conn_func = functools.partial(connect_direct, uri=args.ws_url, headers=headers)
8089
else:
@@ -88,23 +97,40 @@
8897
runtime=Runtime(args.runtime) if args.runtime else Runtime.MICRO,
8998
region=Region(args.region) if args.region else Region.AWS_US_WEST_2,
9099
version=args.version,
100+
force_new=args.force_new,
91101
session_type=SessionType(args.session_type),
92102
)
93103

94-
def render(results: pandas.DataFrame) -> None:
95-
table = Table()
104+
def render_df(df: pandas.DataFrame) -> Table:
105+
table = Table(show_header=True)
96106
table.add_column("#")
97-
for column in results.columns:
107+
for column in df.columns:
98108
table.add_column(column, max_width=args.wide, no_wrap=True)
99-
for row in results.itertuples(name=None):
109+
for row in df.itertuples(name=None):
100110
r = [str(x) for x in row]
101111
table.add_row(*r)
102-
Console().print(table)
112+
return table
113+
114+
def render_stored(sr: StoreResult) -> Table:
115+
table = Table(show_header=True)
116+
table.add_column("URI")
117+
table.add_column("Size", justify="right")
118+
table.add_row(sr.result_uri, str(sr.size))
119+
return table
120+
121+
def render(results: pandas.DataFrame | StoreResult) -> None:
122+
if isinstance(results, StoreResult):
123+
Console().print(render_stored(results))
124+
else:
125+
Console().print(render_df(results))
103126

104-
def execute(conn: Connection, sql: str) -> pandas.DataFrame:
127+
def execute(conn: Connection, sql: str) -> pandas.DataFrame | StoreResult:
105128
with conn.cursor() as cursor:
106-
cursor.execute(sql)
107-
return cursor.fetchall()
129+
cursor.execute(sql, store=store)
130+
if args.store:
131+
return cursor.get_store_result()
132+
else:
133+
return cursor.fetchall()
108134

109135
try:
110136
with conn_func() as conn:

0 commit comments

Comments
 (0)