File: test_app_notifications.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 (53 lines) | stat: -rw-r--r-- 1,917 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
import asyncio

from textual.app import App


class NotificationApp(App[None]):
    pass


async def test_app_no_notifications() -> None:
    """An app with no notifications should have an empty notification list."""
    async with NotificationApp().run_test() as pilot:
        assert len(pilot.app._notifications) == 0


async def test_app_with_notifications() -> None:
    """An app with notifications should have notifications in the list."""
    async with NotificationApp().run_test() as pilot:
        pilot.app.notify("test")
        await pilot.pause()
        assert len(pilot.app._notifications) == 1


async def test_app_with_removing_notifications() -> None:
    """An app with notifications should have notifications in the list, which can be removed."""
    async with NotificationApp().run_test() as pilot:
        pilot.app.notify("test")
        await pilot.pause()
        assert len(pilot.app._notifications) == 1
        pilot.app._unnotify(list(pilot.app._notifications)[0])
        assert len(pilot.app._notifications) == 0


async def test_app_with_notifications_that_expire() -> None:
    """Notifications should expire from an app."""
    async with NotificationApp().run_test() as pilot:
        for n in range(10):
            pilot.app.notify("test", timeout=(0.01 if bool(n % 2) else 60))

        # Wait until the 0.01 timeout expires on all notifications (plus some leeway)
        await asyncio.sleep(0.25)
        assert len(pilot.app._notifications) == 5


async def test_app_clearing_notifications() -> None:
    """The application should be able to clear all notifications."""
    async with NotificationApp().run_test() as pilot:
        for _ in range(100):
            pilot.app.notify("test", timeout=120)
        await pilot.pause()
        assert len(pilot.app._notifications) == 100
        pilot.app.clear_notifications()
        assert len(pilot.app._notifications) == 0