Debian Codegraph @

scripts/profile_fast_query.py

raw
1 import asyncio
2 from unittest.mock import patch
3
4 from textual.widgets.text_area import Selection
5
6 from harlequin import Harlequin
7 from harlequin.editor_cache import BufferState, Cache
8 from harlequin_duckdb import DuckDbAdapter
9
10
11 async def load_lots_of_buffers() -> None:
12 with (
13 patch("harlequin.components.code_editor.load_cache") as mock_load_cache,
14 patch(
15 "harlequin.components.code_editor.adopt_recovery",
16 return_value=(None, None),
17 ),
18 ):
19 buff = BufferState(
20 selection=Selection((0, 0), (0, 0)),
21 text="select 1000; ",
22 )
23 cache = Cache(focus_index=0, buffers=[buff])
24 mock_load_cache.return_value = cache
25
26 adapter = DuckDbAdapter((":memory:",), no_init=True)
27 app = Harlequin(adapter=adapter)
28
29 async with app.run_test() as pilot:
30 while app.editor is None:
31 await pilot.pause()
32 await pilot.press("ctrl+j")
33 while (table := app.results_viewer.get_visible_table()) is None:
34 await pilot.pause()
35 assert table.row_count == 1
36
37 app.exit()
38
39
40 def main() -> None:
41 asyncio.run(load_lots_of_buffers())
42 print("Ran successfully")
43
44
45 if __name__ == "__main__":
46 main()