File: test_lazy.py

package info (click to toggle)
textual 2.1.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 55,084 kB
  • sloc: python: 85,423; lisp: 1,669; makefile: 101
file content (55 lines) | stat: -rw-r--r-- 1,606 bytes parent folder | download | duplicates (2)
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
44
45
46
47
48
49
50
51
52
53
54
55
from textual.app import App, ComposeResult
from textual.containers import Horizontal, Vertical
from textual.lazy import Lazy, Reveal
from textual.widgets import Label


class LazyApp(App):
    def compose(self) -> ComposeResult:
        with Vertical():
            with Lazy(Horizontal()):
                yield Label(id="foo")
            with Horizontal():
                yield Label(id="bar")


async def test_lazy():
    app = LazyApp()
    async with app.run_test() as pilot:
        # No #foo on initial mount
        assert len(app.query("#foo")) == 0
        assert len(app.query("#bar")) == 1
        await pilot.pause()
        await pilot.pause()
        # #bar mounted after refresh
        assert len(app.query("#foo")) == 1
        assert len(app.query("#bar")) == 1


class RevealApp(App):
    def compose(self) -> ComposeResult:
        with Reveal(Vertical()):
            yield Label(id="foo")
            yield Label(id="bar")
            yield Label(id="baz")


async def test_lazy_reveal():
    app = RevealApp()
    async with app.run_test() as pilot:
        # No #foo on initial mount

        # Only first child should be available initially
        assert app.query_one("#foo").display
        # Next two aren't mounted yet
        assert not app.query("#baz")

        # All children should be visible after a pause
        await pilot.pause()
        for n in range(3):
            await pilot.pause(1 / 60)
            await pilot.pause()

        assert app.query_one("#foo").display
        assert app.query_one("#bar").display
        assert app.query_one("#baz").display