File: profile_buffers.py

package info (click to toggle)
harlequin 2.5.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,856 kB
  • sloc: python: 12,064; makefile: 44; sql: 6
file content (43 lines) | stat: -rw-r--r-- 1,218 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import asyncio
from unittest.mock import patch

from textual.widgets.text_area import Selection

from harlequin import Harlequin
from harlequin.editor_cache import BufferState, Cache
from harlequin_duckdb import DuckDbAdapter


async def wait_for_filtered_workers(app: Harlequin) -> None:
    filtered_workers = [
        w for w in app.workers if w.name != "_database_tree_background_loader"
    ]
    if filtered_workers:
        await app.workers.wait_for_complete(filtered_workers)


async def load_lots_of_buffers() -> None:
    with patch("harlequin.components.code_editor.load_cache") as mock_load_cache:
        buff = BufferState(
            selection=Selection((0, 0), (0, 0)),
            text="select 1; " * 20,
        )
        cache = Cache(focus_index=0, buffers=[buff] * 10)
        mock_load_cache.return_value = cache

        adapter = DuckDbAdapter((":memory:",), no_init=True)
        app = Harlequin(adapter=adapter)

        async with app.run_test() as pilot:
            await wait_for_filtered_workers(app)
            await pilot.pause()
        app.exit()


def main() -> None:
    asyncio.run(load_lots_of_buffers())
    print("Ran successfully")


if __name__ == "__main__":
    main()