File: test_notification.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 (40 lines) | stat: -rw-r--r-- 1,146 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
from __future__ import annotations

from time import sleep

from textual.notifications import Notification


def test_message() -> None:
    """A notification should not change the message."""
    assert Notification("test").message == "test"


def test_default_title() -> None:
    """A notification with no title should have a empty title."""
    assert Notification("test").title == ""


def test_default_severity_level() -> None:
    """The default severity level should be as expected."""
    assert Notification("test").severity == "information"


def test_default_timeout() -> None:
    """The default timeout should be as expected."""
    assert Notification("test").timeout == Notification.timeout


def test_identity_is_unique() -> None:
    """A collection of notifications should, by default, have unique IDs."""
    notifications: set[str] = set()
    for _ in range(1000):
        notifications.add(Notification("test").identity)
    assert len(notifications) == 1000


def test_time_out() -> None:
    test = Notification("test", timeout=0.5)
    assert test.has_expired is False
    sleep(0.6)
    assert test.has_expired is True