repo
stringclasses
454 values
file_path
stringlengths
5
201
extension
stringclasses
1 value
content
stringlengths
8
509k
num_lines
int64
3
16.9k
size_bytes
int64
8
511k
textual
tests/test_tabbed_content.py
.py
from __future__ import annotations import pytest from textual.app import App, ComposeResult from textual.reactive import var from textual.widgets import Label, Tab, TabbedContent, TabPane, Tabs from textual.widgets._tabbed_content import ContentTab async def test_tabbed_content_switch_via_ui(): """Check tab nav...
917
32,374
textual
tests/test_screen_modes.py
.py
from itertools import cycle from typing import Type import pytest from textual.app import ( ActiveModeError, App, ComposeResult, InvalidModeError, UnknownModeError, ) from textual.screen import ModalScreen, Screen from textual.widgets import Footer, Header, Label class ScreenBindingsMixin(Screen...
232
6,305
textual
tests/test_collapsible.py
.py
from __future__ import annotations from textual import on from textual.app import App, ComposeResult from textual.widgets import Collapsible, Label from textual.widgets._collapsible import CollapsibleTitle COLLAPSED_CLASS = "-collapsed" def get_title(collapsible: Collapsible) -> CollapsibleTitle: return collaps...
248
7,896
textual
tests/test_rlock.py
.py
import asyncio import pytest from textual.rlock import RLock async def test_simple_lock(): lock = RLock() # Starts not locked assert not lock.is_locked # Acquire the lock await lock.acquire() assert lock.is_locked # Acquire a second time (should not block) await lock.acquire() as...
57
1,270
textual
tests/test_widget_mounting.py
.py
import pytest from textual.app import App from textual.css.query import TooManyMatches from textual.widget import MountError, Widget, WidgetError from textual.widgets import Static class SelfOwn(Widget): """Test a widget that tries to own itself.""" def __init__(self) -> None: super().__init__(self)...
126
4,855
textual
tests/test_layout_resolve.py
.py
from __future__ import annotations from typing import NamedTuple import pytest from textual._layout_resolve import layout_resolve class Edge(NamedTuple): size: int | None = None fraction: int = 1 min_size: int = 1 def test_empty(): assert layout_resolve(10, []) == [] def test_total_zero(): ...
102
3,338
textual
tests/test_driver.py
.py
from textual import on from textual.app import App from textual.events import Click, MouseDown, MouseUp from textual.widgets import Button async def test_driver_mouse_down_up_click(): """Mouse down and up should issue a click.""" class MyApp(App): messages = [] @on(Click) @on(MouseDo...
128
3,899
textual
tests/test_geometry.py
.py
from typing import Literal import pytest from textual.geometry import Offset, Region, Shape, Size, Spacing, clamp def test_dimensions_region(): assert Size(30, 40).region == Region(0, 0, 30, 40) def test_dimensions_contains(): assert Size(10, 10).contains(5, 5) assert Size(10, 10).contains(9, 9) a...
834
22,314
textual
tests/test_log.py
.py
from textual.app import App, ComposeResult from textual.widgets import Log async def test_process_line(): log = Log() assert log._process_line("foo") == "foo" assert log._process_line("foo\t") == "foo " assert log._process_line("\0foo") == "�foo" async def test_disabled_log_no_attribute_error() ...
26
808
textual
tests/test_wrap.py
.py
import pytest from textual._wrap import chunks, compute_wrap_offsets @pytest.mark.parametrize( "input_text, expected_output", [ ("", []), (" ", [(0, 4, " ")]), ("\t", [(0, 1, "\t")]), ("foo", [(0, 3, "foo")]), (" foo ", [(0, 2, " "), (2, 7, "foo ")]), ...
44
1,472
textual
tests/test_widget_mount_point.py
.py
import pytest from textual.widget import MountError, Widget class Content(Widget): pass class Body(Widget): pass async def test_find_dom_spot(): # Build up a "fake" DOM for an application. screen = Widget(name="Screen") header = Widget(name="Header", id="header") body = Body(id="body") ...
40
1,295
textual
tests/test_suspend.py
.py
import sys import pytest from textual.app import App, SuspendNotSupported from textual.drivers.headless_driver import HeadlessDriver async def test_suspend_not_supported() -> None: """Suspending when not supported should raise an error.""" async with App().run_test() as pilot: # Pilot uses the headl...
64
2,119
textual
tests/test_call_x_schedulers.py
.py
import asyncio from textual._context import active_message_pump from textual.app import App from textual.message_pump import MessagePump class CallLaterApp(App[None]): def __init__(self) -> None: self.display_count = 0 super().__init__() def post_display_hook(self) -> None: self.disp...
51
1,432
textual
tests/test_links.py
.py
from textual.app import App, ComposeResult from textual.screen import Screen from textual.widgets import Label async def test_links() -> None: """Regression test for https://github.com/Textualize/textual/issues/4536""" messages: list[str] = [] class LinkLabel(Label): def action_bell_message(self,...
38
1,391
textual
tests/test_pipe.py
.py
import subprocess import sys from pathlib import Path import pytest skip_windows = pytest.mark.skipif( sys.platform == "win32", reason="Syntax not supported on Windows" ) @skip_windows def test_deadlock(): """Regression test for https://github.com/Textualize/textual/issues/4643""" app_path = (Path(__fil...
22
570
textual
tests/test_visible.py
.py
from textual.app import App, ComposeResult from textual.containers import VerticalScroll from textual.widget import Widget async def test_visibility_changes() -> None: """Test changing visibility via code and CSS. See https://github.com/Textualize/textual/issues/1355 as the motivation for these tests. ""...
79
2,647
textual
tests/test_resolve.py
.py
from fractions import Fraction import pytest from textual._resolve import resolve, resolve_fraction_unit from textual.css.scalar import Scalar from textual.geometry import Size from textual.widget import Widget def test_resolve_empty(): assert resolve([], 10, 1, Size(20, 10), Size(80, 24)) == [] @pytest.mark....
169
4,128
textual
tests/test_segment_tools.py
.py
from rich.segment import Segment from rich.style import Style from textual._segment_tools import align_lines, line_crop, line_pad, line_trim from textual.geometry import Size def test_line_crop(): bold = Style(bold=True) italic = Style(italic=True) segments = [ Segment("Hello", bold), Seg...
196
6,131
textual
tests/test_header.py
.py
from textual.app import App from textual.screen import Screen from textual.widgets import Header, Static async def test_screen_title_none_is_ignored(): class MyScreen(Screen): def compose(self): yield Header() class MyApp(App): TITLE = "app title" def on_mount(self): ...
141
3,492
textual
tests/test_data_bind.py
.py
import pytest from textual.app import App, ComposeResult from textual.reactive import ReactiveError, reactive from textual.widgets import Label class FooLabel(Label): foo = reactive("Foo") def render(self) -> str: return self.foo class DataBindApp(App): bar = reactive("Bar") def compose(s...
87
2,350
textual
tests/test_strip.py
.py
import pytest from rich.console import Console from rich.segment import Segment from rich.style import Style from textual._segment_tools import NoCellPositionForIndex from textual.color import Color from textual.filter import Monochrome from textual.strip import Strip def test_cell_length() -> None: strip = Stri...
208
6,003
textual
tests/test_app.py
.py
import asyncio import contextlib import pytest from rich.terminal_theme import DIMMED_MONOKAI, MONOKAI, NIGHT_OWLISH from textual import events from textual.app import App, ComposeResult from textual.command import SimpleCommand from textual.pilot import Pilot, _get_mouse_message_arguments from textual.screen import ...
426
11,790
textual
tests/test_mount.py
.py
"""Regression test for https://github.com/Textualize/textual/issues/2914 Make sure that calls to render only happen after a widget being mounted. """ import asyncio from textual.app import App from textual.widget import Widget class W(Widget): def render(self): return self.renderable async def on_...
28
653
textual
tests/test_disabled.py
.py
"""Test Widget.disabled.""" import pytest from textual.app import App, ComposeResult from textual.containers import Vertical, VerticalScroll from textual.widgets import ( Button, Checkbox, DataTable, DirectoryTree, Input, Label, ListItem, ListView, Markdown, MarkdownViewer, ...
150
4,664
textual
tests/test_await_remove.py
.py
from textual.app import App from textual.widgets import Label class SelfRemovingLabel(Label): async def on_mount(self) -> None: await self.remove() class RemoveOnTimerApp(App[None]): def on_mount(self): for _ in range(5): self.mount(SelfRemovingLabel("I will remove myself!")) a...
22
670
textual
tests/test_animation.py
.py
from time import perf_counter from textual.app import App, ComposeResult from textual.reactive import var from textual.widgets import Static class AnimApp(App): CSS = """ #foo { height: 1; } """ def compose(self) -> ComposeResult: yield Static("foo", id="foo") async def test_an...
302
9,584
textual
tests/test_widget_navigation.py
.py
from __future__ import annotations import pytest from textual._widget_navigation import ( find_first_enabled, find_last_enabled, find_next_enabled, find_next_enabled_no_wrap, get_directed_distance, ) class _D: def __init__(self, disabled): self.disabled = disabled # Represent disab...
155
4,414
textual
tests/test_auto_scroll.py
.py
import pytest from textual._auto_scroll import get_auto_scroll_regions from textual.geometry import Region @pytest.mark.parametrize( "region, lines, expected", [ # Simple case ( Region(0, 0, 100, 20), 1, (Region(0, 0, 100, 1), Region(0, 19, 100, 1)), ...
44
1,146
textual
tests/test_lazy.py
.py
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(i...
56
1,606
textual
tests/deadlock.py
.py
""" Called by test_pipe.py """ from textual.app import App from textual.binding import Binding from textual.widgets import Footer class MyApp(App[None]): BINDINGS = [ Binding(key="q", action="quit", description="Quit the app"), ] def compose(self): yield Footer() app = MyApp() app.run...
22
323
textual
tests/test_paste.py
.py
from textual import events from textual.app import App from textual.widgets import Input async def test_paste_app(): paste_events = [] class PasteApp(App): def on_paste(self, event): paste_events.append(event) app = PasteApp() async with app.run_test() as pilot: app.post_...
46
1,162
textual
tests/test_content_switcher.py
.py
from __future__ import annotations import pytest from textual.app import App, ComposeResult from textual.css.query import NoMatches from textual.widget import Widget from textual.widgets import ContentSwitcher class SwitcherApp(App[None]): def __init__(self, initial: str | None = None) -> None: super()....
123
5,202
textual
tests/test_switch.py
.py
from textual.app import App, ComposeResult from textual.widgets import Switch async def test_switch_click_doesnt_bubble_up(): """Regression test for https://github.com/Textualize/textual/issues/2366""" class SwitchApp(App[None]): def compose(self) -> ComposeResult: yield Switch() ...
19
571
textual
tests/test_version.py
.py
import re # https://stackoverflow.com/questions/37972029/regex-to-match-pep440-compliant-version-strings VERSION_PATTERN = r""" v? (?: (?:(?P<epoch>[0-9]+)!)? # epoch (?P<release>[0-9]+(?:\.[0-9]+)*) # release segment (?P<pre> ...
42
1,233
textual
tests/test_getters.py
.py
import pytest from textual import containers, getters from textual.app import App, ComposeResult from textual.css.query import NoMatches, WrongType from textual.widget import Widget from textual.widgets import Input, Label async def test_getters() -> None: """Check the getter descriptors work, and return expecte...
62
1,779
textual
tests/test_features.py
.py
from __future__ import annotations from textual.app import App async def test_textual_env_var(monkeypatch): monkeypatch.setenv("TEXTUAL", "") app = App() assert app.features == set() assert app.devtools is None assert app.debug is False monkeypatch.setenv("TEXTUAL", "devtools") app = App...
30
796
textual
tests/test_box_model.py
.py
from __future__ import annotations from fractions import Fraction from textual.box_model import BoxModel from textual.geometry import Size, Spacing from textual.widget import Widget async def test_content_box(): one = Fraction(1) class TestWidget(Widget): def get_content_width(self, container: Size...
190
6,248
textual
tests/test_tooltips.py
.py
"""Tests for the tooltips.""" from typing_extensions import Final from textual.app import App, ComposeResult from textual.widgets import Static class TooltipApp(App[None]): TOOLTIP_DELAY = 0.4 CSS = """ Static { width: 1fr; height: 1fr; } """ @staticmethod def tip(static...
119
4,975
textual
tests/test_app_focus_blur.py
.py
"""Test the workings of reacting to AppFocus and AppBlur.""" from textual.app import App, ComposeResult from textual.events import AppBlur, AppFocus from textual.widgets import Input class FocusBlurApp(App[None]): AUTO_FOCUS = "#input-4" def compose(self) -> ComposeResult: for n in range(10): ...
80
2,840
textual
tests/test_animator.py
.py
from __future__ import annotations from dataclasses import dataclass from unittest.mock import Mock import pytest from textual._animator import Animator, SimpleAnimation from textual._easing import DEFAULT_EASING, EASING class Animatable: """An animatable object.""" def __init__(self, value): self...
293
7,495
textual
tests/test_arrange.py
.py
import pytest from textual._arrange import TOP_Z, arrange from textual._context import active_app from textual.app import App from textual.geometry import NULL_OFFSET, Region, Size, Spacing from textual.layout import WidgetPlacement from textual.widget import Widget async def test_arrange_empty(): container = Wi...
128
3,608
textual
tests/test_binding_inheritance.py
.py
"""Tests relating to key binding inheritance. In here you'll find some tests for general key binding inheritance, but there is an emphasis on the inheriting of movement key bindings as they (as of the time of writing) hold a special place in the Widget hierarchy of Textual. <URL:https://github.com/Textualize/textual/...
643
24,202
textual
tests/test_message_handling.py
.py
from textual.app import App, ComposeResult from textual.message import Message from textual.widget import Widget async def test_message_inheritance_namespace(): """Inherited messages get their correct namespaces. Regression test for https://github.com/Textualize/textual/issues/1814. """ class BaseWi...
51
1,315
textual
tests/test_constants.py
.py
from textual.constants import _get_environ_bool, _get_environ_int, _get_environ_port def test_environ_int(monkeypatch): """Check minimum is applied.""" monkeypatch.setenv("FOO", "-1") assert _get_environ_int("FOO", 1, minimum=0) == 0 monkeypatch.setenv("FOO", "0") assert _get_environ_int("FOO", 1,...
32
1,090
textual
tests/test_binary_encode.py
.py
import pytest from textual._binary_encode import DecodeError, dump, load @pytest.mark.parametrize( "data", [ None, False, True, -10, -1, 0, 1, 100, "", "💩", "Hello", b"World", b"", [], (),...
91
1,747
textual
tests/test_file_monitor.py
.py
import os from pathlib import Path from textual.file_monitor import FileMonitor def test_repr() -> None: file_monitor = FileMonitor([Path(".")], lambda: None) assert "FileMonitor" in repr(file_monitor) def test_file_never_found(): path = "doesnt_exist.tcss" file_monitor = FileMonitor([Path(path)], ...
59
1,711
textual
tests/test_spatial_map.py
.py
import pytest from textual._spatial_map import SpatialMap from textual.geometry import Offset, Region @pytest.mark.parametrize( "region,grid", [ ( Region(0, 0, 10, 10), [ (0, 0), ], ), ( Region(10, 10, 10, 10), ...
65
1,632
textual
tests/test_textlog.py
.py
from rich.text import Text from textual.widgets import RichLog async def test_make_renderable_expand_tabs(): # Regression test for https://github.com/Textualize/textual/issues/3007 text_log = RichLog() renderable = text_log._make_renderable("\tfoo") assert isinstance(renderable, Text) assert rend...
12
350
textual
tests/test_dom.py
.py
import pytest from textual.css.errors import StyleValueError from textual.dom import BadIdentifier, DOMNode def test_display_default(): node = DOMNode() assert node.display is True @pytest.mark.parametrize( "setter_value,style_value", [[True, "block"], [False, "none"], ["block", "block"], ["none", ...
283
6,918
textual
tests/test_placeholder.py
.py
import pytest from textual.widgets import Placeholder from textual.widgets._placeholder import InvalidPlaceholderVariant async def test_invalid_placeholder_variant(): with pytest.raises(InvalidPlaceholderVariant): Placeholder(variant="this is clearly not a valid variant!") async def test_invalid_reacti...
16
473
textual
tests/test_parser.py
.py
from textual._parser import Parser def test_read1(): class TestParser(Parser[str]): """A simple parser that reads a byte at a time from a stream.""" def parse(self, on_token): while True: data = yield self.read1() if not data: break ...
54
1,784
textual
tests/test_command.py
.py
from __future__ import annotations from typing import Iterable from textual.app import App, ComposeResult, SystemCommand from textual.containers import Grid from textual.screen import ModalScreen, Screen from textual.widgets import Button, Label class QuitScreen(ModalScreen[bool]): """Screen with a dialog to qu...
63
1,886
textual
tests/test_count_parameters.py
.py
from functools import partial from textual._callback import count_parameters def test_functions() -> None: """Test count parameters of functions.""" def foo(): ... def bar(a): ... def baz(a, b): ... # repeat to allow for caching for _ in range(3): assert count_parameters(foo) == 0 ...
58
1,377
textual
tests/test_widget_removing.py
.py
from textual.app import App, ComposeResult from textual.containers import Container, Vertical from textual.widgets import Button, Label, Static async def test_remove_single_widget(): """It should be possible to the only widget on a screen.""" async with App().run_test() as pilot: widget = Static() ...
228
8,442
textual
tests/test_demo.py
.py
from textual.demo.demo_app import DemoApp async def test_demo(): """Test the demo runs.""" # Test he demo can at least run. # This exists mainly to catch screw-ups that might effect only certain Python versions. app = DemoApp() async with app.run_test() as pilot: await pilot.pause(0.1)
11
317
textual
tests/test_xterm_parser.py
.py
import itertools import pytest from textual._xterm_parser import XTermParser from textual.events import ( Key, MouseDown, MouseMove, MouseScrollDown, MouseScrollLeft, MouseScrollRight, MouseScrollUp, MouseUp, Paste, ) from textual.messages import TerminalSupportsSynchronizedOutput ...
416
12,036
textual
tests/test_data_table.py
.py
from __future__ import annotations import pytest from rich.panel import Panel from rich.text import Text from textual._wait import wait_for_idle from textual.actions import SkipAction from textual.app import App, ComposeResult, RenderableType from textual.coordinate import Coordinate from textual.geometry import Offs...
1,492
52,375
textual
tests/test_styles_cache.py
.py
from __future__ import annotations from rich.segment import Segment from textual._styles_cache import StylesCache from textual.color import Color from textual.css.styles import Styles from textual.geometry import Region, Size from textual.strip import Strip def _extract_content(lines: list[Strip]) -> list[str]: ...
272
6,016
textual
tests/test_dynamic_bindings.py
.py
from __future__ import annotations from textual.app import App async def test_dynamic_disabled(): """Check we can dynamically disable bindings.""" actions = [] class DynamicApp(App): BINDINGS = [ ("a", "register('a')", "A"), ("b", "register('b')", "B"), ("c", ...
34
899
textual
tests/test_border_subtitle.py
.py
from textual.app import App, ComposeResult from textual.widget import Widget async def test_border_subtitle(): class BorderWidget(Widget): BORDER_TITLE = "foo" BORDER_SUBTITLE = "bar" class SimpleApp(App): def compose(self) -> ComposeResult: yield BorderWidget() empty...
19
518
textual
tests/test_easing.py
.py
""" Test the easing functions by sampling the range [0, 1] uniformly in 21 points. Then, a TypeScript script was used to sample all the original functions, the data was collected, and is here tested against the Python implementation. """ import pytest from textual._easing import EASING POINTS = [ 0.0, 0.05, ...
741
16,367
textual
tests/test_issue_4248.py
.py
"""Test https://github.com/Textualize/textual/issues/4248""" from textual.app import App, ComposeResult from textual.widgets import Label async def test_issue_4248() -> None: """Various forms of click parameters should be fine.""" bumps = 0 class ActionApp(App[None]): def compose(self) -> Compo...
43
1,608
textual
tests/test_path.py
.py
from __future__ import annotations from pathlib import Path import pytest from textual.app import App APP_DIR = Path(__file__).parent class RelativePathObjectApp(App[None]): CSS_PATH = Path("test.tcss") class RelativePathStrApp(App[None]): CSS_PATH = "test.tcss" class AbsolutePathObjectApp(App[None]):...
45
1,095
textual
tests/test_pilot.py
.py
from string import punctuation from typing import Type import pytest from textual import events, work from textual._on import on from textual.app import App, ComposeResult from textual.binding import Binding from textual.containers import Center, Middle from textual.css.errors import StylesheetError from textual.pilo...
453
15,523
textual
tests/test_rule.py
.py
import pytest from textual.widgets import Rule from textual.widgets.rule import InvalidLineStyle, InvalidRuleOrientation async def test_invalid_rule_orientation(): with pytest.raises(InvalidRuleOrientation): Rule(orientation="invalid orientation!") async def test_invalid_rule_line_style(): with pyt...
27
742
textual
tests/test_reactive.py
.py
from __future__ import annotations import asyncio import pytest from textual.app import App, ComposeResult from textual.message import Message from textual.message_pump import MessagePump from textual.reactive import Initialize, Reactive, TooManyComputesError, reactive, var from textual.widget import Widget OLD_VAL...
843
25,252
textual
tests/test_style_importance.py
.py
from textual.app import App, ComposeResult from textual.color import Color from textual.containers import Container from textual.css.scalar import ScalarOffset class StyleApp(App[None]): CSS = """ Container { border: round green !important; outline: round green !important; align: right...
103
3,501
textual
tests/test_validation.py
.py
from __future__ import annotations import pytest from textual.validation import ( URL, Failure, Function, Integer, Length, Number, Regex, ValidationResult, Validator, ) VALIDATOR = Function(lambda value: True) def test_ValidationResult_merge_successes(): results = [Validatio...
235
8,907
textual
tests/test_modal.py
.py
from __future__ import annotations from textual.app import App, ComposeResult from textual.containers import Grid from textual.screen import ModalScreen from textual.widgets import Button, Footer, Header, Label TEXT = """I must not fear. Fear is the mind-killer. Fear is the little-death that brings total obliteration...
100
2,563
textual
tests/test_selection.py
.py
import pytest from textual.app import App, ComposeResult from textual.containers import VerticalScroll from textual.geometry import Offset from textual.selection import Selection from textual.widgets import Static @pytest.mark.parametrize( "text,selection,expected", [ ("Hello", Selection(None, None),...
228
8,203
textual
tests/test_style_properties.py
.py
import pytest from rich.style import Style from textual.color import Color from textual.css.errors import StyleValueError from textual.css.styles import Styles def test_box_normalization(): """Check that none or hidden is normalized to empty string.""" styles = Styles() styles.border_left = ("none", "red...
33
1,120
textual
tests/test_filters.py
.py
from rich.color import Color as RichColor from rich.color import ColorType from rich.segment import Segment from rich.style import Style from rich.terminal_theme import MONOKAI from textual.color import Color from textual.filter import ANSIToTruecolor def test_ansi_to_truecolor_8_bit_dim(): """Test that converti...
30
906
textual
tests/test_style_inheritance.py
.py
from textual.app import App, ComposeResult from textual.widgets import Button, Static async def test_text_style_inheritance(): """Check that changes to text style are inherited in children.""" class FocusableThing(Static, can_focus=True): DEFAULT_CSS = """ FocusableThing { text-st...
38
1,099
textual
tests/test_auto_refresh.py
.py
import asyncio from time import time from textual.app import App from textual.pilot import Pilot class RefreshApp(App[float]): def __init__(self): self.count = 0 super().__init__() def on_mount(self): self.start = time() self.auto_refresh = 0.1 def automatic_refresh(self...
34
773
textual
tests/test_binding.py
.py
from string import ascii_lowercase import pytest from textual.app import App from textual.binding import ( Binding, BindingError, BindingsMap, InvalidBinding, NoBinding, ) from textual.screen import Screen BINDING1 = Binding("a,b", action="action1", description="description1") BINDING2 = Binding(...
140
3,992
textual
tests/test_slug.py
.py
import pytest from textual._slug import TrackedSlugs, slug, slug_for_tcss_id from textual.dom import check_identifiers @pytest.mark.xdist_group("group1") @pytest.mark.parametrize( "text, expected", [ ("test", "test"), ("Test", "test"), (" Test ", "test"), ("-test-", "-test-"),...
89
2,605
textual
tests/test_compositor_regions_to_spans.py
.py
from textual._compositor import Compositor from textual.geometry import Region def test_regions_to_ranges_no_regions(): assert list(Compositor._regions_to_spans([])) == [] def test_regions_to_ranges_single_region(): regions = [Region(0, 0, 3, 2)] assert list(Compositor._regions_to_spans(regions)) == [ ...
55
1,520
textual
tests/test_line_split.py
.py
from textual._line_split import line_split def test_split_string_to_lines_and_endings(): # Test with different line endings assert line_split("Hello\r\nWorld\n") == [("Hello", "\r\n"), ("World", "\n")] assert line_split("Hello\rWorld\r\n") == [("Hello", "\r"), ("World", "\r\n")] assert line_split("Hel...
27
849
textual
tests/test_signal.py
.py
import pytest from textual.app import App, ComposeResult from textual.signal import Signal, SignalError from textual.widgets import Label async def test_signal(): """Test signal subscribe""" called = 0 class TestLabel(Label): def on_mount(self) -> None: def signal_result(_): ...
111
3,159
textual
tests/test_color.py
.py
import pytest from rich.color import Color as RichColor from textual.color import Color, Gradient, Lab, lab_to_rgb, rgb_to_lab def test_rich_color(): """Check conversion to Rich color.""" assert Color(10, 20, 30, 1.0).rich_color == RichColor.from_rgb(10, 20, 30) assert Color.from_rich_color(RichColor.fro...
325
10,482
textual
tests/test_line_filter.py
.py
from rich.segment import Segment from rich.style import Style from textual.color import Color from textual.filter import DimFilter def test_dim_apply(): """Check dim filter changes color and resets dim attribute.""" dim_filter = DimFilter() segments = [Segment("Hello, World!", Style.parse("dim #ffffff ...
20
527
textual
tests/test_eta.py
.py
from textual.eta import ETA def test_basics() -> None: eta = ETA() eta.add_sample(1.0, 1.0) assert eta.first_sample == (0, 0) assert eta.last_sample == (1.0, 1.0) assert len(eta._samples) == 2 repr(eta) def test_speed() -> None: eta = ETA() # One sample is not enough to determine spe...
57
1,423
textual
tests/test_shutdown.py
.py
from textual.app import App from textual.containers import Horizontal from textual.widgets import Footer, Tree class TreeApp(App[None]): def compose(self): yield Horizontal(Tree("Dune")) yield Footer() async def test_shutdown(): # regression test for https://github.com/Textualize/textual/iss...
19
504
textual
tests/test_win_sleep.py
.py
import asyncio import time import sys import pytest from textual.app import App pytestmark = pytest.mark.skipif( sys.platform != "win32", reason="We only need to test this on Windows." ) def test_win_sleep_timer_is_cancellable(): """Regression test for https://github.com/Textualize/textual/issues/2711. ...
42
1,204
textual
tests/test_duration.py
.py
import pytest from textual._duration import DurationParseError, _duration_as_seconds def test_parse() -> None: assert _duration_as_seconds("30") == 30.0 assert _duration_as_seconds("30s") == 30.0 assert _duration_as_seconds("30000ms") == 30.0 assert _duration_as_seconds("0.5") == 0.5 assert _dura...
16
481
textual
tests/test_loop.py
.py
from textual._loop import loop_first, loop_first_last, loop_from_index, loop_last def test_loop_first(): assert list(loop_first([])) == [] iterable = loop_first(["apples", "oranges", "pears", "lemons"]) assert next(iterable) == (True, "apples") assert next(iterable) == (False, "oranges") assert ne...
66
1,784
textual
tests/test_border.py
.py
import pytest from rich.segment import Segment from rich.style import Style as RichStyle from rich.text import Text from textual._border import render_border_label, render_row from textual.content import Content from textual.style import Style from textual.widget import Widget def test_border_render_row(): style...
272
7,651
textual
tests/test_keys.py
.py
import pytest from textual.app import App from textual.binding import Binding from textual.keys import _character_to_key, format_key, key_to_character @pytest.mark.parametrize( "character,key", [ ("1", "1"), ("2", "2"), ("a", "a"), ("z", "z"), ("_", "underscore"), ...
79
2,171
textual
tests/test_widget.py
.py
from operator import attrgetter import pytest from textual import events from textual._node_list import DuplicateIds from textual.app import App, ComposeResult from textual.containers import Container, Vertical from textual.content import Content from textual.css.errors import StyleValueError from textual.css.query i...
769
22,998
textual
tests/test_freeze.py
.py
import pytest from textual.app import App from textual.screen import Screen from textual.widgets import Footer, Header, Input class MyScreen(Screen): def compose(self): yield Header() yield Input() yield Footer() class MyApp(App): def on_mount(self): self.install_screen(MySc...
27
616
textual
tests/test_message_pump.py
.py
import threading import pytest from textual._dispatch_key import dispatch_key from textual.app import App, ComposeResult from textual.errors import DuplicateKeyHandlers from textual.events import Key from textual.message import Message from textual.widget import Widget from textual.widgets import Button, Input, Label...
193
5,367
textual
tests/test_two_way_dict.py
.py
import pytest from textual._two_way_dict import TwoWayDict @pytest.fixture def two_way_dict(): return TwoWayDict( { 1: 10, 2: 20, 3: 30, } ) def test_get(two_way_dict): assert two_way_dict.get(1) == 10 def test_get_key(two_way_dict): assert two_...
46
871
textual
tests/test_overflow_change.py
.py
"""Regression test for #1616 https://github.com/Textualize/textual/issues/1616""" from textual.app import App from textual.containers import VerticalScroll async def test_overflow_change_updates_virtual_size_appropriately(): class MyApp(App): def compose(self): yield VerticalScroll() app...
36
1,049
textual
tests/test_tabs.py
.py
from __future__ import annotations import pytest from textual import on from textual.app import App, ComposeResult from textual.widgets import Tab, Tabs from textual.widgets._tabs import Underline async def test_tab_label(): """It should be possible to access a tab's label.""" assert Tab("Pilot").label_text...
513
16,823
textual
tests/test_on.py
.py
from __future__ import annotations from dataclasses import dataclass import pytest from textual import on from textual._on import OnDecoratorError from textual.app import App, ComposeResult from textual.events import Enter, Leave from textual.message import Message from textual.widget import Widget from textual.widg...
381
10,866
textual
tests/test_test_runner.py
.py
from textual import events from textual.app import App async def test_run_test() -> None: """Test the run_test context manager.""" keys_pressed: list[str] = [] class TestApp(App[str]): def on_key(self, event: events.Key) -> None: keys_pressed.append(event.key) app = TestApp() ...
24
779
textual
tests/test_markdown.py
.py
"""Unit tests for the Markdown widget.""" from __future__ import annotations from pathlib import Path from typing import Iterator import pytest from markdown_it.token import Token from rich.text import Span import textual.widgets._markdown as MD from textual import on from textual.app import App, ComposeResult from...
220
7,055
textual
tests/test_content.py
.py
from __future__ import annotations import pytest from rich.text import Text from textual.color import Color from textual.content import Content, Span from textual.style import Style from textual.visual import RenderOptions from textual.widget import Widget def test_blank(): """Check blank content.""" blank ...
590
17,878
textual
tests/test_suggestions.py
.py
import pytest from textual.suggestions import get_suggestion, get_suggestions @pytest.mark.parametrize( "word, possible_words, expected_result", ( ["background", ("background",), "background"], ["backgroundu", ("background",), "background"], ["bkgrund", ("background",), "background"],...
36
1,355
textual
tests/test_keymap.py
.py
from __future__ import annotations from typing import Any from textual.app import App, ComposeResult from textual.binding import Binding, Keymap from textual.dom import DOMNode from textual.widget import Widget from textual.widgets import Label class Counter(App[None]): BINDINGS = [ Binding(key="i,up", ...
220
6,410