mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
added tests for screens
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from datetime import datetime
|
||||
import inspect
|
||||
import io
|
||||
import os
|
||||
@@ -9,9 +8,11 @@ import platform
|
||||
import sys
|
||||
import warnings
|
||||
from contextlib import redirect_stdout
|
||||
from datetime import datetime
|
||||
from pathlib import PurePath
|
||||
from time import perf_counter
|
||||
from typing import (
|
||||
TYPE_CHECKING,
|
||||
Any,
|
||||
Generic,
|
||||
Iterable,
|
||||
@@ -19,11 +20,10 @@ from typing import (
|
||||
TextIO,
|
||||
Type,
|
||||
TypeVar,
|
||||
TYPE_CHECKING,
|
||||
)
|
||||
from weakref import WeakSet, WeakValueDictionary
|
||||
|
||||
from ._ansi_sequences import SYNC_START, SYNC_END
|
||||
from ._ansi_sequences import SYNC_END, SYNC_START
|
||||
|
||||
if sys.version_info >= (3, 8):
|
||||
from typing import Literal
|
||||
@@ -39,30 +39,24 @@ from rich.protocol import is_renderable
|
||||
from rich.segment import Segments
|
||||
from rich.traceback import Traceback
|
||||
|
||||
from . import actions
|
||||
from . import events
|
||||
from . import log
|
||||
from . import messages
|
||||
from . import actions, events, log, messages
|
||||
from ._animator import Animator
|
||||
from ._callback import invoke
|
||||
from ._context import active_app
|
||||
from ._event_broker import extract_handler_actions, NoHandler
|
||||
from ._event_broker import NoHandler, extract_handler_actions
|
||||
from .binding import Bindings, NoBinding
|
||||
from .css.stylesheet import Stylesheet
|
||||
from .css.query import NoMatchingNodesError
|
||||
from .css.stylesheet import Stylesheet
|
||||
from .design import ColorSystem
|
||||
from .devtools.client import DevtoolsClient, DevtoolsConnectionError, DevtoolsLog
|
||||
from .devtools.redirect_output import StdoutRedirector
|
||||
from .dom import DOMNode
|
||||
from .driver import Driver
|
||||
from .features import parse_features, FeatureFlag
|
||||
from .features import FeatureFlag, parse_features
|
||||
from .file_monitor import FileMonitor
|
||||
from .geometry import Offset, Region, Size
|
||||
from .message_pump import MessagePump
|
||||
from .reactive import Reactive
|
||||
from .renderables.blank import Blank
|
||||
from ._profile import timer
|
||||
|
||||
from .screen import Screen
|
||||
from .widget import Widget
|
||||
|
||||
|
||||
66
tests/test_screens.py
Normal file
66
tests/test_screens.py
Normal file
@@ -0,0 +1,66 @@
|
||||
import pytest
|
||||
|
||||
from textual.app import App, ScreenStackError
|
||||
from textual.screen import Screen
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_screens():
|
||||
|
||||
app = App()
|
||||
app._set_active()
|
||||
|
||||
assert not app._installed_screens
|
||||
|
||||
screen1 = Screen(name="screen1")
|
||||
screen2 = Screen(name="screen2")
|
||||
screen3 = Screen(name="screen3")
|
||||
|
||||
# installs screens
|
||||
app.install_screen(screen1, "screen1")
|
||||
app.install_screen(screen2, "screen2")
|
||||
|
||||
# Check they are installed
|
||||
assert app.is_screen_installed("screen1")
|
||||
assert app.is_screen_installed("screen2")
|
||||
|
||||
assert app.get_screen("screen1") is screen1
|
||||
with pytest.raises(KeyError):
|
||||
app.get_screen("foo")
|
||||
|
||||
# Check screen3 is not installed
|
||||
assert not app.is_screen_installed("screen3")
|
||||
|
||||
# Installs screen3
|
||||
app.install_screen(screen3, "screen3")
|
||||
# Confirm installed
|
||||
assert app.is_screen_installed("screen3")
|
||||
|
||||
# Check screen stack is empty
|
||||
assert app.screen_stack == []
|
||||
# Push a screen
|
||||
app.push_screen("screen1")
|
||||
# Check it is on the stack
|
||||
assert app.screen_stack == [screen1]
|
||||
# Check it is current
|
||||
assert app.screen is screen1
|
||||
|
||||
# Switch to another screen
|
||||
app.switch_screen("screen2")
|
||||
# Check it has changed the stack and that it is current
|
||||
assert app.screen_stack == [screen2]
|
||||
assert app.screen is screen2
|
||||
|
||||
# Push another screen
|
||||
app.push_screen("screen3")
|
||||
assert app.screen_stack == [screen2, screen3]
|
||||
assert app.screen is screen3
|
||||
|
||||
# Pop a screen
|
||||
assert app.pop_screen() is screen3
|
||||
assert app.screen is screen2
|
||||
assert app.screen_stack == [screen2]
|
||||
|
||||
# Check we can't pop last screen
|
||||
with pytest.raises(ScreenStackError):
|
||||
app.pop_screen()
|
||||
@@ -1,6 +0,0 @@
|
||||
import pytest
|
||||
|
||||
from textual.layouts.grid import GridLayout
|
||||
from textual.layouts.horizontal import HorizontalLayout
|
||||
from textual.layouts.vertical import VerticalLayout
|
||||
from textual.screen import Screen
|
||||
Reference in New Issue
Block a user